From 5697b0c41ef1929e5f46a8c3eb531324f3d36851 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Sun, 13 Oct 2019 18:45:38 +0200 Subject: [PATCH] Fix interface locations corrupting during upgrades --- .../colossalchests/item/ItemUpgradeTool.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java b/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java index cd5e6c2d..efddf851 100644 --- a/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java +++ b/src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java @@ -1,5 +1,6 @@ package org.cyclops.colossalchests.item; +import com.google.common.collect.Lists; import lombok.Data; import lombok.EqualsAndHashCode; import net.minecraft.block.BlockState; @@ -23,6 +24,7 @@ import org.cyclops.colossalchests.block.IBlockChestMaterial; import org.cyclops.colossalchests.block.Interface; import org.cyclops.colossalchests.tileentity.TileColossalChest; +import org.cyclops.colossalchests.tileentity.TileInterface; import org.cyclops.cyclopscore.block.multi.DetectionResult; import org.cyclops.cyclopscore.datastructure.Wrapper; import org.cyclops.cyclopscore.helper.BlockHelpers; @@ -34,6 +36,8 @@ import org.cyclops.cyclopscore.inventory.PlayerInventoryIterator; import org.cyclops.cyclopscore.inventory.SimpleInventory; +import java.util.List; + /** * An item to upgrade chests to the next tier. * @author rubensworks @@ -143,7 +147,9 @@ && consumeItems(player, requiredWalls, true))) { SimpleInventory oldInventory = tile.getLastValidInventory(); Direction oldRotation = tile.getRotation(); Vec3d oldRenderOffset = tile.getRenderOffset(); + List oldInterfaceLocations = tile.getInterfaceLocations(); Wrapper coreLocation = new Wrapper<>(null); + List interfaceLocations = Lists.newArrayList(); validMaterial.getChestDetector().detect(world, pos, null, (location, blockState) -> { BlockState blockStateNew = null; if (blockState.getBlock() instanceof ColossalChest) { @@ -151,6 +157,7 @@ && consumeItems(player, requiredWalls, true))) { blockStateNew = newType.getBlockCore().getDefaultState(); } else if (blockState.getBlock() instanceof Interface) { blockStateNew = newType.getBlockInterface().getDefaultState(); + interfaceLocations.add(location); } else if (blockState.getBlock() instanceof ChestWall) { blockStateNew = newType.getBlockWall().getDefaultState(); } @@ -171,7 +178,18 @@ && consumeItems(player, requiredWalls, true))) { tileNew.setMaterial(newType); tileNew.setRotation(oldRotation); tileNew.setRenderOffset(oldRenderOffset); + for (Vec3i oldInterfaceLocation : oldInterfaceLocations) { + tileNew.addInterface(oldInterfaceLocation); + } tileNew.setSize(size); // To trigger the chest size to be updated + + // Set the core position into the newly transformed interfaces + for (BlockPos interfaceLocation : interfaceLocations) { + TileInterface tileInterface = TileHelpers.getSafeTile(world, interfaceLocation, TileInterface.class) + .orElseThrow(() -> new IllegalStateException("Could not find a colossal chest interface location during upgrading.")); + tileInterface.setCorePosition(coreLocation.get()); + } + Advancements.CHEST_FORMED.trigger((ServerPlayerEntity) player, Pair.of(newType, size.getX() + 1)); }