mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
fix some wrench rotation issues
This commit is contained in:
parent
5299204fb5
commit
0b6098817e
5 changed files with 70 additions and 47 deletions
|
@ -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;
|
||||
|
|
|
@ -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<ConnectionState> 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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue