From 0b6098817ed876e66003f02066b3664bc4644aa8 Mon Sep 17 00:00:00 2001 From: zelophed Date: Mon, 29 Mar 2021 20:31:08 +0200 Subject: [PATCH] fix some wrench rotation issues --- .../components/fan/EncasedFanTileEntity.java | 32 +++++++++++-------- .../components/flywheel/FlywheelBlock.java | 32 ++++++++++++++++--- .../flywheel/engine/EngineTileEntity.java | 26 +++++++-------- .../contraptions/wrench/IWrenchable.java | 22 ++++++------- .../utility/animation/LerpedFloat.java | 5 +-- 5 files changed, 70 insertions(+), 47 deletions(-) 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 eb5bc626c..02231612b 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 @@ -1,14 +1,5 @@ package com.simibubi.create.content.contraptions.components.fan; -import javax.annotation.Nullable; - -import com.simibubi.create.AllBlocks; -import com.simibubi.create.AllTags.AllBlockTags; -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 mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; @@ -19,6 +10,14 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import javax.annotation.Nullable; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllTags.AllBlockTags; +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; + @MethodsReturnNonnullByDefault public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements IAirCurrentSource { @@ -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 e2bdc323d..6b7322527 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 c2004404a..65aa9ac76 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 @@ -1,15 +1,5 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine; -import java.util.List; - -import com.simibubi.create.AllBlocks; -import com.simibubi.create.CreateClient; -import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock; -import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; -import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered; -import com.simibubi.create.foundation.tileEntity.SmartTileEntity; -import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; - import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; @@ -18,8 +8,14 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.fml.DistExecutor; -import org.apache.http.client.CredentialsProvider; + +import java.util.List; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock; +import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; +import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered; +import com.simibubi.create.foundation.tileEntity.SmartTileEntity; +import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; public class EngineTileEntity extends SmartTileEntity implements IInstanceRendered { @@ -85,16 +81,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 72bae90b2..d18fc2475 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 @@ -1,15 +1,5 @@ package com.simibubi.create.content.contraptions.wrench; -import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; -import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; -import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; -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.DirectionHelper; -import com.simibubi.create.foundation.utility.VoxelShaper; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; @@ -22,6 +12,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; +import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; +import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; +import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; +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.DirectionHelper; +import com.simibubi.create.foundation.utility.VoxelShaper; + public interface IWrenchable { default ActionResultType onWrenched(BlockState state, ItemUseContext context) { @@ -37,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() {