From bb59826fc2ca0512ceb554e3be603dc193d0a9e0 Mon Sep 17 00:00:00 2001 From: Paul Schifferer Date: Tue, 16 Jan 2024 20:03:57 -0800 Subject: [PATCH] Trees --- .../catherder/common/entity/CatEntity.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/sweetrpg/catherder/common/entity/CatEntity.java b/src/main/java/com/sweetrpg/catherder/common/entity/CatEntity.java index a3ecd66..a2215c3 100644 --- a/src/main/java/com/sweetrpg/catherder/common/entity/CatEntity.java +++ b/src/main/java/com/sweetrpg/catherder/common/entity/CatEntity.java @@ -1320,19 +1320,19 @@ public void addAdditionalSaveData(CompoundTag compound) { } NBTUtil.writeItemStack(compound, "fetchItem", this.getToyVariant()); - DimensionDependentArg> bedsData = this.entityData.get(CAT_TREE_LOCATION.get()); + DimensionDependentArg> treesData = this.entityData.get(CAT_TREE_LOCATION.get()); + if(!treesData.isEmpty()) { + ListTag treesList = new ListTag(); - if(!bedsData.isEmpty()) { - ListTag bedsList = new ListTag(); - - for(Entry, Optional> entry : bedsData.entrySet()) { - CompoundTag bedNBT = new CompoundTag(); - NBTUtil.putResourceLocation(bedNBT, "dim", entry.getKey().location()); - NBTUtil.putBlockPos(bedNBT, "pos", entry.getValue()); - bedsList.add(bedNBT); + for(Entry, Optional> entry : treesData.entrySet()) { + CompoundTag treeTag = new CompoundTag(); + NBTUtil.putResourceLocation(treeTag, "dim", entry.getKey().location()); + NBTUtil.putBlockPos(treeTag, "pos", entry.getValue()); + treesList.add(treeTag); } - compound.put("beds", bedsList); + compound.put("beds", treesList); // TODO: remove this eventually + compound.put("trees", treesList); } DimensionDependentArg> bowlsData = this.entityData.get(CAT_BOWL_LOCATION.get()); @@ -1567,27 +1567,26 @@ public void readAdditionalSaveData(CompoundTag compound) { } // cat tree - DimensionDependentArg> bedsData = this.entityData.get(CAT_TREE_LOCATION.get()).copyEmpty(); - + DimensionDependentArg> treesData = this.entityData.get(CAT_TREE_LOCATION.get()).copyEmpty(); try { - if(compound.contains("beds", Tag.TAG_LIST)) { - ListTag bedsList = compound.getList("beds", Tag.TAG_COMPOUND); + if(compound.contains("beds", Tag.TAG_LIST)) { // TODO: eventually replace with "trees" + ListTag treesList = compound.getList("beds", Tag.TAG_COMPOUND); - for(int i = 0; i < bedsList.size(); i++) { - CompoundTag bedNBT = bedsList.getCompound(i); - ResourceLocation loc = NBTUtil.getResourceLocation(bedNBT, "dim"); + for(int i = 0; i < treesList.size(); i++) { + CompoundTag treeTag = treesList.getCompound(i); + ResourceLocation loc = NBTUtil.getResourceLocation(treeTag, "dim"); ResourceKey type = ResourceKey.create(Registries.DIMENSION, loc); - Optional pos = NBTUtil.getBlockPos(bedNBT, "pos"); - bedsData.put(type, pos); + Optional pos = NBTUtil.getBlockPos(treeTag, "pos"); + treesData.put(type, pos); } } } catch (Exception e) { - CatHerder.LOGGER.error("Failed to load beds: " + e.getMessage()); + CatHerder.LOGGER.error("Failed to load trees: " + e.getMessage()); e.printStackTrace(); } - this.entityData.set(CAT_TREE_LOCATION.get(), bedsData); + this.entityData.set(CAT_TREE_LOCATION.get(), treesData); // cat bowl DimensionDependentArg> bowlsData = this.entityData.get(CAT_BOWL_LOCATION.get()).copyEmpty(); @@ -1629,7 +1628,7 @@ public void readAdditionalSaveData(CompoundTag compound) { } } catch (Exception e) { - CatHerder.LOGGER.error("Failed to load litterboxes: " + e.getMessage()); + CatHerder.LOGGER.error("Failed to load litter boxes: " + e.getMessage()); e.printStackTrace(); }