This commit is contained in:
yuesha-yc 2021-08-29 16:56:44 +08:00
parent bb6fd49762
commit 99c5e754ad
No known key found for this signature in database
GPG key ID: 009D79A802D4ED01
14 changed files with 401 additions and 400 deletions

View file

@ -3,10 +3,10 @@ package com.teammoeg.steampowered;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.simibubi.create.repack.registrate.util.NonNullLazyValue;
import com.teammoeg.steampowered.client.SteamPoweredClient;
import com.teammoeg.steampowered.network.PacketHandler;
import com.teammoeg.steampowered.registrate.SPBlocks;
import com.teammoeg.steampowered.registrate.SPItems;
import com.teammoeg.steampowered.registrate.SPTiles;
import com.teammoeg.steampowered.network.PacketHandler;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

View file

@ -20,60 +20,60 @@ import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
public class AlternatorBlock extends DirectionalKineticBlock implements ITE<AlternatorTileEntity>, IRotate {
public static final VoxelShaper ALTERNATOR_SHAPE = SPShapes.shape(0, 3, 0, 16, 13, 16).add(2, 0, 2, 14, 14, 14).forDirectional();
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return ALTERNATOR_SHAPE.get(state.getValue(FACING));
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction preferred = getPreferredFacing(context);
if ((context.getPlayer() != null && context.getPlayer()
.isShiftKeyDown()) || preferred == null)
return super.getStateForPlacement(context);
return defaultBlockState().setValue(FACING, preferred);
}
public AlternatorBlock(Properties properties) {
super(properties);
}
public static final VoxelShaper ALTERNATOR_SHAPE = SPShapes.shape(0, 3, 0, 16, 13, 16).add(2, 0, 2, 14, 14, 14).forDirectional();
@Override
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
return face == state.getValue(FACING);
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return ALTERNATOR_SHAPE.get(state.getValue(FACING));
}
@Override
public Axis getRotationAxis(BlockState state) {
return state.getValue(FACING)
.getAxis();
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction preferred = getPreferredFacing(context);
if ((context.getPlayer() != null && context.getPlayer()
.isShiftKeyDown()) || preferred == null)
return super.getStateForPlacement(context);
return defaultBlockState().setValue(FACING, preferred);
}
@Override
public Class<AlternatorTileEntity> getTileEntityClass() {
return AlternatorTileEntity.class;
}
public AlternatorBlock(Properties properties) {
super(properties);
}
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return SPTiles.ALTERNATOR.create();
}
@Override
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
return face == state.getValue(FACING);
}
@Override
public SpeedLevel getMinimumRequiredSpeedLevel() {
return SpeedLevel.MEDIUM;
}
@Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
TileEntity tileentity = state.hasTileEntity() ? worldIn.getBlockEntity(pos) : null;
if(tileentity != null) {
if(tileentity instanceof AlternatorTileEntity) {
((AlternatorTileEntity)tileentity).updateCache();
}
}
}
@Override
public Axis getRotationAxis(BlockState state) {
return state.getValue(FACING)
.getAxis();
}
@Override
public Class<AlternatorTileEntity> getTileEntityClass() {
return AlternatorTileEntity.class;
}
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return SPTiles.ALTERNATOR.create();
}
@Override
public SpeedLevel getMinimumRequiredSpeedLevel() {
return SpeedLevel.MEDIUM;
}
@Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
TileEntity tileentity = state.hasTileEntity() ? worldIn.getBlockEntity(pos) : null;
if (tileentity != null) {
if (tileentity instanceof AlternatorTileEntity) {
((AlternatorTileEntity) tileentity).updateCache();
}
}
}
}

View file

@ -1,7 +1,5 @@
package com.teammoeg.steampowered.block;
import static net.minecraft.util.Direction.UP;
import java.util.function.BiFunction;
import com.simibubi.create.foundation.utility.VoxelShaper;
import net.minecraft.block.Block;
import net.minecraft.util.Direction;
@ -10,6 +8,10 @@ import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import java.util.function.BiFunction;
import static net.minecraft.util.Direction.UP;
public class SPShapes {
// From create:AllShapes

View file

@ -75,9 +75,9 @@ public class SteamEngineBlock extends EngineBlock implements ITE<FurnaceEngineTi
@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)) {
double d0 = (double)p_180655_3_.getX() + 0.5D;
double d1 = (double)p_180655_3_.getY();
double d2 = (double)p_180655_3_.getZ() + 0.5D;
double d0 = (double) p_180655_3_.getX() + 0.5D;
double d1 = (double) p_180655_3_.getY();
double d2 = (double) p_180655_3_.getZ() + 0.5D;
if (p_180655_4_.nextDouble() < 0.1D) {
p_180655_2_.playLocalSound(d0, d1, d2, SoundEvents.BLASTFURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
@ -86,9 +86,9 @@ public class SteamEngineBlock extends EngineBlock implements ITE<FurnaceEngineTi
Direction.Axis direction$axis = direction.getAxis();
double d3 = 0.52D;
double d4 = p_180655_4_.nextDouble() * 0.6D - 0.3D;
double d5 = direction$axis == Direction.Axis.X ? (double)direction.getStepX() * 0.52D : d4;
double d5 = direction$axis == Direction.Axis.X ? (double) direction.getStepX() * 0.52D : d4;
double d6 = p_180655_4_.nextDouble() * 9.0D / 16.0D;
double d7 = direction$axis == Direction.Axis.Z ? (double)direction.getStepZ() * 0.52D : d4;
double d7 = direction$axis == Direction.Axis.Z ? (double) direction.getStepZ() * 0.52D : d4;
p_180655_2_.addParticle(ParticleTypes.LAVA, d0 + d5, d1 + d6, d2 + d7, 0.0D, 0.0D, 0.0D);
}
}

View file

@ -5,17 +5,16 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.foundation.render.PartialBufferer;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
public class AlternatorRenderer extends KineticTileEntityRenderer {
public AlternatorRenderer(TileEntityRendererDispatcher dispatcher) {
super(dispatcher);
}
public AlternatorRenderer(TileEntityRendererDispatcher dispatcher) {
super(dispatcher);
}
@Override
protected SuperByteBuffer getRotatedModel(KineticTileEntity te) {
return PartialBufferer.getFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState());
}
@Override
protected SuperByteBuffer getRotatedModel(KineticTileEntity te) {
return PartialBufferer.getFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState());
}
}

View file

@ -49,7 +49,7 @@ public class GasContainerItem extends BucketItem {
} else if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
return ActionResult.pass(itemstack);
} else {
BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult)raytraceresult;
BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) raytraceresult;
BlockPos blockpos = blockraytraceresult.getBlockPos();
Direction direction = blockraytraceresult.getDirection();
BlockPos blockpos1 = blockpos.relative(direction);
@ -59,19 +59,20 @@ public class GasContainerItem extends BucketItem {
// ONLY STEAM ALLOWED
if (blockstate1.getBlock() instanceof FlowingFluidBlock) {
Fluid tempFluid = ((FlowingFluidBlock)blockstate1.getBlock()).getFluid();
Fluid tempFluid = ((FlowingFluidBlock) blockstate1.getBlock()).getFluid();
boolean isSteam = tempFluid != Fluids.EMPTY && tempFluid == FluidRegistry.steam.get();
if (isSteam && blockstate1.getBlock() instanceof IBucketPickupHandler) {
Fluid fluid = ((IBucketPickupHandler)blockstate1.getBlock()).takeLiquid(p_77659_1_, blockpos, blockstate1);
Fluid fluid = ((IBucketPickupHandler) blockstate1.getBlock()).takeLiquid(p_77659_1_, blockpos, blockstate1);
if (fluid != Fluids.EMPTY) {
p_77659_2_.awardStat(Stats.ITEM_USED.get(this));
SoundEvent soundevent = this.content.getAttributes().getFillSound();
if (soundevent == null) soundevent = fluid.is(FluidTags.LAVA) ? SoundEvents.BUCKET_FILL_LAVA : SoundEvents.BUCKET_FILL;
if (soundevent == null)
soundevent = fluid.is(FluidTags.LAVA) ? SoundEvents.BUCKET_FILL_LAVA : SoundEvents.BUCKET_FILL;
p_77659_2_.playSound(soundevent, 1.0F, 1.0F);
ItemStack itemstack1 = DrinkHelper.createFilledResult(itemstack, p_77659_2_, new ItemStack(fluid.getBucket()));
if (!p_77659_1_.isClientSide) {
CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayerEntity)p_77659_2_, new ItemStack(fluid.getBucket()));
CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayerEntity) p_77659_2_, new ItemStack(fluid.getBucket()));
}
return ActionResult.sidedSuccess(itemstack1, p_77659_1_.isClientSide());
@ -86,7 +87,7 @@ public class GasContainerItem extends BucketItem {
if (this.emptyBucket(p_77659_2_, p_77659_1_, blockpos2, blockraytraceresult)) {
this.checkExtraContent(p_77659_1_, itemstack, blockpos2);
if (p_77659_2_ instanceof ServerPlayerEntity) {
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity)p_77659_2_, blockpos2, itemstack);
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity) p_77659_2_, blockpos2, itemstack);
}
p_77659_2_.awardStat(Stats.ITEM_USED.get(this));
@ -110,6 +111,6 @@ public class GasContainerItem extends BucketItem {
}
private boolean canBlockContainFluid(World worldIn, BlockPos posIn, BlockState blockstate) {
return blockstate.getBlock() instanceof ILiquidContainer && ((ILiquidContainer)blockstate.getBlock()).canPlaceLiquid(worldIn, posIn, blockstate, this.content);
return blockstate.getBlock() instanceof ILiquidContainer && ((ILiquidContainer) blockstate.getBlock()).canPlaceLiquid(worldIn, posIn, blockstate, this.content);
}
}

