Update 2
This commit is contained in:
parent
3d0cb62437
commit
f2de0513f2
5 changed files with 44 additions and 51 deletions
|
@ -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<FurnaceEngineTi
|
|||
return FurnaceEngineTileEntity.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
TileEntity tileentity = worldIn.getBlockEntity(pos);
|
||||
if (player.getMainHandItem().isEmpty() && tileentity instanceof SteamEngineTileEntity) {
|
||||
if (player.isCrouching()) {
|
||||
((SteamEngineTileEntity) tileentity).getTank().fill(new FluidStack(Fluids.WATER, 1000), IFluidHandler.FluidAction.EXECUTE);
|
||||
} else {
|
||||
player.displayClientMessage(new StringTextComponent("Steam Volume:" + ((SteamEngineTileEntity) tileentity).getTank().getFluidAmount()), false);
|
||||
}
|
||||
}
|
||||
return super.use(state, worldIn, pos, player, handIn, hit);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState p_180655_1_, World p_180655_2_, BlockPos p_180655_3_, Random p_180655_4_) {
|
||||
if (p_180655_1_.getValue(LIT)) {
|
||||
|
|
|
@ -1,82 +1,90 @@
|
|||
package com.teammoeg.steampowered.create;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineBlock;
|
||||
import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineTileEntity;
|
||||
import com.simibubi.create.foundation.block.BlockStressValues;
|
||||
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
||||
import com.teammoeg.steampowered.FluidRegistry;
|
||||
import net.minecraft.block.AbstractFurnaceBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class SteamEngineTileEntity extends EngineTileEntity {
|
||||
public class SteamEngineTileEntity extends EngineTileEntity implements IHaveGoggleInformation {
|
||||
|
||||
private static final float GENERATING_CAPACITY = 128F;
|
||||
private static final float GENERATING_SPEED = 16F;
|
||||
private static final int CONSUMING_STEAM_MB_PER_TICK = 160;
|
||||
private static final int STEAM_STORAGE_MAXIMUM = 160000;
|
||||
private static final float GENERATING_CAPACITY = 32F;
|
||||
private static final float GENERATING_SPEED = 32F;
|
||||
private static final int CONSUMING_STEAM_MB_PER_TICK = 100;
|
||||
private static final int STEAM_STORAGE_MAXIMUM = 100000;
|
||||
|
||||
protected FluidTank tank = new FluidTank(STEAM_STORAGE_MAXIMUM, fluidStack -> {
|
||||
return fluidStack.getFluid() == FluidRegistry.steam.get();
|
||||
});
|
||||
|
||||
private final LazyOptional<IFluidHandler> holder = LazyOptional.of(() -> tank);
|
||||
private LazyOptional<IFluidHandler> holder = LazyOptional.of(() -> tank);
|
||||
|
||||
public SteamEngineTileEntity(TileEntityType<? extends SteamEngineTileEntity> 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<ITextComponent> 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 <T> LazyOptional<T> getCapability(@Nonnull Capability<T> 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<IFluidHandler> oldCap = this.holder;
|
||||
this.holder = LazyOptional.of(() -> {
|
||||
return this.tank;
|
||||
});
|
||||
oldCap.invalidate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 374 B |
Binary file not shown.
After Width: | Height: | Size: 435 B |
Loading…
Reference in a new issue