updated display and placement

This commit is contained in:
khj xiaogu 2022-01-15 21:20:10 +08:00
parent 10684fd97d
commit 0b9c3f3643
No known key found for this signature in database
GPG key ID: DEA172814EAFF426
2 changed files with 122 additions and 103 deletions

View file

@ -79,7 +79,7 @@ public class DynamoBlock extends DirectionalKineticBlock implements ITE<DynamoTi
if ((context.getPlayer() != null && context.getPlayer().isShiftKeyDown()) || preferred == null) {
return super.getStateForPlacement(context).setValue(REDSTONE_LOCKED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
}
return defaultBlockState().setValue(FACING, preferred).setValue(REDSTONE_LOCKED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
return defaultBlockState().setValue(FACING, preferred.getOpposite()).setValue(REDSTONE_LOCKED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
}
public DynamoBlock(Properties properties) {

View file

@ -56,13 +56,16 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
private FluidTank tank;
private LazyOptional<IFluidHandler> holder = LazyOptional.of(() -> tank);
private int heatup = 0;
public SteamEngineTileEntity(TileEntityType<? extends SteamEngineTileEntity> type) {
super(type);
this.refreshCapability();
this.tank = new FluidTank(this.getSteamStorage(), fluidStack -> {
ITag<Fluid> steamTag = FluidTags.getAllTags().getTag(new ResourceLocation("forge", "steam"));
if (steamTag != null) return fluidStack.getFluid().is(steamTag);
else return fluidStack.getFluid() == FluidRegistry.steam.get();
if (steamTag != null)
return fluidStack.getFluid().is(steamTag);
else
return fluidStack.getFluid() == FluidRegistry.steam.get();
});
}
@ -72,9 +75,13 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
if (level != null && !level.isClientSide) {
BlockState state = this.level.getBlockState(this.worldPosition);
if (this.poweredWheel == null || this.poweredWheel.isRemoved()) {
this.level.setBlockAndUpdate(this.worldPosition, state.setValue(SteamEngineBlock.LIT, false));
this.refreshWheelSpeed();
heatup = 0;
tank.drain(this.getSteamConsumptionPerTick(), IFluidHandler.FluidAction.EXECUTE);
} else {
if (!tank.isEmpty()&&tank.drain(this.getSteamConsumptionPerTick(), IFluidHandler.FluidAction.EXECUTE).getAmount() >= this.getSteamConsumptionPerTick()) {
if (!tank.isEmpty() && tank.drain(this.getSteamConsumptionPerTick(), IFluidHandler.FluidAction.EXECUTE)
.getAmount() >= this.getSteamConsumptionPerTick()) {
this.level.setBlockAndUpdate(this.worldPosition, state.setValue(SteamEngineBlock.LIT, true));
if (heatup >= 60) {
this.appliedCapacity = this.getGeneratingCapacity();
@ -92,18 +99,26 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
}
}
this.level.sendBlockUpdated(this.getBlockPos(), this.getBlockState(), this.getBlockState(), 3);
this.setChanged();
}
}
public boolean addToGoggleTooltip(List<ITextComponent> tooltip, boolean isPlayerSneaking) {
if (tank.isEmpty() || tank.getFluidAmount() < this.getSteamConsumptionPerTick()) {
tooltip.add(componentSpacing.plainCopy().append(new TranslationTextComponent("tooltip.steampowered.steam_engine.not_enough_steam").withStyle(TextFormatting.RED)));
}else if(heatup<20) {
tooltip.add(componentSpacing.plainCopy().append(new TranslationTextComponent("tooltip.steampowered.steam_engine.heating").withStyle(TextFormatting.YELLOW)));
if (!this.getBlockState().getValue(SteamEngineBlock.LIT)) {
tooltip.add(componentSpacing.plainCopy()
.append(new TranslationTextComponent("tooltip.steampowered.steam_engine.not_enough_steam")
.withStyle(TextFormatting.RED)));
} else if (heatup < 60) {
tooltip.add(componentSpacing.plainCopy()
.append(new TranslationTextComponent("tooltip.steampowered.steam_engine.heating")
.withStyle(TextFormatting.YELLOW)));
} else {
tooltip.add(componentSpacing.plainCopy().append(new TranslationTextComponent("tooltip.steampowered.steam_engine.running").withStyle(TextFormatting.GREEN)));
tooltip.add(componentSpacing.plainCopy()
.append(new TranslationTextComponent("tooltip.steampowered.steam_engine.running")
.withStyle(TextFormatting.GREEN)));
}
return this.containedFluidTooltip(tooltip, isPlayerSneaking, getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY));
return this.containedFluidTooltip(tooltip, isPlayerSneaking,
getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY));
}
protected void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) {
@ -113,9 +128,10 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
}
public void write(CompoundNBT compound, boolean clientPacket) {
super.write(compound, clientPacket);
compound.put("TankContent", tank.writeToNBT(new CompoundNBT()));
compound.putInt("heatup", heatup);
super.write(compound, clientPacket);
}
@Override
@ -124,7 +140,8 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
if (!this.holder.isPresent()) {
this.refreshCapability();
}
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ? holder.cast() : super.getCapability(capability, facing);
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ? holder.cast()
: super.getCapability(capability, facing);
}
private void refreshCapability() {
@ -142,12 +159,14 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
if (this.getFlywheel() == wheelState.getBlock()) {
Direction wheelFacing = (Direction) wheelState.getValue(FlywheelBlock.HORIZONTAL_FACING);
if (wheelFacing.getAxis() == engineFacing.getClockWise().getAxis()) {
if (!FlywheelBlock.isConnected(wheelState) || FlywheelBlock.getConnection(wheelState) == engineFacing.getOpposite()) {
if (!FlywheelBlock.isConnected(wheelState)
|| FlywheelBlock.getConnection(wheelState) == engineFacing.getOpposite()) {
TileEntity te = this.level.getBlockEntity(wheelPos);
if (!te.isRemoved()) {
if (te instanceof FlywheelTileEntity) {
if (!FlywheelBlock.isConnected(wheelState)) {
FlywheelBlock.setConnection(this.level, te.getBlockPos(), te.getBlockState(), engineFacing.getOpposite());
FlywheelBlock.setConnection(this.level, te.getBlockPos(), te.getBlockState(),
engineFacing.getOpposite());
}
this.poweredWheel = (FlywheelTileEntity) te;