Mildly problematic

- Fixed broken kinetic propagation caused by bracket handling
- Fixed crash when fluid-interfacing with a contraption loaded from disk
This commit is contained in:
simibubi 2020-12-18 18:30:58 +01:00
parent 6c6760ef17
commit 62621f8bdd
7 changed files with 25 additions and 14 deletions

View file

@ -607,7 +607,14 @@ public abstract class Contraption {
int index = 0;
for (MountedStorage mountedStorage : storage.values())
handlers[index++] = mountedStorage.getItemHandler();
IFluidHandler[] fluidHandlers = new IFluidHandler[fluidStorage.size()];
index = 0;
for (MountedFluidStorage mountedStorage : fluidStorage.values())
fluidHandlers[index++] = mountedStorage.getFluidHandler();
inventory = new CombinedInvWrapper(handlers);
fluidInventory = new CombinedTankWrapper(fluidHandlers);
if (nbt.contains("BoundsFront"))
bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5));

View file

@ -123,6 +123,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp
if (!contraption.assemble(world, pos))
return;
if (isWindmill())
AllTriggers.triggerForNearbyPlayers(AllTriggers.WINDMILL, world, pos, 5);
if (contraption.getSailBlocks() >= 16 * 8)
AllTriggers.triggerForNearbyPlayers(AllTriggers.MAXED_WINDMILL, world, pos, 5);

View file

@ -49,7 +49,7 @@ public class AxisPipeBlock extends RotatedPillarBlock implements IWrenchableWith
if (blockTypeChanged && !world.isRemote)
FluidPropagator.propagateChangedPipe(world, pos, state);
if (state != newState && !isMoving)
removeBracket(world, pos).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack));
removeBracket(world, pos, true).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack));
if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity()))
world.removeTileEntity(pos);
}
@ -127,12 +127,12 @@ public class AxisPipeBlock extends RotatedPillarBlock implements IWrenchableWith
}
@Override
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos) {
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos, boolean inOnReplacedContext) {
BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
if (behaviour == null)
return Optional.empty();
BlockState bracket = behaviour.getBracket();
behaviour.removeBracket();
behaviour.removeBracket(inOnReplacedContext);
if (bracket == Blocks.AIR.getDefaultState())
return Optional.empty();
return Optional.of(new ItemStack(bracket.getBlock()));

View file

@ -103,7 +103,7 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren
if (blockTypeChanged && !world.isRemote)
FluidPropagator.propagateChangedPipe(world, pos, state);
if (state != newState && !isMoving)
removeBracket(world, pos).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack));
removeBracket(world, pos, true).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack));
if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity()))
world.removeTileEntity(pos);
}
@ -260,13 +260,13 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren
}
@Override
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos) {
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos, boolean inOnReplacedContext) {
BracketedTileEntityBehaviour behaviour =
BracketedTileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
if (behaviour == null)
return Optional.empty();
BlockState bracket = behaviour.getBracket();
behaviour.removeBracket();
behaviour.removeBracket(inOnReplacedContext);
if (bracket == Blocks.AIR.getDefaultState())
return Optional.empty();
return Optional.of(new ItemStack(bracket.getBlock()));

View file

@ -55,7 +55,7 @@ public abstract class AbstractShaftBlock extends RotatedPillarKineticBlock imple
@SuppressWarnings("deprecation")
public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
if (state != newState && !isMoving)
removeBracket(world, pos).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack));
removeBracket(world, pos, true).ifPresent(stack -> Block.spawnAsEntity(world, pos, stack));
super.onReplaced(state, world, pos, newState, isMoving);
}
@ -102,12 +102,12 @@ public abstract class AbstractShaftBlock extends RotatedPillarKineticBlock imple
}
@Override
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos) {
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos, boolean inOnReplacedContext) {
BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
if (behaviour == null)
return Optional.empty();
BlockState bracket = behaviour.getBracket();
behaviour.removeBracket();
behaviour.removeBracket(inOnReplacedContext);
if (bracket == Blocks.AIR.getDefaultState())
return Optional.empty();
return Optional.of(new ItemStack(bracket.getBlock()));

View file

@ -62,12 +62,15 @@ public class BracketedTileEntityBehaviour extends TileEntityBehaviour {
AllTriggers.triggerFor(trigger.apply(state), player);
}
public void removeBracket() {
public void removeBracket(boolean inOnReplacedContext) {
World world = getWorld();
if (!world.isRemote)
world.playEvent(2001, getPos(), Block.getStateId(getBracket()));
this.bracket = Optional.empty();
reRender = true;
if (inOnReplacedContext)
tileEntity.sendData();
else
tileEntity.notifyUpdate();
}

View file

@ -19,7 +19,7 @@ import net.minecraft.world.World;
public interface IWrenchableWithBracket extends IWrenchable {
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos);
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos, boolean inOnReplacedContext);
@Override
default ActionResultType onWrenched(BlockState state, ItemUseContext context) {
@ -31,7 +31,7 @@ public interface IWrenchableWithBracket extends IWrenchable {
default boolean tryRemoveBracket(ItemUseContext context) {
World world = context.getWorld();
BlockPos pos = context.getPos();
Optional<ItemStack> bracket = removeBracket(world, pos);
Optional<ItemStack> bracket = removeBracket(world, pos, false);
BlockState blockState = world.getBlockState(pos);
if (bracket.isPresent()) {
PlayerEntity player = context.getPlayer();