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; int index = 0;
for (MountedStorage mountedStorage : storage.values()) for (MountedStorage mountedStorage : storage.values())
handlers[index++] = mountedStorage.getItemHandler(); 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); inventory = new CombinedInvWrapper(handlers);
fluidInventory = new CombinedTankWrapper(fluidHandlers);
if (nbt.contains("BoundsFront")) if (nbt.contains("BoundsFront"))
bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5)); bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5));

View file

@ -123,7 +123,8 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp
if (!contraption.assemble(world, pos)) if (!contraption.assemble(world, pos))
return; return;
AllTriggers.triggerForNearbyPlayers(AllTriggers.WINDMILL, world, pos, 5); if (isWindmill())
AllTriggers.triggerForNearbyPlayers(AllTriggers.WINDMILL, world, pos, 5);
if (contraption.getSailBlocks() >= 16 * 8) if (contraption.getSailBlocks() >= 16 * 8)
AllTriggers.triggerForNearbyPlayers(AllTriggers.MAXED_WINDMILL, world, pos, 5); 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) if (blockTypeChanged && !world.isRemote)
FluidPropagator.propagateChangedPipe(world, pos, state); FluidPropagator.propagateChangedPipe(world, pos, state);
if (state != newState && !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));
if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity())) if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity()))
world.removeTileEntity(pos); world.removeTileEntity(pos);
} }
@ -127,12 +127,12 @@ public class AxisPipeBlock extends RotatedPillarBlock implements IWrenchableWith
} }
@Override @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); BracketedTileEntityBehaviour behaviour = TileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
if (behaviour == null) if (behaviour == null)
return Optional.empty(); return Optional.empty();
BlockState bracket = behaviour.getBracket(); BlockState bracket = behaviour.getBracket();
behaviour.removeBracket(); behaviour.removeBracket(inOnReplacedContext);
if (bracket == Blocks.AIR.getDefaultState()) if (bracket == Blocks.AIR.getDefaultState())
return Optional.empty(); return Optional.empty();
return Optional.of(new ItemStack(bracket.getBlock())); 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) if (blockTypeChanged && !world.isRemote)
FluidPropagator.propagateChangedPipe(world, pos, state); FluidPropagator.propagateChangedPipe(world, pos, state);
if (state != newState && !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));
if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity())) if (state.hasTileEntity() && (blockTypeChanged || !newState.hasTileEntity()))
world.removeTileEntity(pos); world.removeTileEntity(pos);
} }
@ -260,13 +260,13 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren
} }
@Override @Override
public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos) { public Optional<ItemStack> removeBracket(IBlockReader world, BlockPos pos, boolean inOnReplacedContext) {
BracketedTileEntityBehaviour behaviour = BracketedTileEntityBehaviour behaviour =
BracketedTileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE); BracketedTileEntityBehaviour.get(world, pos, BracketedTileEntityBehaviour.TYPE);
if (behaviour == null) if (behaviour == null)
return Optional.empty(); return Optional.empty();
BlockState bracket = behaviour.getBracket(); BlockState bracket = behaviour.getBracket();
behaviour.removeBracket(); behaviour.removeBracket(inOnReplacedContext);
if (bracket == Blocks.AIR.getDefaultState()) if (bracket == Blocks.AIR.getDefaultState())
return Optional.empty(); return Optional.empty();
return Optional.of(new ItemStack(bracket.getBlock())); return Optional.of(new ItemStack(bracket.getBlock()));

View file

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

View file

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

View file

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