fix some wrench rotation issues

This commit is contained in:
zelophed 2021-03-29 20:31:08 +02:00
parent 5299204fb5
commit 0b6098817e
5 changed files with 70 additions and 47 deletions

View file

@ -1,14 +1,5 @@
package com.simibubi.create.content.contraptions.components.fan; 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 mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
@ -19,6 +10,14 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; 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 @MethodsReturnNonnullByDefault
public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements IAirCurrentSource { public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements IAirCurrentSource {
@ -73,12 +72,17 @@ public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements
public void updateGenerator() { public void updateGenerator() {
BlockState blockState = getBlockState(); BlockState blockState = getBlockState();
if (!AllBlocks.ENCASED_FAN.has(blockState)) boolean shouldGenerate = true;
return;
if (blockState.get(EncasedFanBlock.FACING) != Direction.DOWN) if (!AllBlocks.ENCASED_FAN.has(blockState))
return; 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();
boolean shouldGenerate = world.isBlockPowered(pos) && world.isBlockPresent(pos.down()) && blockBelowIsHot();
if (shouldGenerate == isGenerator) if (shouldGenerate == isGenerator)
return; return;
isGenerator = shouldGenerate; isGenerator = shouldGenerate;

View file

@ -1,16 +1,13 @@
package com.simibubi.create.content.contraptions.components.flywheel; 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.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemUseContext;
import net.minecraft.state.EnumProperty; import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer.Builder; import net.minecraft.state.StateContainer.Builder;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.Axis;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.IStringSerializable;
@ -19,6 +16,13 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; 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 class FlywheelBlock extends HorizontalKineticBlock {
public static EnumProperty<ConnectionState> CONNECTION = EnumProperty.create("connection", ConnectionState.class); public static EnumProperty<ConnectionState> CONNECTION = EnumProperty.create("connection", ConnectionState.class);
@ -84,6 +88,24 @@ public class FlywheelBlock extends HorizontalKineticBlock {
return state.get(HORIZONTAL_FACING).getAxis(); 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 { public enum ConnectionState implements IStringSerializable {
NONE, LEFT, RIGHT; NONE, LEFT, RIGHT;

View file

@ -1,15 +1,5 @@
package com.simibubi.create.content.contraptions.components.flywheel.engine; 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.block.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
@ -18,8 +8,14 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; 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 { public class EngineTileEntity extends SmartTileEntity implements IInstanceRendered {
@ -85,16 +81,16 @@ public class EngineTileEntity extends SmartTileEntity implements IInstanceRender
} }
public void detachWheel() { public void detachWheel() {
if (poweredWheel.isRemoved()) if (poweredWheel == null || poweredWheel.isRemoved())
return; return;
poweredWheel.setRotation(0, 0); poweredWheel.setRotation(0, 0);
FlywheelBlock.setConnection(world, poweredWheel.getPos(), poweredWheel.getBlockState(), null); FlywheelBlock.setConnection(world, poweredWheel.getPos(), poweredWheel.getBlockState(), null);
poweredWheel = null;
} }
@Override @Override
public void remove() { public void remove() {
if (poweredWheel != null) detachWheel();
detachWheel();
super.remove(); super.remove();
} }

View file

@ -1,15 +1,5 @@
package com.simibubi.create.content.contraptions.wrench; 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.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; 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.World;
import net.minecraft.world.server.ServerWorld; 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 { public interface IWrenchable {
default ActionResultType onWrenched(BlockState state, ItemUseContext context) { default ActionResultType onWrenched(BlockState state, ItemUseContext context) {
@ -37,7 +37,7 @@ public interface IWrenchable {
if (te != null) if (te != null)
te.updateContainingBlockInfo(); te.updateContainingBlockInfo();
if (te instanceof GeneratingKineticTileEntity) { if (te instanceof GeneratingKineticTileEntity) {
((GeneratingKineticTileEntity) te).updateGeneratedRotation(); ((GeneratingKineticTileEntity) te).reActivateSource = true;
} }
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;

View file

@ -1,9 +1,10 @@
package com.simibubi.create.foundation.utility.animation; package com.simibubi.create.foundation.utility.animation;
import com.simibubi.create.foundation.utility.AngleHelper;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import com.simibubi.create.foundation.utility.AngleHelper;
// Can replace all Interpolated value classes // Can replace all Interpolated value classes
// InterpolatedChasingValue, InterpolatedValue, InterpolatedChasingAngle, InterpolatedAngle // InterpolatedChasingValue, InterpolatedValue, InterpolatedChasingAngle, InterpolatedAngle
public class LerpedFloat { public class LerpedFloat {
@ -82,7 +83,7 @@ public class LerpedFloat {
} }
public boolean settled() { public boolean settled() {
return MathHelper.epsilonEquals(previousValue, value); return MathHelper.epsilonEquals((double) previousValue, value);
} }
public float getChaseTarget() { public float getChaseTarget() {