Skip to content

Commit

Permalink
Fix interface locations corrupting during upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 13, 2019
1 parent 18a3443 commit 5697b0c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/cyclops/colossalchests/item/ItemUpgradeTool.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -143,14 +147,17 @@ && consumeItems(player, requiredWalls, true))) {
SimpleInventory oldInventory = tile.getLastValidInventory();
Direction oldRotation = tile.getRotation();
Vec3d oldRenderOffset = tile.getRenderOffset();
List<Vec3i> oldInterfaceLocations = tile.getInterfaceLocations();
Wrapper<BlockPos> coreLocation = new Wrapper<>(null);
List<BlockPos> interfaceLocations = Lists.newArrayList();
validMaterial.getChestDetector().detect(world, pos, null, (location, blockState) -> {
BlockState blockStateNew = null;
if (blockState.getBlock() instanceof ColossalChest) {
coreLocation.set(location);
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();
}
Expand All @@ -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));
}

Expand Down

0 comments on commit 5697b0c

Please sign in to comment.