From 57dcf747303cbd9f00adb0033cdb54482b839203 Mon Sep 17 00:00:00 2001 From: Yuqi154 <1123489751@qq.com> Date: Fri, 26 Jul 2024 13:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BC=8F=E6=96=97=E5=AF=B9?= =?UTF-8?q?=E7=81=B6=E7=9A=84=E9=94=99=E8=AF=AF=E8=A1=8C=E4=B8=BA=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=81=B6=E5=86=85=E8=87=AA=E5=8A=A8=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=BB=91=E6=9A=97=E7=89=A9=E8=B4=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/block/entities/CookingRange.java | 45 ++++++----------- .../mystiasizakaya/content/cooking/Main.java | 5 +- .../mystiasizakaya/util/GetItemStack.java | 9 +++- .../mystiasizakaya/util/SetSlotItem.java | 49 ++++++++++--------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/hiedacamellia/mystiasizakaya/content/block/entities/CookingRange.java b/src/main/java/org/hiedacamellia/mystiasizakaya/content/block/entities/CookingRange.java index 67d8b9fc..76024f30 100644 --- a/src/main/java/org/hiedacamellia/mystiasizakaya/content/block/entities/CookingRange.java +++ b/src/main/java/org/hiedacamellia/mystiasizakaya/content/block/entities/CookingRange.java @@ -105,21 +105,14 @@ protected void setItems(NonNullList stacks) { @Override public boolean canPlaceItem(int index, ItemStack stack) { - if (index == 6) - return false; - if (index == 7) - return false; - if (index == 8) - return false; - if (index == 9) - return false; - if (index == 10) - return false; - if (index == 11) - return false; - if (index == 12) - return false; - return true; + switch (index){ + case 6,7,8,9,10,11,12 -> { + return false; + } + default -> { + return true; + } + } } @Override @@ -129,25 +122,17 @@ public int[] getSlotsForFace(Direction side) { @Override public boolean canPlaceItemThroughFace(int index, ItemStack stack, @Nullable Direction direction) { - return this.canPlaceItem(index, stack); + //if(index==0) + + return false; + + //return this.canPlaceItem(index, stack); } @Override public boolean canTakeItemThroughFace(int index, ItemStack stack, Direction direction) { - if (index == 7) - return false; - if (index == 8) - return false; - if (index == 9) - return false; - if (index == 10) - return false; - if (index == 11) - return false; - if (index == 12) - return false; - return true; - } + return index == 6; + } @Override public LazyOptional getCapability(Capability capability, @Nullable Direction facing) { diff --git a/src/main/java/org/hiedacamellia/mystiasizakaya/content/cooking/Main.java b/src/main/java/org/hiedacamellia/mystiasizakaya/content/cooking/Main.java index d9ccbef7..1fc5af3a 100644 --- a/src/main/java/org/hiedacamellia/mystiasizakaya/content/cooking/Main.java +++ b/src/main/java/org/hiedacamellia/mystiasizakaya/content/cooking/Main.java @@ -82,9 +82,10 @@ public static void execute(LevelAccessor world, double x, double y, double z) { } util = GetItemStack.getItemStack(world, Pos.get(x, y, z), 0); + /* if (util.getItem() == ItemStack.EMPTY.getItem()) { SetSlotItem.setSlotItem(world, x, y, z, new ItemStack(ItemRegistery.HEI_AN_WU_ZHI.get()), 12, 1); - } + }*/ List raws = new ArrayList<>(); List ingredients = new ArrayList<>(); @@ -126,6 +127,8 @@ public static void execute(LevelAccessor world, double x, double y, double z) { } } + //SetSlotItem.setEmptySlot(world, x, y, z, 12); + // ItemStack cuisine = GetItemStack.getItemStack(world, Pos.get(x, y, z), 12); // try { // cuisine.inventoryTick(null, null, 0, false); diff --git a/src/main/java/org/hiedacamellia/mystiasizakaya/util/GetItemStack.java b/src/main/java/org/hiedacamellia/mystiasizakaya/util/GetItemStack.java index 7b66b5f3..97c80b57 100644 --- a/src/main/java/org/hiedacamellia/mystiasizakaya/util/GetItemStack.java +++ b/src/main/java/org/hiedacamellia/mystiasizakaya/util/GetItemStack.java @@ -13,8 +13,15 @@ public static ItemStack getItemStack(LevelAccessor world, BlockPos pos, int slot AtomicReference _retval = new AtomicReference<>(ItemStack.EMPTY); BlockEntity _ent = world.getBlockEntity(pos); if (_ent != null) - _ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null) + return getItemStack(_ent, slotid); + return _retval.get(); + } + public static ItemStack getItemStack(BlockEntity be, int slotid) { + AtomicReference _retval = new AtomicReference<>(ItemStack.EMPTY); + if (be != null) { + be.getCapability(ForgeCapabilities.ITEM_HANDLER, null) .ifPresent(capability -> _retval.set(capability.getStackInSlot(slotid).copy())); + } return _retval.get(); } } diff --git a/src/main/java/org/hiedacamellia/mystiasizakaya/util/SetSlotItem.java b/src/main/java/org/hiedacamellia/mystiasizakaya/util/SetSlotItem.java index 8b1933a7..e87ddd24 100644 --- a/src/main/java/org/hiedacamellia/mystiasizakaya/util/SetSlotItem.java +++ b/src/main/java/org/hiedacamellia/mystiasizakaya/util/SetSlotItem.java @@ -11,21 +11,13 @@ import java.util.List; public class SetSlotItem { - public static void setSlotItem(LevelAccessor world, double x, double y, double z, ItemStack itemStack, int slotid, - int count) { + public static void setSlotItem(LevelAccessor world, double x, double y, double z, ItemStack itemStack, int slotid, int count) { BlockEntity _ent = world.getBlockEntity(Pos.get(x, y, z)); if (_ent != null) { - final int _slotid = slotid; - final ItemStack _setstack = itemStack; - _setstack.setCount(count); - _ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> { - if (capability instanceof IItemHandlerModifiable) - ((IItemHandlerModifiable) capability).setStackInSlot(_slotid, _setstack ); - }); + setSlotItem(_ent, itemStack, slotid, count); } } - public static void setSlotItem(BlockEntity be, ItemStack itemStack, int slotid, - int count) { + public static void setSlotItem(BlockEntity be, ItemStack itemStack, int slotid, int count) { if (be != null) { final int _slotid = slotid; final ItemStack _setstack = itemStack; @@ -36,32 +28,45 @@ public static void setSlotItem(BlockEntity be, ItemStack itemStack, int slotid, }); } } + public static void querySlotItem(LevelAccessor world, double x, double y, double z, int slotid,int count) { + BlockEntity _ent = world.getBlockEntity(Pos.get(x, y, z)); + if (_ent != null) { + querySlotItem(_ent, slotid, count); + } + } + public static void querySlotItem(BlockEntity be, int slotid,int count) { + if (be != null) { + ItemStack item = GetItemStack.getItemStack(be, slotid); + setSlotItem(be, item, slotid, item.getCount()-count); + } + } + public static void querySlotItem(BlockEntity be, int[] slotid,int[] count) { + if (be != null) { + for (int i = 0; i < slotid.length; i++) { + querySlotItem(be, slotid[i], count[i]); + } + } + } + + public static void setEmptySlot(LevelAccessor world, double x, double y, double z, int slotid) { BlockEntity _ent = world.getBlockEntity(Pos.get(x, y, z)); if (_ent != null) { - final int _slotid = slotid; - _ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> { - if (capability instanceof IItemHandlerModifiable) - ((IItemHandlerModifiable) capability).setStackInSlot(_slotid, ItemStack.EMPTY); - }); + setEmptySlot(_ent, slotid); } } public static void setEmptySlot(BlockEntity be, int slotid) { if (be != null) { - final int _slotid = slotid; be.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> { if (capability instanceof IItemHandlerModifiable) - ((IItemHandlerModifiable) capability).setStackInSlot(_slotid, ItemStack.EMPTY); + ((IItemHandlerModifiable) capability).setStackInSlot(slotid, ItemStack.EMPTY); }); } } public static void setEmptySlot(BlockEntity be, int[] slotid) { if (be != null) { for (int slot : slotid) { - be.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> { - if (capability instanceof IItemHandlerModifiable) - ((IItemHandlerModifiable) capability).setStackInSlot(slot, ItemStack.EMPTY); - }); + setEmptySlot(be, slot); }; } }