diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java index 0bc036783..d6b69f26d 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellBlock.java @@ -12,6 +12,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BellBlock; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -45,6 +46,23 @@ public abstract class AbstractBellBlock exten } } + @Override + public void neighborChanged(BlockState pState, Level pLevel, BlockPos pPos, Block pBlock, BlockPos pFromPos, + boolean pIsMoving) { + if (pLevel.isClientSide) + return; + boolean shouldPower = pLevel.hasNeighborSignal(pPos); + if (shouldPower == pState.getValue(POWERED)) + return; + pLevel.setBlock(pPos, pState.setValue(POWERED, shouldPower), 3); + if (!shouldPower) + return; + Direction facing = pState.getValue(FACING); + BellAttachType type = pState.getValue(ATTACHMENT); + ring(pLevel, pPos, + type == BellAttachType.CEILING || type == BellAttachType.FLOOR ? facing : facing.getClockWise(), null); + } + @Override public boolean onHit(Level world, BlockState state, BlockHitResult hit, @Nullable Player player, boolean flag) { BlockPos pos = hit.getBlockPos(); @@ -52,20 +70,20 @@ public abstract class AbstractBellBlock exten if (direction == null) direction = world.getBlockState(pos) .getValue(FACING); - if (!this.canRingFrom(state, direction, hit.getLocation().y - pos.getY())) return false; + return ring(world, pos, direction, player); + } + private boolean ring(Level world, BlockPos pos, Direction direction, Player player) { TE te = getTileEntity(world, pos); + if (world.isClientSide) + return true; if (te == null || !te.ring(world, pos, direction)) return false; - - if (!world.isClientSide) { - playSound(world, pos); - if (player != null) - player.awardStat(Stats.BELL_RING); - } - + playSound(world, pos); + if (player != null) + player.awardStat(Stats.BELL_RING); return true; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java index a6ceab29b..98aceda43 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/AbstractBellTileEntity.java @@ -5,9 +5,11 @@ import java.util.List; import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; +import com.simibubi.create.foundation.utility.NBTHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -33,6 +35,7 @@ public abstract class AbstractBellTileEntity extends SmartTileEntity { isRinging = true; ringingTicks = 0; ringDirection = direction; + sendData(); return true; }; @@ -49,6 +52,24 @@ public abstract class AbstractBellTileEntity extends SmartTileEntity { ringingTicks = 0; } } + + @Override + protected void write(CompoundTag tag, boolean clientPacket) { + super.write(tag, clientPacket); + if (!clientPacket || ringingTicks != 0 || !isRinging) + return; + NBTHelper.writeEnum(tag, "Ringing", ringDirection); + } + + @Override + protected void read(CompoundTag tag, boolean clientPacket) { + super.read(tag, clientPacket); + if (!clientPacket || !tag.contains("Ringing")) + return; + ringDirection = NBTHelper.readEnum(tag, "Ringing", Direction.class); + ringingTicks = 0; + isRinging = true; + } @OnlyIn(Dist.CLIENT) public abstract PartialModel getBellModel(); diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellBlock.java b/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellBlock.java index 63b17fd9b..bd589c63a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellBlock.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellBlock.java @@ -18,7 +18,7 @@ public class HauntedBellBlock extends AbstractBellBlock { public BlockEntityType getTileEntityType() { return AllTileEntities.HAUNTED_BELL.get(); } - + @Override public Class getTileEntityClass() { return HauntedBellTileEntity.class; @@ -31,8 +31,11 @@ public class HauntedBellBlock extends AbstractBellBlock { @Override public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean isMoving) { - if (oldState.getBlock() != this) - withTileEntityDo(world, pos, HauntedBellTileEntity::startEffect); + if (oldState.getBlock() != this && !world.isClientSide) + withTileEntityDo(world, pos, hbte -> { + hbte.effectTicks = HauntedBellTileEntity.EFFECT_TICKS; + hbte.sendData(); + }); } } diff --git a/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellTileEntity.java index a81aaa2f1..0de6b9b23 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/bell/HauntedBellTileEntity.java @@ -39,21 +39,9 @@ public class HauntedBellTileEntity extends AbstractBellTileEntity { public boolean ring(Level world, BlockPos pos, Direction direction) { if (isRinging && ringingTicks < RECHARGE_TICKS) return false; - - if (!super.ring(world, pos, direction)) - return false; - - if (!world.isClientSide) - HauntedBellPulser.sendPulse(world, pos, DISTANCE, false); - - startEffect(); - - return true; - } - - public void startEffect() { + HauntedBellPulser.sendPulse(world, pos, DISTANCE, false); effectTicks = EFFECT_TICKS; - sendData(); + return super.ring(world, pos, direction); } @Override diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/GlobalRailwayManager.java b/src/main/java/com/simibubi/create/content/logistics/trains/GlobalRailwayManager.java index 3b1b27359..c0cecc5ec 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/GlobalRailwayManager.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/GlobalRailwayManager.java @@ -176,9 +176,9 @@ public class GlobalRailwayManager { for (TrackGraph graph : trackNetworks.values()) graph.tickPoints(false); - if (AllKeys.isKeyDown(GLFW.GLFW_KEY_K)) - trackNetworks.values() - .forEach(TrackGraph::debugViewReserved); +// if (AllKeys.isKeyDown(GLFW.GLFW_KEY_K)) +// trackNetworks.values() +// .forEach(TrackGraph::debugViewReserved); // if (AllKeys.isKeyDown(GLFW.GLFW_KEY_J) && AllKeys.altDown()) // trackNetworks.values() // .forEach(TrackGraph::debugViewNodes); diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlock.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlock.java index 861657a22..e882b5ef7 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationBlock.java @@ -47,6 +47,17 @@ public class StationBlock extends HorizontalDirectionalBlock implements ITE ste.trainPresent ? 15 : 0) + .orElse(0); + } + @Override public void fillItemCategory(CreativeModeTab pTab, NonNullList pItems) { super.fillItemCategory(pTab, pItems); @@ -62,7 +73,7 @@ public class StationBlock extends HorizontalDirectionalBlock implements ITE () -> withTileEntityDo(pLevel, pPos, te -> this.displayScreen(te, pPlayer))); diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java index cf0a64464..8504aa016 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/edgePoint/station/StationTileEntity.java @@ -164,7 +164,7 @@ public class StationTileEntity extends SmartTileEntity { this.trainPresent = trainPresent; this.trainCanDisassemble = canDisassemble; this.trainBackwards = imminentTrain != null && imminentTrain.currentlyBackwards; - sendData(); + notifyUpdate(); } }