changed how the wrench rotates blocks
- wrench now rotates the target block around the axis of the face that the it was used on
This commit is contained in:
parent
a4513086a1
commit
f1057bf558
12 changed files with 87 additions and 125 deletions
|
@ -1,13 +1,63 @@
|
|||
package com.simibubi.create.modules.contraptions;
|
||||
|
||||
import com.simibubi.create.foundation.utility.VoxelShaper;
|
||||
import com.simibubi.create.modules.contraptions.base.*;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IWrenchable {
|
||||
|
||||
public default ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
default ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockState rotated = getRotatedBlockState(state, context.getFace());
|
||||
if (!rotated.isValidPosition(world, context.getPos()))
|
||||
return ActionResultType.PASS;
|
||||
|
||||
KineticTileEntity.switchToBlockState(world, context.getPos(), updateAfterWrenched(rotated, context));
|
||||
|
||||
TileEntity te = context.getWorld().getTileEntity(context.getPos());
|
||||
if (te instanceof GeneratingKineticTileEntity) {
|
||||
((GeneratingKineticTileEntity) te).updateGeneratedRotation();
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
default BlockState updateAfterWrenched(BlockState newState, ItemUseContext context) {
|
||||
return newState;
|
||||
}
|
||||
|
||||
static BlockState getRotatedBlockState(BlockState originalState, Direction targetedFace){
|
||||
BlockState newState = originalState;
|
||||
|
||||
if (targetedFace.getAxis() == Direction.Axis.Y) {
|
||||
if (originalState.has(HorizontalAxisKineticBlock.HORIZONTAL_AXIS))
|
||||
return originalState.with(HorizontalAxisKineticBlock.HORIZONTAL_AXIS, VoxelShaper.axisAsFace(originalState.get(HorizontalAxisKineticBlock.HORIZONTAL_AXIS)).rotateAround(targetedFace.getAxis()).getAxis());
|
||||
if (originalState.has(HorizontalKineticBlock.HORIZONTAL_FACING))
|
||||
return originalState.with(HorizontalKineticBlock.HORIZONTAL_FACING, originalState.get(HorizontalKineticBlock.HORIZONTAL_FACING).rotateAround(targetedFace.getAxis()));
|
||||
}
|
||||
|
||||
if (originalState.has(RotatedPillarKineticBlock.AXIS))
|
||||
return originalState.with(RotatedPillarKineticBlock.AXIS, VoxelShaper.axisAsFace(originalState.get(RotatedPillarKineticBlock.AXIS)).rotateAround(targetedFace.getAxis()).getAxis());
|
||||
|
||||
if (!originalState.has(DirectionalKineticBlock.FACING)) return originalState;
|
||||
|
||||
Direction stateFacing = originalState.get(DirectionalKineticBlock.FACING);
|
||||
|
||||
if (stateFacing.getAxis().equals(targetedFace.getAxis())) {
|
||||
if (originalState.has(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE)) return originalState.cycle(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE);
|
||||
else return originalState;
|
||||
} else {
|
||||
do {
|
||||
newState = newState.with(DirectionalKineticBlock.FACING, newState.get(DirectionalKineticBlock.FACING).rotateAround(targetedFace.getAxis()));
|
||||
if (targetedFace.getAxis() == Direction.Axis.Y && newState.has(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE)) newState = newState.cycle(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE);
|
||||
} while (newState.get(DirectionalKineticBlock.FACING).getAxis().equals(targetedFace.getAxis()));
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@ package com.simibubi.create.modules.contraptions.base;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.Rotation;
|
||||
|
@ -86,17 +84,6 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
|
|||
return this.getDefaultState().with(FACING, facing).with(AXIS_ALONG_FIRST_COORDINATE, alongFirst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
Direction face = context.getFace();
|
||||
if ((turnBackOnWrenched() ? face.getOpposite() : face) == state.get(FACING)) {
|
||||
KineticTileEntity.switchToBlockState(world, context.getPos(), state.cycle(AXIS_ALONG_FIRST_COORDINATE));
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return super.onWrenched(state, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Axis getRotationAxis(BlockState state) {
|
||||
Axis pistonAxis = state.get(FACING).getAxis();
|
||||
|
|
|
@ -3,15 +3,12 @@ package com.simibubi.create.modules.contraptions.base;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class DirectionalKineticBlock extends KineticBlock {
|
||||
|
||||
|
@ -45,24 +42,6 @@ public abstract class DirectionalKineticBlock extends KineticBlock {
|
|||
return prefferedSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
Direction facing = turnBackOnWrenched() ? context.getFace().getOpposite() : context.getFace();
|
||||
World world = context.getWorld();
|
||||
if (facing == state.get(FACING))
|
||||
return ActionResultType.PASS;
|
||||
|
||||
BlockState with = state.with(FACING, facing);
|
||||
if (!with.isValidPosition(world, context.getPos()))
|
||||
return ActionResultType.PASS;
|
||||
KineticTileEntity.switchToBlockState(world, context.getPos(), with);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
protected boolean turnBackOnWrenched() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
Direction preferred = getPreferredFacing(context);
|
||||
|
|
|
@ -3,11 +3,9 @@ package com.simibubi.create.modules.contraptions.base;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.Direction.AxisDirection;
|
||||
|
@ -15,7 +13,6 @@ import net.minecraft.util.Mirror;
|
|||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class HorizontalAxisKineticBlock extends KineticBlock {
|
||||
|
||||
|
@ -69,18 +66,6 @@ public abstract class HorizontalAxisKineticBlock extends KineticBlock {
|
|||
return face.getAxis() == state.get(HORIZONTAL_AXIS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
Direction facing = context.getFace();
|
||||
if (facing.getAxis().isVertical())
|
||||
return ActionResultType.PASS;
|
||||
World world = context.getWorld();
|
||||
if (facing.getAxis() == state.get(HORIZONTAL_AXIS))
|
||||
return ActionResultType.PASS;
|
||||
KineticTileEntity.switchToBlockState(world, context.getPos(), state.cycle(HORIZONTAL_AXIS));
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rot) {
|
||||
Axis axis = state.get(HORIZONTAL_AXIS);
|
||||
|
|
|
@ -3,15 +3,12 @@ package com.simibubi.create.modules.contraptions.base;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class HorizontalKineticBlock extends KineticBlock {
|
||||
|
||||
|
@ -52,18 +49,6 @@ public abstract class HorizontalKineticBlock extends KineticBlock {
|
|||
return prefferedSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
Direction facing = context.getFace();
|
||||
if (facing.getAxis().isVertical())
|
||||
return ActionResultType.PASS;
|
||||
World world = context.getWorld();
|
||||
if (facing == state.get(HORIZONTAL_FACING))
|
||||
return ActionResultType.PASS;
|
||||
KineticTileEntity.switchToBlockState(world, context.getPos(), state.with(HORIZONTAL_FACING, facing));
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rot) {
|
||||
return state.with(HORIZONTAL_FACING, rot.rotate(state.get(HORIZONTAL_FACING)));
|
||||
|
|
|
@ -3,15 +3,12 @@ package com.simibubi.create.modules.contraptions.base;
|
|||
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;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class RotatedPillarKineticBlock extends KineticBlock {
|
||||
|
||||
|
@ -72,14 +69,4 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock {
|
|||
: context.getNearestLookingDirection().getAxis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
Axis axis = context.getFace().getAxis();
|
||||
World world = context.getWorld();
|
||||
if (axis == state.get(AXIS))
|
||||
return ActionResultType.PASS;
|
||||
KineticTileEntity.switchToBlockState(world, context.getPos(), state.with(AXIS, axis));
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.modules.contraptions.components.contraptions.bearing;
|
||||
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.Direction;
|
||||
|
@ -25,11 +24,6 @@ public abstract class BearingBlock extends DirectionalKineticBlock {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean turnBackOnWrenched() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Axis getRotationAxis(BlockState state) {
|
||||
return state.get(FACING).getAxis();
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.simibubi.create.foundation.block.IWithTileEntity;
|
|||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -18,11 +17,7 @@ import net.minecraft.state.EnumProperty;
|
|||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
@ -102,11 +97,6 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock
|
|||
return super.onWrenched(state, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean turnBackOnWrenched() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public enum PistonState implements IStringSerializable {
|
||||
RETRACTED, MOVING, EXTENDED;
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@ package com.simibubi.create.modules.contraptions.components.fan;
|
|||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
|
@ -50,15 +50,21 @@ public class EncasedFanBlock extends DirectionalKineticBlock implements IWithTil
|
|||
|
||||
protected void blockUpdate(BlockState state, World worldIn, BlockPos pos) {
|
||||
notifyFanTile(worldIn, pos);
|
||||
if (worldIn.isRemote || state.get(FACING) != Direction.DOWN)
|
||||
if (worldIn.isRemote)
|
||||
return;
|
||||
withTileEntityDo(worldIn, pos, EncasedFanTileEntity::updateGenerator);
|
||||
withTileEntityDo(worldIn, pos, te -> te.updateGenerator(state.get(FACING)));
|
||||
}
|
||||
|
||||
protected void notifyFanTile(IWorld world, BlockPos pos) {
|
||||
withTileEntityDo(world, pos, EncasedFanTileEntity::blockInFrontChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateAfterWrenched(BlockState newState, ItemUseContext context) {
|
||||
blockUpdate(newState, context.getWorld(), context.getPos());
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderLayer getRenderLayer() {
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.simibubi.create.AllTileEntities;
|
|||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.config.CKinetics;
|
||||
import com.simibubi.create.modules.contraptions.base.GeneratingKineticTileEntity;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
|
@ -59,8 +58,8 @@ public class EncasedFanTileEntity extends GeneratingKineticTileEntity {
|
|||
return isGenerator ? AllConfigs.SERVER.kinetics.generatingFanSpeed.get() : 0;
|
||||
}
|
||||
|
||||
public void updateGenerator() {
|
||||
boolean shouldGenerate = world.isBlockPowered(pos) && world.isBlockPresent(pos.down()) && blockBelowIsHot();
|
||||
public void updateGenerator(Direction facing) {
|
||||
boolean shouldGenerate = world.isBlockPowered(pos) && facing == Direction.DOWN && world.isBlockPresent(pos.down()) && blockBelowIsHot();
|
||||
if (shouldGenerate == isGenerator)
|
||||
return;
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ import com.simibubi.create.foundation.block.IWithTileEntity;
|
|||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -109,12 +107,13 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock
|
|||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
Direction facing = context.getFace();
|
||||
if (facing.getAxis().isVertical() && !state.get(VERTICAL)) {
|
||||
KineticTileEntity.switchToBlockState(context.getWorld(), context.getPos(), state.cycle(VERTICAL));
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return super.onWrenched(state, context);
|
||||
BlockState newState = state;
|
||||
|
||||
if (context.getFace().getAxis() != Axis.Y)
|
||||
if (newState.get(HORIZONTAL_AXIS) != context.getFace().getAxis())
|
||||
newState = newState.cycle(VERTICAL);
|
||||
|
||||
return super.onWrenched(newState, context);
|
||||
}
|
||||
|
||||
private BlockState withAxis(Axis axis, BlockItemUseContext context) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.simibubi.create.foundation.utility.Lang;
|
|||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -16,7 +15,6 @@ import net.minecraft.state.EnumProperty;
|
|||
import net.minecraft.state.IProperty;
|
||||
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.Direction.AxisDirection;
|
||||
|
@ -120,6 +118,22 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
|
|||
return stateIn.with(PART, part).with(CONNECTED_ALONG_FIRST_COORDINATE, connectionAlongFirst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateAfterWrenched(BlockState newState, ItemUseContext context) {
|
||||
Blocks.AIR.getDefaultState().updateNeighbors(context.getWorld(), context.getPos(), 1);
|
||||
Axis axis = newState.get(AXIS);
|
||||
newState = getDefaultState().with(AXIS, axis);
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (facing.getAxis() == axis)
|
||||
continue;
|
||||
BlockPos pos = context.getPos();
|
||||
BlockPos offset = pos.offset(facing);
|
||||
newState = updatePostPlacement(newState, facing, context.getWorld().getBlockState(offset), context.getWorld(),
|
||||
pos, offset); }
|
||||
newState.updateNeighbors(context.getWorld(), context.getPos(), 1 | 2);
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
return face.getAxis() == state.get(AXIS);
|
||||
|
@ -169,19 +183,6 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
|
|||
return new EncasedShaftTileEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
Axis axis = state.get(AXIS);
|
||||
boolean connectionAlongFirst = state.get(CONNECTED_ALONG_FIRST_COORDINATE);
|
||||
Axis connectionAxis = connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X)
|
||||
: (axis == Axis.Z ? Axis.Y : Axis.Z);
|
||||
|
||||
if (context.getFace().getAxis() == connectionAxis)
|
||||
return ActionResultType.PASS;
|
||||
|
||||
return super.onWrenched(state, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasStaticPart() {
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue