From fa53e0214181835f60315a849875e5efd28c6360 Mon Sep 17 00:00:00 2001 From: Jenny Date: Fri, 2 May 2025 14:45:51 +0200 Subject: [PATCH] different texture for linked chest, fixed double chest --- gradle.properties | 4 ++-- .../networked_chests/items/ChestInterface.java | 10 +++++++--- .../models/item/chest_interface.json | 10 +++++++++- .../models/item/chest_interface_linked.json | 6 ++++++ .../textures/item/chest_interface_linked.png | Bin 0 -> 162 bytes 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/assets/networked_chests/models/item/chest_interface_linked.json create mode 100644 src/main/resources/assets/networked_chests/textures/item/chest_interface_linked.png diff --git a/gradle.properties b/gradle.properties index 14d3518..7995748 100644 --- a/gradle.properties +++ b/gradle.properties @@ -38,12 +38,12 @@ mod_name=Networked Chests # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=0.1.1 +mod_version=0.2.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html mod_group_id=com.jenny # The authors of the mod. This is a simple text string that is used for display purposes in the mod list. -mod_authors=Jenny +mod_authors=xJenny69 # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. mod_description= diff --git a/src/main/java/com/jenny/networked_chests/items/ChestInterface.java b/src/main/java/com/jenny/networked_chests/items/ChestInterface.java index 8339efd..1c3d0f7 100644 --- a/src/main/java/com/jenny/networked_chests/items/ChestInterface.java +++ b/src/main/java/com/jenny/networked_chests/items/ChestInterface.java @@ -2,6 +2,7 @@ package com.jenny.networked_chests.items; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -15,7 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,6 +63,7 @@ public class ChestInterface extends Item { if (chestLocation == null) { chestLocation = new CompoundTag(); } + chestLocation.putInt("CustomModelData", 1); chestLocation.putInt("chest_pos_x", blockPos.getX()); chestLocation.putInt("chest_pos_y", blockPos.getY()); chestLocation.putInt("chest_pos_z", blockPos.getZ()); @@ -77,8 +79,9 @@ public class ChestInterface extends Item { private void openChest(Level level, ServerPlayer player, ItemStack itemStack) { if (chestSet(itemStack)) { if (isChest(level, getPos(itemStack))) { - ((ChestBlockEntity) level.getBlockEntity(getPos(itemStack))).startOpen(player); - player.openMenu((ChestBlockEntity) level.getBlockEntity(getPos(itemStack))); + level.getBlockState(getPos(itemStack)).use(level, player, InteractionHand.MAIN_HAND, new BlockHitResult(player.position(), Direction.DOWN, getPos(itemStack), false)); + //((ChestBlockEntity) level.getBlockEntity(getPos(itemStack))).startOpen(player); + //player.openMenu((ChestBlockEntity) level.getBlockEntity(getPos(itemStack))); } else { unsetChest(itemStack); messageChestMissing(player); @@ -97,6 +100,7 @@ public class ChestInterface extends Item { private void unsetChest(ItemStack itemStack) { CompoundTag cTag = itemStack.getTag(); assert cTag != null; + cTag.remove("CustomModelData"); cTag.remove("chest_pos_x"); cTag.remove("chest_pos_y"); cTag.remove("chest_pos_z"); diff --git a/src/main/resources/assets/networked_chests/models/item/chest_interface.json b/src/main/resources/assets/networked_chests/models/item/chest_interface.json index f761163..112591d 100644 --- a/src/main/resources/assets/networked_chests/models/item/chest_interface.json +++ b/src/main/resources/assets/networked_chests/models/item/chest_interface.json @@ -2,5 +2,13 @@ "parent": "minecraft:item/generated", "textures": { "layer0": "networked_chests:item/chest_interface" - } + }, + "overrides": [ + { + "predicate": { + "custom_model_data": 1 + }, + "model": "networked_chests:item/chest_interface_linked" + } + ] } \ No newline at end of file diff --git a/src/main/resources/assets/networked_chests/models/item/chest_interface_linked.json b/src/main/resources/assets/networked_chests/models/item/chest_interface_linked.json new file mode 100644 index 0000000..0a00436 --- /dev/null +++ b/src/main/resources/assets/networked_chests/models/item/chest_interface_linked.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "networked_chests:item/chest_interface_linked" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/networked_chests/textures/item/chest_interface_linked.png b/src/main/resources/assets/networked_chests/textures/item/chest_interface_linked.png new file mode 100644 index 0000000000000000000000000000000000000000..b395064964ab34da9ad5e83f2cc05f5bbce0ae7e GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|Vmw_OLo9le z6BY;<7#SECR8+bBS9kyX?X9<@G2h}*4Po>W@e6)3D;)UafE*LP>TP