View file

@ -28,130 +28,128 @@ import java.util.List;
*/
public class Multimeter extends Item {
public Multimeter(Properties props) {
super(props);
}
@Override
public ActionResultType useOn(ItemUseContext c) {
TileEntity te = c.getLevel().getBlockEntity(c.getClickedPos());
if(te != null && !c.getLevel().isClientSide()) {
LazyOptional<IEnergyStorage> cap;
cap = te.getCapability(CapabilityEnergy.ENERGY, c.getClickedFace());
if(cap != null) {
IEnergyStorage energy = cap.orElse(null);
String measur = new TranslationTextComponent("item."+SteamPowered.MODID+".multimeter.measuring").getString(Integer.MAX_VALUE);
CompoundNBT tag = c.getItemInHand().getTag();
if(tag == null)
tag = new CompoundNBT();
if(hasPos(tag)) {
if(posEquals(tag, c.getClickedPos(), c.getClickedFace())) {
int de = getDeltaEnergy(tag, energy != null ? energy.getEnergyStored() : 0);
long dt = getDeltaTime(tag, c.getLevel().getGameTime());
measur = " ["+(dt > 0 ? de/dt : 0) + "fe/t ("+(dt)+(new TranslationTextComponent("item."+SteamPowered.MODID+".multimeter.ticks").getString(Integer.MAX_VALUE))+")]";
clearPos(tag);
}
else {
setContent(tag, c.getClickedPos(), c.getClickedFace(), c.getLevel().getGameTime(), energy != null ? energy.getEnergyStored() : 0);
}
}
else {
setContent(tag, c.getClickedPos(), c.getClickedFace(), c.getLevel().getGameTime(), energy != null ? energy.getEnergyStored() : 0);
}
c.getItemInHand().setTag(tag);
c.getPlayer().sendMessage(new TranslationTextComponent("item."+SteamPowered.MODID+".multimeter.title")
.append(new StringTextComponent(" ").append(getTextComponent(energy,
new TranslationTextComponent("item."+SteamPowered.MODID+".multimeter.no_capability").getString(Integer.MAX_VALUE), "fe")).append(new StringTextComponent(" " + measur))),
PlayerEntity.createPlayerUUID(c.getPlayer().getGameProfile()));
return ActionResultType.SUCCESS;
}
}
return ActionResultType.PASS;
}
public static ITextComponent getTextComponent(IEnergyStorage ies, String nan, String unit) {
if(ies == null)
return new StringTextComponent(nan);
return new StringTextComponent(format(ies.getEnergyStored())+unit).withStyle(TextFormatting.AQUA).append(new StringTextComponent(" / ").withStyle(TextFormatting.GRAY)).append(new StringTextComponent(format(ies.getMaxEnergyStored())+unit));
}
public static ITextComponent getTextComponent(IEnergyStorage ies) {
return getTextComponent(ies, "NaN", "fe");
}
public static String format(int n) {
if(n > 1000000)
return Math.round((double)n/100000d)/10d + "M";
if(n > 1000)
return Math.round((double)n/100d)/10d + "K";
return n + "";
}
@Override
public Multimeter(Properties props) {
super(props);
}
@Override
public ActionResultType useOn(ItemUseContext c) {
TileEntity te = c.getLevel().getBlockEntity(c.getClickedPos());
if (te != null && !c.getLevel().isClientSide()) {
LazyOptional<IEnergyStorage> cap;
cap = te.getCapability(CapabilityEnergy.ENERGY, c.getClickedFace());
if (cap != null) {
IEnergyStorage energy = cap.orElse(null);
String measur = new TranslationTextComponent("item." + SteamPowered.MODID + ".multimeter.measuring").getString(Integer.MAX_VALUE);
CompoundNBT tag = c.getItemInHand().getTag();
if (tag == null)
tag = new CompoundNBT();
if (hasPos(tag)) {
if (posEquals(tag, c.getClickedPos(), c.getClickedFace())) {
int de = getDeltaEnergy(tag, energy != null ? energy.getEnergyStored() : 0);
long dt = getDeltaTime(tag, c.getLevel().getGameTime());
measur = " [" + (dt > 0 ? de / dt : 0) + "fe/t (" + (dt) + (new TranslationTextComponent("item." + SteamPowered.MODID + ".multimeter.ticks").getString(Integer.MAX_VALUE)) + ")]";
clearPos(tag);
} else {
setContent(tag, c.getClickedPos(), c.getClickedFace(), c.getLevel().getGameTime(), energy != null ? energy.getEnergyStored() : 0);
}
} else {
setContent(tag, c.getClickedPos(), c.getClickedFace(), c.getLevel().getGameTime(), energy != null ? energy.getEnergyStored() : 0);
}
c.getItemInHand().setTag(tag);
c.getPlayer().sendMessage(new TranslationTextComponent("item." + SteamPowered.MODID + ".multimeter.title")
.append(new StringTextComponent(" ").append(getTextComponent(energy,
new TranslationTextComponent("item." + SteamPowered.MODID + ".multimeter.no_capability").getString(Integer.MAX_VALUE), "fe")).append(new StringTextComponent(" " + measur))),
PlayerEntity.createPlayerUUID(c.getPlayer().getGameProfile()));
return ActionResultType.SUCCESS;
}
}
return ActionResultType.PASS;
}
public static ITextComponent getTextComponent(IEnergyStorage ies, String nan, String unit) {
if (ies == null)
return new StringTextComponent(nan);
return new StringTextComponent(format(ies.getEnergyStored()) + unit).withStyle(TextFormatting.AQUA).append(new StringTextComponent(" / ").withStyle(TextFormatting.GRAY)).append(new StringTextComponent(format(ies.getMaxEnergyStored()) + unit));
}
public static ITextComponent getTextComponent(IEnergyStorage ies) {
return getTextComponent(ies, "NaN", "fe");
}
public static String format(int n) {
if (n > 1000000)
return Math.round((double) n / 100000d) / 10d + "M";
if (n > 1000)
return Math.round((double) n / 100d) / 10d + "K";
return n + "";
}
@Override
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
CompoundNBT nbt = stack.getTag();
super.appendHoverText(stack, worldIn, tooltip, flagIn);
if(hasPos(nbt))
tooltip.add(new TranslationTextComponent("item."+ SteamPowered.MODID+".multimeter.measuring"));
CompoundNBT nbt = stack.getTag();
super.appendHoverText(stack, worldIn, tooltip, flagIn);
if (hasPos(nbt))
tooltip.add(new TranslationTextComponent("item." + SteamPowered.MODID + ".multimeter.measuring"));
}
public static boolean hasPos(CompoundNBT nbt) {
if(nbt == null)
return false;
return nbt.contains("x") && nbt.contains("y") && nbt.contains("z") && nbt.contains("side");
public static boolean hasPos(CompoundNBT nbt) {
if (nbt == null)
return false;
return nbt.contains("x") && nbt.contains("y") && nbt.contains("z") && nbt.contains("side");
}
public static BlockPos getPos(CompoundNBT nbt){
if(nbt == null)
return null;
return new BlockPos(nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"));
public static BlockPos getPos(CompoundNBT nbt) {
if (nbt == null)
return null;
return new BlockPos(nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"));
}
public static int getDeltaEnergy(CompoundNBT nbt, int now){
if(nbt == null)
return 0;
int r = now - nbt.getInt("start");
return r;
public static int getDeltaEnergy(CompoundNBT nbt, int now) {
if (nbt == null)
return 0;
int r = now - nbt.getInt("start");
return r;
}
public static long getDeltaTime(CompoundNBT nbt, long now){
if(nbt == null)
return 0;
long r = now - nbt.getLong("tick");
return r > 0 ? r : 0;
public static long getDeltaTime(CompoundNBT nbt, long now) {
if (nbt == null)
return 0;
long r = now - nbt.getLong("tick");
return r > 0 ? r : 0;
}
public static Direction getDirection(CompoundNBT nbt){
if(nbt == null)
return null;
return Direction.from3DDataValue(nbt.getInt("side"));
public static Direction getDirection(CompoundNBT nbt) {
if (nbt == null)
return null;
return Direction.from3DDataValue(nbt.getInt("side"));
}
public static boolean posEquals(CompoundNBT nbt, BlockPos pos, Direction dir){
return nbt.getInt("x") == pos.getX() && nbt.getInt("y") == pos.getY() && nbt.getInt("z") == pos.getZ() && nbt.getInt("side") == dir.get3DDataValue();
public static boolean posEquals(CompoundNBT nbt, BlockPos pos, Direction dir) {
return nbt.getInt("x") == pos.getX() && nbt.getInt("y") == pos.getY() && nbt.getInt("z") == pos.getZ() && nbt.getInt("side") == dir.get3DDataValue();
}
public static void clearPos(CompoundNBT nbt){
nbt.remove("x");
nbt.remove("y");
nbt.remove("z");
nbt.remove("side");
nbt.remove("tick");
nbt.remove("start");
public static void clearPos(CompoundNBT nbt) {
nbt.remove("x");
nbt.remove("y");
nbt.remove("z");
nbt.remove("side");
nbt.remove("tick");
nbt.remove("start");
}
public static CompoundNBT setContent(CompoundNBT nbt, BlockPos pos, Direction dir, long tick, int energy){
if(nbt == null)
return new CompoundNBT();
nbt.putInt("x", pos.getX());
nbt.putInt("y", pos.getY());
nbt.putInt("z", pos.getZ());
nbt.putInt("side", dir.get3DDataValue());
nbt.putLong("tick", tick);
nbt.putInt("start", energy);
return nbt;
public static CompoundNBT setContent(CompoundNBT nbt, BlockPos pos, Direction dir, long tick, int energy) {
if (nbt == null)
return new CompoundNBT();
nbt.putInt("x", pos.getX());
nbt.putInt("y", pos.getY());
nbt.putInt("z", pos.getZ());
nbt.putInt("side", dir.get3DDataValue());
nbt.putLong("tick", tick);
nbt.putInt("start", energy);
return nbt;
}
}

View file

@ -35,14 +35,14 @@ public class TileSyncPacket {
}
public void handle(Supplier<NetworkEvent.Context> context) {
NetworkEvent.Context ctx = (NetworkEvent.Context)context.get();
NetworkEvent.Context ctx = (NetworkEvent.Context) context.get();
if (ctx.getDirection().getReceptionSide() == LogicalSide.SERVER) {
ctx.enqueueWork(() -> {
ServerWorld world = ((ServerPlayerEntity) Objects.requireNonNull(ctx.getSender())).getLevel();
if (world.isAreaLoaded(this.pos, 1)) {
TileEntity tile = world.getBlockEntity(this.pos);
if (tile instanceof SteamEngineTileEntity) {
((SteamEngineTileEntity)tile).receiveFromClient(this.nbt);
((SteamEngineTileEntity) tile).receiveFromClient(this.nbt);
}
}
@ -53,7 +53,7 @@ public class TileSyncPacket {
if (world != null) {
TileEntity tile = world.getBlockEntity(this.pos);
if (tile instanceof SteamEngineTileEntity) {
((SteamEngineTileEntity)tile).receiveFromServer(this.nbt);
((SteamEngineTileEntity) tile).receiveFromServer(this.nbt);
}
}

View file

@ -5,7 +5,6 @@ import com.simibubi.create.foundation.ponder.PonderRegistrationHelper;
import com.simibubi.create.foundation.ponder.content.KineticsScenes;
import com.simibubi.create.foundation.ponder.content.PonderTag;
import com.teammoeg.steampowered.SteamPowered;
import com.teammoeg.steampowered.ponder.SPScenes;
import com.teammoeg.steampowered.registrate.SPBlocks;
import net.minecraft.util.ResourceLocation;

View file

@ -6,8 +6,8 @@ import com.simibubi.create.foundation.ponder.SceneBuildingUtil;
import com.simibubi.create.foundation.ponder.Selection;
import com.simibubi.create.foundation.ponder.content.PonderPalette;
import com.simibubi.create.foundation.ponder.elements.WorldSectionElement;
import com.teammoeg.steampowered.registrate.SPBlocks;
import com.teammoeg.steampowered.block.SteamEngineBlock;
import com.teammoeg.steampowered.registrate.SPBlocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.FurnaceBlock;
import net.minecraft.util.Direction;
@ -54,7 +54,7 @@ public class SPScenes {
scene.world.hideSection(furnaceSelect, Direction.NORTH);
scene.idle(15);
// Change engine
scene.world.setBlock(enginePos, (BlockState)((BlockState) SPBlocks.STEAM_ENGINE.get().defaultBlockState().setValue(FurnaceBlock.FACING, Direction.NORTH)).setValue(SteamEngineBlock.LIT, true), false);
scene.world.setBlock(enginePos, (BlockState) ((BlockState) SPBlocks.STEAM_ENGINE.get().defaultBlockState().setValue(FurnaceBlock.FACING, Direction.NORTH)).setValue(SteamEngineBlock.LIT, true), false);
scene.world.showSection(furnaceSelect, Direction.NORTH);
scene.idle(10);
scene.world.moveSection(engine, util.vector.of(0.0D, -1.0D, 0.0D), 15);

View file

@ -22,7 +22,7 @@ public class SPBlocks {
private static final CreateRegistrate REGISTRATE = SteamPowered.registrate.get()
.itemGroup(() -> SteamPowered.itemGroup);
public static final BlockEntry<SteamEngineBlock> STEAM_ENGINE = REGISTRATE.block("steam_engine", SteamEngineBlock::new)
public static final BlockEntry<SteamEngineBlock> STEAM_ENGINE = REGISTRATE.block("steam_engine", SteamEngineBlock::new)
.initialProperties(SharedProperties::stone)
.item()
.transform(customItemModel())

View file

@ -34,5 +34,6 @@ public class SPTiles {
.renderer(() -> AlternatorRenderer::new)
.register();
public static void register() {}
public static void register() {
}
}

View file

@ -1,11 +1,8 @@
package com.teammoeg.steampowered.tileentity;
import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.foundation.utility.Lang;
import com.teammoeg.steampowered.SteamPowered;
import com.teammoeg.steampowered.block.AlternatorBlock;
import com.teammoeg.steampowered.item.Multimeter;
@ -25,179 +22,183 @@ import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import java.util.List;
/**
* Adapted from: Create: Crafts & Additions
*/
public class AlternatorTileEntity extends KineticTileEntity {
protected final InternalEnergyStorage energy;
private LazyOptional<IEnergyStorage> lazyEnergy;
private static final int
MAX_IN = 0,
MAX_OUT = 256, // FE Output
CAPACITY = 2048, // FE Storage
STRESS = 4096,
FE_RPM = 80; // Forge Energy conversion rate (in FE/t at max RPM).
private static final double EFFICIENCY = 0.75D;
public AlternatorTileEntity(TileEntityType<?> typeIn) {
super(typeIn);
energy = new InternalEnergyStorage(CAPACITY, MAX_IN, MAX_OUT);
lazyEnergy = LazyOptional.of(() -> energy);
}
@Override
public boolean addToGoggleTooltip(List<ITextComponent> tooltip, boolean isPlayerSneaking) {
tooltip.add(new StringTextComponent(spacing).append(new TranslationTextComponent(SteamPowered.MODID + ".tooltip.energy.production").withStyle(TextFormatting.GRAY)));
tooltip.add(new StringTextComponent(spacing).append(new StringTextComponent(" " + Multimeter.format(getEnergyProductionRate((int) (isSpeedRequirementFulfilled() ? getSpeed() : 0))) + "fe/t ") // fix
.withStyle(TextFormatting.AQUA)).append(Lang.translate("gui.goggles.at_current_speed").withStyle(TextFormatting.DARK_GRAY)));
return super.addToGoggleTooltip(tooltip, isPlayerSneaking);
}
@Override
public float calculateStressApplied() {
float impact = STRESS/256f;
this.lastStressApplied = impact;
return impact;
}
@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
if(cap == CapabilityEnergy.ENERGY && (isEnergyInput(side) || isEnergyOutput(side)))// && !level.isClientSide
return lazyEnergy.cast();
return super.getCapability(cap, side);
}
public boolean isEnergyInput(Direction side) {
return false;
}
protected final InternalEnergyStorage energy;
private LazyOptional<IEnergyStorage> lazyEnergy;
public boolean isEnergyOutput(Direction side) {
return side != getBlockState().getValue(AlternatorBlock.FACING);
}
@Override
public void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) {
super.fromTag(state, compound, clientPacket);
energy.read(compound);
}
@Override
public void write(CompoundNBT compound, boolean clientPacket) {
super.write(compound, clientPacket);
energy.write(compound);
}
private boolean firstTickState = true;
@Override
public void tick() {
super.tick();
if(level != null && level.isClientSide())
return;
if(firstTickState)
firstTick();
firstTickState = false;
if(Math.abs(getSpeed()) > 0 && isSpeedRequirementFulfilled())
energy.internalProduceEnergy(getEnergyProductionRate((int)getSpeed()));
private static final int
MAX_IN = 0,
MAX_OUT = 256, // FE Output
CAPACITY = 2048, // FE Storage
STRESS = 4096,
FE_RPM = 80; // Forge Energy conversion rate (in FE/t at max RPM).
private static final double EFFICIENCY = 0.75D;
for(Direction d : Direction.values()) {
if(!isEnergyOutput(d))
continue;
IEnergyStorage ies = getCachedEnergy(d);
if(ies == null)
continue;
int ext = energy.extractEnergy(ies.receiveEnergy(MAX_OUT, true), false);
int rec = ies.receiveEnergy(ext, false);
}
}
public static int getEnergyProductionRate(int rpm) {
rpm = Math.abs(rpm);
return (int)((double) FE_RPM * ((double)Math.abs(rpm) / 256d) * EFFICIENCY);
}
@Override
protected Block getStressConfigKey() {
return AllBlocks.MECHANICAL_MIXER.get();
}
@Override
public void setRemoved() {
super.setRemoved();
lazyEnergy.invalidate();
}
public void firstTick() {
updateCache();
};
public void updateCache() {
if(level.isClientSide())
return;
for(Direction side : Direction.values()) {
TileEntity te = level.getBlockEntity(worldPosition.relative(side));
if(te == null) {
setCache(side, LazyOptional.empty());
continue;
}
LazyOptional<IEnergyStorage> le = te.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
setCache(side, le);
}
}
private LazyOptional<IEnergyStorage> escacheUp = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheDown = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheNorth = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheEast = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheSouth = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheWest = LazyOptional.empty();
public void setCache(Direction side, LazyOptional<IEnergyStorage> storage) {
switch(side) {
case DOWN:
escacheDown = storage;
break;
case EAST:
escacheEast = storage;
break;
case NORTH:
escacheNorth = storage;
break;
case SOUTH:
escacheSouth = storage;
break;
case UP:
escacheUp = storage;
break;
case WEST:
escacheWest = storage;
break;
}
}
public IEnergyStorage getCachedEnergy(Direction side) {
switch(side) {
case DOWN:
return escacheDown.orElse(null);
case EAST:
return escacheEast.orElse(null);
case NORTH:
return escacheNorth.orElse(null);
case SOUTH:
return escacheSouth.orElse(null);
case UP:
return escacheUp.orElse(null);
case WEST:
return escacheWest.orElse(null);
}
return null;
}
public AlternatorTileEntity(TileEntityType<?> typeIn) {
super(typeIn);
energy = new InternalEnergyStorage(CAPACITY, MAX_IN, MAX_OUT);
lazyEnergy = LazyOptional.of(() -> energy);
}
@Override
public World getWorld() {
return getLevel();
}
@Override
public boolean addToGoggleTooltip(List<ITextComponent> tooltip, boolean isPlayerSneaking) {
tooltip.add(new StringTextComponent(spacing).append(new TranslationTextComponent(SteamPowered.MODID + ".tooltip.energy.production").withStyle(TextFormatting.GRAY)));
tooltip.add(new StringTextComponent(spacing).append(new StringTextComponent(" " + Multimeter.format(getEnergyProductionRate((int) (isSpeedRequirementFulfilled() ? getSpeed() : 0))) + "fe/t ") // fix
.withStyle(TextFormatting.AQUA)).append(Lang.translate("gui.goggles.at_current_speed").withStyle(TextFormatting.DARK_GRAY)));
return super.addToGoggleTooltip(tooltip, isPlayerSneaking);
}
@Override
public float calculateStressApplied() {
float impact = STRESS / 256f;
this.lastStressApplied = impact;
return impact;
}
@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
if (cap == CapabilityEnergy.ENERGY && (isEnergyInput(side) || isEnergyOutput(side)))// && !level.isClientSide
return lazyEnergy.cast();
return super.getCapability(cap, side);
}
public boolean isEnergyInput(Direction side) {
return false;
}
public boolean isEnergyOutput(Direction side) {
return side != getBlockState().getValue(AlternatorBlock.FACING);
}
@Override
public void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) {
super.fromTag(state, compound, clientPacket);
energy.read(compound);
}
@Override
public void write(CompoundNBT compound, boolean clientPacket) {
super.write(compound, clientPacket);
energy.write(compound);
}
private boolean firstTickState = true;
@Override
public void tick() {
super.tick();
if (level != null && level.isClientSide())
return;
if (firstTickState)
firstTick();
firstTickState = false;
if (Math.abs(getSpeed()) > 0 && isSpeedRequirementFulfilled())
energy.internalProduceEnergy(getEnergyProductionRate((int) getSpeed()));
for (Direction d : Direction.values()) {
if (!isEnergyOutput(d))
continue;
IEnergyStorage ies = getCachedEnergy(d);
if (ies == null)
continue;
int ext = energy.extractEnergy(ies.receiveEnergy(MAX_OUT, true), false);
int rec = ies.receiveEnergy(ext, false);
}
}
public static int getEnergyProductionRate(int rpm) {
rpm = Math.abs(rpm);
return (int) ((double) FE_RPM * ((double) Math.abs(rpm) / 256d) * EFFICIENCY);
}
@Override
protected Block getStressConfigKey() {
return AllBlocks.MECHANICAL_MIXER.get();
}
@Override
public void setRemoved() {
super.setRemoved();
lazyEnergy.invalidate();
}
public void firstTick() {
updateCache();
}
;
public void updateCache() {
if (level.isClientSide())
return;
for (Direction side : Direction.values()) {
TileEntity te = level.getBlockEntity(worldPosition.relative(side));
if (te == null) {
setCache(side, LazyOptional.empty());
continue;
}
LazyOptional<IEnergyStorage> le = te.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
setCache(side, le);
}
}
private LazyOptional<IEnergyStorage> escacheUp = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheDown = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheNorth = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheEast = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheSouth = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheWest = LazyOptional.empty();
public void setCache(Direction side, LazyOptional<IEnergyStorage> storage) {
switch (side) {
case DOWN:
escacheDown = storage;
break;
case EAST:
escacheEast = storage;
break;
case NORTH:
escacheNorth = storage;
break;
case SOUTH:
escacheSouth = storage;
break;
case UP:
escacheUp = storage;
break;
case WEST:
escacheWest = storage;
break;
}
}
public IEnergyStorage getCachedEnergy(Direction side) {
switch (side) {
case DOWN:
return escacheDown.orElse(null);
case EAST:
return escacheEast.orElse(null);
case NORTH:
return escacheNorth.orElse(null);
case SOUTH:
return escacheSouth.orElse(null);
case UP:
return escacheUp.orElse(null);
case WEST:
return escacheWest.orElse(null);
}
return null;
}
@Override
public World getWorld() {
return getLevel();
}
}

View file

@ -11,7 +11,7 @@ import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.energy.IEnergyStorage;
public class InternalEnergyStorage extends EnergyStorage {
public InternalEnergyStorage(int capacity) {
public InternalEnergyStorage(int capacity) {
super(capacity, capacity, capacity, 0);
}
@ -26,66 +26,66 @@ public class InternalEnergyStorage extends EnergyStorage {
public InternalEnergyStorage(int capacity, int maxReceive, int maxExtract, int energy) {
super(capacity, maxReceive, maxExtract, energy);
}
public CompoundNBT write(CompoundNBT nbt) {
nbt.putInt("energy", energy);
return nbt;
nbt.putInt("energy", energy);
return nbt;
}
public void read(CompoundNBT nbt) {
setEnergy(nbt.getInt("energy"));
setEnergy(nbt.getInt("energy"));
}
public CompoundNBT write(CompoundNBT nbt, String name) {
nbt.putInt("energy_"+name, energy);
return nbt;
nbt.putInt("energy_" + name, energy);
return nbt;
}
public void read(CompoundNBT nbt, String name) {
setEnergy(nbt.getInt("energy_"+name));
setEnergy(nbt.getInt("energy_" + name));
}
@Override
public boolean canExtract() {
return true;
return true;
}
@Override
public boolean canReceive() {
return true;
return true;
}
public int internalConsumeEnergy(int consume) {
int oenergy = energy;
int oenergy = energy;
energy = Math.max(0, energy - consume);
return oenergy - energy;
}
public int internalProduceEnergy(int produce) {
int oenergy = energy;
int oenergy = energy;
energy = Math.min(capacity, energy + produce);
return oenergy - energy;
}
public void setEnergy(int energy) {
this.energy = energy;
this.energy = energy;
}
@Deprecated
public void outputToSide(World world, BlockPos pos, Direction side, int max) {
TileEntity te = world.getBlockEntity(pos.relative(side));
if(te == null)
return;
LazyOptional<IEnergyStorage> opt = te.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
IEnergyStorage ies = opt.orElse(null);
if(ies == null)
return;
int ext = this.extractEnergy(max, false);
this.receiveEnergy(ext - ies.receiveEnergy(ext, false), false);
TileEntity te = world.getBlockEntity(pos.relative(side));
if (te == null)
return;
LazyOptional<IEnergyStorage> opt = te.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
IEnergyStorage ies = opt.orElse(null);
if (ies == null)
return;
int ext = this.extractEnergy(max, false);
this.receiveEnergy(ext - ies.receiveEnergy(ext, false), false);
}
@Override
public String toString() {
return getEnergyStored() + "/" + getMaxEnergyStored();
return getEnergyStored() + "/" + getMaxEnergyStored();
}
}