diff --git a/src/main/java/com/teammoeg/steampowered/create/SteamEngineBlock.java b/src/main/java/com/teammoeg/steampowered/create/SteamEngineBlock.java index 0c6f998..bb1791a 100644 --- a/src/main/java/com/teammoeg/steampowered/create/SteamEngineBlock.java +++ b/src/main/java/com/teammoeg/steampowered/create/SteamEngineBlock.java @@ -8,26 +8,22 @@ import com.simibubi.create.content.contraptions.components.flywheel.engine.Furna import com.simibubi.create.foundation.block.ITE; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.fluid.Fluids; import net.minecraft.item.BlockItemUseContext; import net.minecraft.particles.ParticleTypes; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; +import net.minecraft.util.Direction; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; import javax.annotation.Nullable; import java.util.Random; @@ -75,19 +71,6 @@ public class SteamEngineBlock extends EngineBlock implements ITE { return fluidStack.getFluid() == FluidRegistry.steam.get(); }); - private final LazyOptional holder = LazyOptional.of(() -> tank); + private LazyOptional holder = LazyOptional.of(() -> tank); public SteamEngineTileEntity(TileEntityType type) { super(type); } @Override - public void lazyTick() { - if (level != null && !level.isClientSide) { - BlockState state = this.level.getBlockState(this.worldPosition); - if (!tank.isEmpty() && tank.getFluidAmount() > CONSUMING_STEAM_MB_PER_TICK) { + public void tick() { + super.tick(); + BlockState state = this.level.getBlockState(this.worldPosition); + if (!tank.isEmpty()) { + if (tank.getFluidAmount() < CONSUMING_STEAM_MB_PER_TICK) { + tank.drain(tank.getFluidAmount(), IFluidHandler.FluidAction.EXECUTE); + } else { + tank.drain(CONSUMING_STEAM_MB_PER_TICK, IFluidHandler.FluidAction.EXECUTE); state.setValue(SteamEngineBlock.LIT, true); this.appliedCapacity = GENERATING_CAPACITY; this.appliedSpeed = GENERATING_SPEED; this.refreshWheelSpeed(); - tank.drain(CONSUMING_STEAM_MB_PER_TICK, IFluidHandler.FluidAction.EXECUTE); - } else { - state.setValue(SteamEngineBlock.LIT, false); - this.appliedCapacity = 0; - this.appliedSpeed = 0; - this.refreshWheelSpeed(); } + } else { + state.setValue(SteamEngineBlock.LIT, false); + this.appliedCapacity = 0; + this.appliedSpeed = 0; + this.refreshWheelSpeed(); } - super.lazyTick(); + } + + public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { + return this.containedFluidTooltip(tooltip, isPlayerSneaking, getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)); } protected void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) { + super.fromTag(state, compound, clientPacket); tank.readFromNBT(compound.getCompound("TankContent")); } public void write(CompoundNBT compound, boolean clientPacket) { compound.put("TankContent", tank.writeToNBT(new CompoundNBT())); + super.write(compound, clientPacket); } @Override @Nonnull public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) - return holder.cast(); - return super.getCapability(capability, facing); + if (!this.holder.isPresent()) { + this.refreshCapability(); + } + return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ? holder.cast() : super.getCapability(capability, facing); } - public FluidTank getTank() { - return tank; + private void refreshCapability() { + LazyOptional oldCap = this.holder; + this.holder = LazyOptional.of(() -> { + return this.tank; + }); + oldCap.invalidate(); } } diff --git a/src/main/resources/assets/steampowered/lang/en_us.json b/src/main/resources/assets/steampowered/lang/en_us.json index 18e8c13..75bfe95 100644 --- a/src/main/resources/assets/steampowered/lang/en_us.json +++ b/src/main/resources/assets/steampowered/lang/en_us.json @@ -2,5 +2,7 @@ "itemGroup.steampowered": "Create: Steam Powered", "item.steampowered.pressurized_gas_container": "Pressurized Gas Container", "item.steampowered.pressurized_steam_container": "Pressurized Steam Container", - "block.steampowered.steam_engine": "Steam Engine" + "block.steampowered.steam_engine": "Steam Engine", + "fluid.steampowered.steam": "Steam", + "fluid.steampowered.steam_following": "Steam" } \ No newline at end of file diff --git a/src/main/resources/assets/steampowered/textures/block/cogwheel.png b/src/main/resources/assets/steampowered/textures/block/cogwheel.png new file mode 100644 index 0000000..3af909e Binary files /dev/null and b/src/main/resources/assets/steampowered/textures/block/cogwheel.png differ diff --git a/src/main/resources/assets/steampowered/textures/block/large_cogwheel.png b/src/main/resources/assets/steampowered/textures/block/large_cogwheel.png new file mode 100644 index 0000000..6cbb952 Binary files /dev/null and b/src/main/resources/assets/steampowered/textures/block/large_cogwheel.png differ