Ding ding

- Haunted and Peculiar bells now accept redstone power
- Train Stations now emit a comparator signal whenever a Train is present
This commit is contained in:
simibubi 2022-03-18 01:41:16 +01:00
parent 6dd3231b6d
commit 15f4e5ba8d
7 changed files with 71 additions and 30 deletions

View file

@ -12,6 +12,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BellBlock; 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.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
@ -45,6 +46,23 @@ public abstract class AbstractBellBlock<TE extends AbstractBellTileEntity> 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 @Override
public boolean onHit(Level world, BlockState state, BlockHitResult hit, @Nullable Player player, boolean flag) { public boolean onHit(Level world, BlockState state, BlockHitResult hit, @Nullable Player player, boolean flag) {
BlockPos pos = hit.getBlockPos(); BlockPos pos = hit.getBlockPos();
@ -52,20 +70,20 @@ public abstract class AbstractBellBlock<TE extends AbstractBellTileEntity> exten
if (direction == null) if (direction == null)
direction = world.getBlockState(pos) direction = world.getBlockState(pos)
.getValue(FACING); .getValue(FACING);
if (!this.canRingFrom(state, direction, hit.getLocation().y - pos.getY())) if (!this.canRingFrom(state, direction, hit.getLocation().y - pos.getY()))
return false; return false;
return ring(world, pos, direction, player);
}
private boolean ring(Level world, BlockPos pos, Direction direction, Player player) {
TE te = getTileEntity(world, pos); TE te = getTileEntity(world, pos);
if (world.isClientSide)
return true;
if (te == null || !te.ring(world, pos, direction)) if (te == null || !te.ring(world, pos, direction))
return false; return false;
playSound(world, pos);
if (!world.isClientSide) { if (player != null)
playSound(world, pos); player.awardStat(Stats.BELL_RING);
if (player != null)
player.awardStat(Stats.BELL_RING);
}
return true; return true;
} }

View file

@ -5,9 +5,11 @@ import java.util.List;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.NBTHelper;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -33,6 +35,7 @@ public abstract class AbstractBellTileEntity extends SmartTileEntity {
isRinging = true; isRinging = true;
ringingTicks = 0; ringingTicks = 0;
ringDirection = direction; ringDirection = direction;
sendData();
return true; return true;
}; };
@ -49,6 +52,24 @@ public abstract class AbstractBellTileEntity extends SmartTileEntity {
ringingTicks = 0; 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) @OnlyIn(Dist.CLIENT)
public abstract PartialModel getBellModel(); public abstract PartialModel getBellModel();

View file

@ -18,7 +18,7 @@ public class HauntedBellBlock extends AbstractBellBlock<HauntedBellTileEntity> {
public BlockEntityType<? extends HauntedBellTileEntity> getTileEntityType() { public BlockEntityType<? extends HauntedBellTileEntity> getTileEntityType() {
return AllTileEntities.HAUNTED_BELL.get(); return AllTileEntities.HAUNTED_BELL.get();
} }
@Override @Override
public Class<HauntedBellTileEntity> getTileEntityClass() { public Class<HauntedBellTileEntity> getTileEntityClass() {
return HauntedBellTileEntity.class; return HauntedBellTileEntity.class;
@ -31,8 +31,11 @@ public class HauntedBellBlock extends AbstractBellBlock<HauntedBellTileEntity> {
@Override @Override
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean isMoving) { public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean isMoving) {
if (oldState.getBlock() != this) if (oldState.getBlock() != this && !world.isClientSide)
withTileEntityDo(world, pos, HauntedBellTileEntity::startEffect); withTileEntityDo(world, pos, hbte -> {
hbte.effectTicks = HauntedBellTileEntity.EFFECT_TICKS;
hbte.sendData();
});
} }
} }

View file

