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.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<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
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<TE extends AbstractBellTileEntity> 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);
}
return true;
}

View file

@ -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;
};
@ -50,6 +53,24 @@ public abstract class AbstractBellTileEntity extends SmartTileEntity {
}
}
@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();

View file

@ -31,8 +31,11 @@ public class HauntedBellBlock extends AbstractBellBlock<HauntedBellTileEntity> {
@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();
});
}
}

View file

@ -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() {
effectTicks = EFFECT_TICKS;
sendData();
return super.ring(world, pos, direction);
}
@Override

View file

@ -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);

View file

@ -47,6 +47,17 @@ public class StationBlock extends HorizontalDirectionalBlock implements ITE<Stat
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
public void fillItemCategory(CreativeModeTab pTab, NonNullList<ItemStack> pItems) {
super.fillItemCategory(pTab, pItems);

View file

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