From 3e1312e69582ad593a480282f6418c413d1d8033 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 23 Oct 2021 01:46:35 +0200 Subject: [PATCH] Close Call - Fixed belt splicing not using or refunding belt connectors - Fixed server crash when opening toolbox --- .../contraptions/relays/belt/BeltSlicer.java | 33 +++++++++++++------ .../toolbox/ToolboxTileEntity.java | 5 +-- .../simibubi/create/events/ClientEvents.java | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlicer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlicer.java index 40d842bad..4446ca388 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlicer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltSlicer.java @@ -71,10 +71,10 @@ public class BeltSlicer { BeltPart part = state.getValue(BeltBlock.PART); List beltChain = BeltBlock.getBeltChain(world, controllerTE.getBlockPos()); boolean creative = player.isCreative(); - + // Shorten from End if (hoveringEnd(state, hit)) { - if (world.isClientSide) + if (world.isClientSide) return ActionResultType.SUCCESS; for (BlockPos blockPos : beltChain) { @@ -160,26 +160,37 @@ public class BeltSlicer { requiredShafts++; int amountRetrieved = 0; + boolean beltFound = false; Search: while (true) { for (int i = 0; i < player.inventory.getContainerSize(); ++i) { - if (amountRetrieved == requiredShafts) + if (amountRetrieved == requiredShafts && beltFound) break Search; ItemStack itemstack = player.inventory.getItem(i); if (itemstack.isEmpty()) continue; int count = itemstack.getCount(); + + if (AllItems.BELT_CONNECTOR.isIn(itemstack)) { + if (!world.isClientSide) + itemstack.shrink(1); + beltFound = true; + continue; + } + if (AllBlocks.SHAFT.isIn(itemstack)) { int taken = Math.min(count, requiredShafts - amountRetrieved); - if (taken == count) - player.inventory.setItem(i, ItemStack.EMPTY); - else - itemstack.shrink(taken); + if (!world.isClientSide) + if (taken == count) + player.inventory.setItem(i, ItemStack.EMPTY); + else + itemstack.shrink(taken); amountRetrieved += taken; } } - player.inventory.placeItemBackInInventory(world, AllBlocks.SHAFT.asStack(amountRetrieved)); + if (!world.isClientSide) + player.inventory.placeItemBackInInventory(world, AllBlocks.SHAFT.asStack(amountRetrieved)); return ActionResultType.FAIL; } } @@ -333,8 +344,10 @@ public class BeltSlicer { state.setValue(BeltBlock.CASING, segmentTE != null && segmentTE.casing != CasingType.NONE) .setValue(BeltBlock.PART, BeltPart.MIDDLE)); - if (!creative) + if (!creative) { player.inventory.placeItemBackInInventory(world, AllBlocks.SHAFT.asStack(2)); + player.inventory.placeItemBackInInventory(world, AllItems.BELT_CONNECTOR.asStack()); + } // Transfer items to other controller BlockPos search = controllerTE.getBlockPos(); @@ -449,7 +462,7 @@ public class BeltSlicer { Feedback feedback = new Feedback(); - // TODO: Populate feedback in the methods for clientside + // TODO: Populate feedback in the methods for clientside if (AllItems.WRENCH.isIn(held) || AllItems.WRENCH.isIn(heldOffHand)) useWrench(state, world, pos, mc.player, Hand.MAIN_HAND, result, feedback); else if (AllItems.BELT_CONNECTOR.isIn(held) || AllItems.BELT_CONNECTOR.isIn(heldOffHand)) diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java index c3a13eb47..3a81b1500 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java @@ -33,6 +33,7 @@ import net.minecraft.util.SoundEvents; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; @@ -366,9 +367,9 @@ public class ToolboxTileEntity extends SmartTileEntity implements INamedContaine @Override public ITextComponent getDisplayName() { return customName != null ? customName - : AllBlocks.TOOLBOXES.get(getColor()) + : new TranslationTextComponent(AllBlocks.TOOLBOXES.get(getColor()) .get() - .getName(); + .getDescriptionId()); } @Override diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 1dad6f595..347b8d9ee 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -126,7 +126,7 @@ public class ClientEvents { // ScreenOpener.tick(); ServerSpeedProvider.clientTick(); BeltConnectorHandler.tick(); - BeltSlicer.tickHoveringInformation(); +// BeltSlicer.tickHoveringInformation(); FilteringRenderer.tick(); LinkRenderer.tick(); ScrollValueRenderer.tick();