@ -39,21 +39,9 @@ public class HauntedBellTileEntity extends AbstractBellTileEntity {
public boolean ring(Level world, BlockPos pos, Direction direction) { public boolean ring(Level world, BlockPos pos, Direction direction) {
if (isRinging && ringingTicks < RECHARGE_TICKS) if (isRinging && ringingTicks < RECHARGE_TICKS)
return false; return false;
HauntedBellPulser.sendPulse(world, pos, DISTANCE, false);
if (!super.ring(world, pos, direction))
return false;
if (!world.isClientSide)
HauntedBellPulser.sendPulse(world, pos, DISTANCE, false);
startEffect();
return true;
}
public void startEffect() {
effectTicks = EFFECT_TICKS; effectTicks = EFFECT_TICKS;
sendData(); return super.ring(world, pos, direction);
} }
@Override @Override

View file

@ -176,9 +176,9 @@ public class GlobalRailwayManager {
for (TrackGraph graph : trackNetworks.values()) for (TrackGraph graph : trackNetworks.values())
graph.tickPoints(false); graph.tickPoints(false);
if (AllKeys.isKeyDown(GLFW.GLFW_KEY_K)) // if (AllKeys.isKeyDown(GLFW.GLFW_KEY_K))
trackNetworks.values() // trackNetworks.values()
.forEach(TrackGraph::debugViewReserved); // .forEach(TrackGraph::debugViewReserved);
// if (AllKeys.isKeyDown(GLFW.GLFW_KEY_J) && AllKeys.altDown()) // if (AllKeys.isKeyDown(GLFW.GLFW_KEY_J) && AllKeys.altDown())
// trackNetworks.values() // trackNetworks.values()
// .forEach(TrackGraph::debugViewNodes); // .forEach(TrackGraph::debugViewNodes);

View file

@ -47,6 +47,17 @@ public class StationBlock extends HorizontalDirectionalBlock implements ITE<Stat
super.createBlockStateDefinition(pBuilder.add(FACING, ASSEMBLING)); super.createBlockStateDefinition(pBuilder.add(FACING, ASSEMBLING));
} }
@Override
public boolean hasAnalogOutputSignal(BlockState pState) {
return true;
}
@Override
public int getAnalogOutputSignal(BlockState pState, Level pLevel, BlockPos pPos) {
return getTileEntityOptional(pLevel, pPos).map(ste -> ste.trainPresent ? 15 : 0)
.orElse(0);
}
@Override @Override
public void fillItemCategory(CreativeModeTab pTab, NonNullList<ItemStack> pItems) { public void fillItemCategory(CreativeModeTab pTab, NonNullList<ItemStack> pItems) {
super.fillItemCategory(pTab, pItems); super.fillItemCategory(pTab, pItems);
@ -62,7 +73,7 @@ public class StationBlock extends HorizontalDirectionalBlock implements ITE<Stat
ItemStack itemInHand = pPlayer.getItemInHand(pHand); ItemStack itemInHand = pPlayer.getItemInHand(pHand);
if (AllItems.WRENCH.isIn(itemInHand)) if (AllItems.WRENCH.isIn(itemInHand))
return InteractionResult.PASS; return InteractionResult.PASS;
if (itemInHand.getItem() == Items.SPONGE) if (itemInHand.getItem() == Items.SPONGE)
Create.RAILWAYS.trains.clear(); Create.RAILWAYS.trains.clear();
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
() -> () -> withTileEntityDo(pLevel, pPos, te -> this.displayScreen(te, pPlayer))); () -> () -> withTileEntityDo(pLevel, pPos, te -> this.displayScreen(te, pPlayer)));

View file

@ -164,7 +164,7 @@ public class StationTileEntity extends SmartTileEntity {
this.trainPresent = trainPresent; this.trainPresent = trainPresent;
this.trainCanDisassemble = canDisassemble; this.trainCanDisassemble = canDisassemble;
this.trainBackwards = imminentTrain != null && imminentTrain.currentlyBackwards; this.trainBackwards = imminentTrain != null && imminentTrain.currentlyBackwards;
sendData(); notifyUpdate();
} }
} }