diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanTileEntity.java index 0a94c83ca..f2c1c6e36 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanTileEntity.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock; import com.simibubi.create.content.logistics.block.chute.ChuteTileEntity; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.utility.BlockHelper; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; @@ -73,12 +72,17 @@ public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements public void updateGenerator() { BlockState blockState = getBlockState(); + boolean shouldGenerate = true; + if (!AllBlocks.ENCASED_FAN.has(blockState)) - return; - if (blockState.get(EncasedFanBlock.FACING) != Direction.DOWN) - return; - - boolean shouldGenerate = world.isBlockPowered(pos) && world.isBlockPresent(pos.down()) && blockBelowIsHot(); + shouldGenerate = false; + + if (shouldGenerate && blockState.get(EncasedFanBlock.FACING) != Direction.DOWN) + shouldGenerate = false; + + if (shouldGenerate) + shouldGenerate = world != null && world.isBlockPowered(pos) && world.isBlockPresent(pos.down()) && blockBelowIsHot(); + if (shouldGenerate == isGenerator) return; isGenerator = shouldGenerate; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelBlock.java index 960f00319..8a4f9255d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelBlock.java @@ -1,16 +1,13 @@ package com.simibubi.create.content.contraptions.components.flywheel; -import com.simibubi.create.AllTileEntities; -import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock; -import com.simibubi.create.foundation.advancement.AllTriggers; -import com.simibubi.create.foundation.utility.Lang; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.BlockItemUseContext; +import net.minecraft.item.ItemUseContext; import net.minecraft.state.EnumProperty; import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.IStringSerializable; @@ -19,6 +16,13 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; +import com.simibubi.create.AllTileEntities; +import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock; +import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineTileEntity; +import com.simibubi.create.content.contraptions.components.flywheel.engine.FurnaceEngineBlock; +import com.simibubi.create.foundation.advancement.AllTriggers; +import com.simibubi.create.foundation.utility.Lang; + public class FlywheelBlock extends HorizontalKineticBlock { public static EnumProperty CONNECTION = EnumProperty.create("connection", ConnectionState.class); @@ -84,6 +88,24 @@ public class FlywheelBlock extends HorizontalKineticBlock { return state.get(HORIZONTAL_FACING).getAxis(); } + @Override + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + Direction connection = getConnection(state); + if (connection == null) + return super.onWrenched(state ,context); + + if (context.getFace().getAxis() == state.get(HORIZONTAL_FACING).getAxis()) + return ActionResultType.PASS; + + World world = context.getWorld(); + BlockPos enginePos = context.getPos().offset(connection, 2); + BlockState engine = world.getBlockState(enginePos); + if (engine.getBlock() instanceof FurnaceEngineBlock) + ((FurnaceEngineBlock) engine.getBlock()).withTileEntityDo(world, enginePos, EngineTileEntity::detachWheel); + + return super.onWrenched(state.with(CONNECTION, ConnectionState.NONE), context); + } + public enum ConnectionState implements IStringSerializable { NONE, LEFT, RIGHT; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java index b4f1f4cf6..da6848b74 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java @@ -76,16 +76,16 @@ public class EngineTileEntity extends SmartTileEntity implements IInstanceRender } public void detachWheel() { - if (poweredWheel.isRemoved()) + if (poweredWheel == null || poweredWheel.isRemoved()) return; poweredWheel.setRotation(0, 0); FlywheelBlock.setConnection(world, poweredWheel.getPos(), poweredWheel.getBlockState(), null); + poweredWheel = null; } @Override public void remove() { - if (poweredWheel != null) - detachWheel(); + detachWheel(); super.remove(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java b/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java index b3a408953..5c28aef5a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java +++ b/src/main/java/com/simibubi/create/content/contraptions/wrench/IWrenchable.java @@ -7,7 +7,6 @@ import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock; import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock; -import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.DirectionHelper; import com.simibubi.create.foundation.utility.VoxelShaper; @@ -38,7 +37,7 @@ public interface IWrenchable { if (te != null) te.updateContainingBlockInfo(); if (te instanceof GeneratingKineticTileEntity) { - ((GeneratingKineticTileEntity) te).updateGeneratedRotation(); + ((GeneratingKineticTileEntity) te).reActivateSource = true; } return ActionResultType.SUCCESS; diff --git a/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java b/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java index 7e99e39cb..8a7a8daeb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java @@ -1,9 +1,10 @@ package com.simibubi.create.foundation.utility.animation; -import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.MathHelper; +import com.simibubi.create.foundation.utility.AngleHelper; + // Can replace all Interpolated value classes // InterpolatedChasingValue, InterpolatedValue, InterpolatedChasingAngle, InterpolatedAngle public class LerpedFloat { @@ -82,7 +83,7 @@ public class LerpedFloat { } public boolean settled() { - return MathHelper.epsilonEquals(previousValue, value); + return MathHelper.epsilonEquals((double) previousValue, value); } public float getChaseTarget() {