mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-13 05:54:01 +01:00
Wrench usage and Smart Cogwheel Placement
- Wrench can now be used properly on most kinetic components - Cogwheels now offset their placement to correct locations automatically - Hand cranks have to be attached to a block now - Mixer and Press can no longer be placed directly above a basin
This commit is contained in:
parent
ce4c5d5c50
commit
b453e6bb2c
@ -3,11 +3,14 @@ package com.simibubi.create.modules.contraptions.base;
|
|||||||
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.BooleanProperty;
|
import net.minecraft.state.BooleanProperty;
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
import net.minecraft.state.StateContainer.Builder;
|
||||||
|
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.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBlock {
|
public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBlock {
|
||||||
@ -30,7 +33,7 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
|
|||||||
facing = facing.getOpposite();
|
facing = facing.getOpposite();
|
||||||
return facing;
|
return facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean getAxisAlignmentForPlacement(BlockItemUseContext context) {
|
protected boolean getAxisAlignmentForPlacement(BlockItemUseContext context) {
|
||||||
return context.getPlacementHorizontalFacing().getAxis() == Axis.X;
|
return context.getPlacementHorizontalFacing().getAxis() == Axis.X;
|
||||||
}
|
}
|
||||||
@ -82,6 +85,23 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
|
|||||||
return this.getDefaultState().with(FACING, facing).with(AXIS_ALONG_FIRST_COORDINATE, alongFirst);
|
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)) {
|
||||||
|
if (!world.isRemote) {
|
||||||
|
BlockPos pos = context.getPos();
|
||||||
|
world.removeTileEntity(pos);
|
||||||
|
world.setBlockState(pos, state.cycle(AXIS_ALONG_FIRST_COORDINATE), 3);
|
||||||
|
KineticTileEntity tileEntity = (KineticTileEntity) world.getTileEntity(pos);
|
||||||
|
tileEntity.attachKinetics();
|
||||||
|
}
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
|
}
|
||||||
|
return super.onWrenched(state, context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
Axis pistonAxis = state.get(FACING).getAxis();
|
Axis pistonAxis = state.get(FACING).getAxis();
|
||||||
@ -98,7 +118,7 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() == getRotationAxis(state);
|
return face.getAxis() == getRotationAxis(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,16 @@ package com.simibubi.create.modules.contraptions.base;
|
|||||||
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.DirectionProperty;
|
import net.minecraft.state.DirectionProperty;
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
import net.minecraft.state.StateContainer.Builder;
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Mirror;
|
import net.minecraft.util.Mirror;
|
||||||
import net.minecraft.util.Rotation;
|
import net.minecraft.util.Rotation;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public abstract class DirectionalKineticBlock extends KineticBlock {
|
public abstract class DirectionalKineticBlock extends KineticBlock {
|
||||||
|
|
||||||
@ -42,6 +46,31 @@ public abstract class DirectionalKineticBlock extends KineticBlock {
|
|||||||
return prefferedSide;
|
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;
|
||||||
|
|
||||||
|
if (!world.isRemote) {
|
||||||
|
BlockPos pos = context.getPos();
|
||||||
|
world.removeTileEntity(pos);
|
||||||
|
world.setBlockState(pos, with, 3);
|
||||||
|
KineticTileEntity tileEntity = (KineticTileEntity) world.getTileEntity(pos);
|
||||||
|
tileEntity.attachKinetics();
|
||||||
|
}
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean turnBackOnWrenched() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||||
Direction preferred = getPreferredFacing(context);
|
Direction preferred = getPreferredFacing(context);
|
||||||
|
@ -3,12 +3,16 @@ package com.simibubi.create.modules.contraptions.base;
|
|||||||
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.IProperty;
|
import net.minecraft.state.IProperty;
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
import net.minecraft.state.StateContainer.Builder;
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Mirror;
|
import net.minecraft.util.Mirror;
|
||||||
import net.minecraft.util.Rotation;
|
import net.minecraft.util.Rotation;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public abstract class HorizontalKineticBlock extends KineticBlock {
|
public abstract class HorizontalKineticBlock extends KineticBlock {
|
||||||
|
|
||||||
@ -49,6 +53,24 @@ public abstract class HorizontalKineticBlock extends KineticBlock {
|
|||||||
return prefferedSide;
|
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;
|
||||||
|
if (!world.isRemote) {
|
||||||
|
BlockPos pos = context.getPos();
|
||||||
|
world.removeTileEntity(pos);
|
||||||
|
world.setBlockState(pos, state.with(HORIZONTAL_FACING, facing), 3);
|
||||||
|
KineticTileEntity tileEntity = (KineticTileEntity) world.getTileEntity(pos);
|
||||||
|
tileEntity.attachKinetics();
|
||||||
|
}
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState rotate(BlockState state, Rotation rot) {
|
public BlockState rotate(BlockState state, Rotation rot) {
|
||||||
return state.with(HORIZONTAL_FACING, rot.rotate(state.get(HORIZONTAL_FACING)));
|
return state.with(HORIZONTAL_FACING, rot.rotate(state.get(HORIZONTAL_FACING)));
|
||||||
|
@ -8,7 +8,7 @@ import net.minecraft.util.Direction;
|
|||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
|
|
||||||
public interface IRotate extends IWrenchable {
|
public interface IRotate extends IWrenchable {
|
||||||
|
|
||||||
@ -61,9 +61,9 @@ public interface IRotate extends IWrenchable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face);
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face);
|
||||||
|
|
||||||
public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face);
|
public boolean hasCogsTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face);
|
||||||
|
|
||||||
public Axis getRotationAxis(BlockState state);
|
public Axis getRotationAxis(BlockState state);
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import net.minecraft.util.Direction.Axis;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ToolType;
|
import net.minecraftforge.common.ToolType;
|
||||||
|
|
||||||
@ -49,12 +50,12 @@ public abstract class KineticBlock extends Block implements IRotate {
|
|||||||
// IRotate
|
// IRotate
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasCogsTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import net.minecraft.util.math.Vec3d;
|
|||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
@ -65,7 +66,7 @@ public class DrillBlock extends DirectionalKineticBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face == state.get(FACING).getOpposite();
|
return face == state.get(FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ public class DrillBlock extends DirectionalKineticBlock
|
|||||||
protected boolean hasStaticPart() {
|
protected boolean hasStaticPart() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@OnlyIn(value = Dist.CLIENT)
|
@OnlyIn(value = Dist.CLIENT)
|
||||||
public SuperByteBuffer renderInContraption(MovementContext context) {
|
public SuperByteBuffer renderInContraption(MovementContext context) {
|
||||||
|
@ -11,6 +11,7 @@ import net.minecraft.util.Direction;
|
|||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class MechanicalBearingBlock extends DirectionalKineticBlock
|
public class MechanicalBearingBlock extends DirectionalKineticBlock
|
||||||
@ -35,7 +36,7 @@ public class MechanicalBearingBlock extends DirectionalKineticBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face == state.get(FACING).getOpposite();
|
return face == state.get(FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +45,11 @@ public class MechanicalBearingBlock extends DirectionalKineticBlock
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean turnBackOnWrenched() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
return state.get(FACING).getAxis();
|
return state.get(FACING).getAxis();
|
||||||
|
@ -10,11 +10,13 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.particles.ParticleTypes;
|
import net.minecraft.particles.ParticleTypes;
|
||||||
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.state.properties.BlockStateProperties;
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
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.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.IStringSerializable;
|
import net.minecraft.util.IStringSerializable;
|
||||||
@ -84,6 +86,18 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||||
|
if (state.get(STATE) != PistonState.RETRACTED)
|
||||||
|
return ActionResultType.PASS;
|
||||||
|
return super.onWrenched(state, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean turnBackOnWrenched() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public enum PistonState implements IStringSerializable {
|
public enum PistonState implements IStringSerializable {
|
||||||
RETRACTED, MOVING, EXTENDED;
|
RETRACTED, MOVING, EXTENDED;
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
import net.minecraft.util.math.BlockRayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasCogsTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return state.get(HORIZONTAL_FACING).getAxis() != face.getAxis();
|
return state.get(HORIZONTAL_FACING).getAxis() != face.getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,10 @@ import com.simibubi.create.foundation.block.IWithTileEntity;
|
|||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
import com.simibubi.create.foundation.utility.AllShapes;
|
||||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
@ -16,6 +18,7 @@ import net.minecraft.util.math.BlockRayTraceResult;
|
|||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class HandCrankBlock extends DirectionalKineticBlock implements IWithTileEntity<HandCrankTileEntity> {
|
public class HandCrankBlock extends DirectionalKineticBlock implements IWithTileEntity<HandCrankTileEntity> {
|
||||||
@ -23,7 +26,7 @@ public class HandCrankBlock extends DirectionalKineticBlock implements IWithTile
|
|||||||
public HandCrankBlock() {
|
public HandCrankBlock() {
|
||||||
super(Properties.from(AllBlocks.COGWHEEL.get()));
|
super(Properties.from(AllBlocks.COGWHEEL.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||||
return AllShapes.CRANK.get(state.get(FACING));
|
return AllShapes.CRANK.get(state.get(FACING));
|
||||||
@ -33,29 +36,60 @@ public class HandCrankBlock extends DirectionalKineticBlock implements IWithTile
|
|||||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||||
BlockRayTraceResult hit) {
|
BlockRayTraceResult hit) {
|
||||||
boolean handEmpty = player.getHeldItem(handIn).isEmpty();
|
boolean handEmpty = player.getHeldItem(handIn).isEmpty();
|
||||||
|
|
||||||
if (!handEmpty && player.isSneaking())
|
if (!handEmpty && player.isSneaking())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
withTileEntityDo(worldIn, pos, te -> te.turn(player.isSneaking()));
|
withTileEntityDo(worldIn, pos, te -> te.turn(player.isSneaking()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||||
|
Direction preferred = getPreferredFacing(context);
|
||||||
|
if (preferred == null || context.isPlacerSneaking())
|
||||||
|
return getDefaultState().with(FACING, context.getFace());
|
||||||
|
return getDefaultState().with(FACING, preferred.getOpposite());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
||||||
|
Direction facing = state.get(FACING).getOpposite();
|
||||||
|
BlockPos neighbourPos = pos.offset(facing);
|
||||||
|
BlockState neighbour = worldIn.getBlockState(neighbourPos);
|
||||||
|
return !neighbour.getCollisionShape(worldIn, neighbourPos).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||||
|
boolean isMoving) {
|
||||||
|
if (worldIn.isRemote)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Direction blockFacing = state.get(FACING);
|
||||||
|
if (fromPos.equals(pos.offset(blockFacing.getOpposite()))) {
|
||||||
|
if (!isValidPosition(state, worldIn, pos)) {
|
||||||
|
worldIn.destroyBlock(pos, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||||
return new HandCrankTileEntity();
|
return new HandCrankTileEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasStaticPart() {
|
protected boolean hasStaticPart() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face == state.get(FACING).getOpposite();
|
return face == state.get(FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
return state.get(FACING).getAxis();
|
return state.get(FACING).getAxis();
|
||||||
|
@ -145,7 +145,7 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.get(AXIS);
|
return face.getAxis() == state.get(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import net.minecraft.util.Direction.Axis;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class EncasedFanBlock extends DirectionalKineticBlock implements IWithTileEntity<EncasedFanTileEntity> {
|
public class EncasedFanBlock extends DirectionalKineticBlock implements IWithTileEntity<EncasedFanTileEntity> {
|
||||||
@ -74,7 +75,7 @@ public class EncasedFanBlock extends DirectionalKineticBlock implements IWithTil
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face == state.get(FACING).getOpposite();
|
return face == state.get(FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.simibubi.create.modules.contraptions.components.mixer;
|
||||||
|
|
||||||
|
import com.simibubi.create.AllBlocks;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
|
import net.minecraft.util.ActionResultType;
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class BasinOperatorBlockItem extends BlockItem {
|
||||||
|
|
||||||
|
public BasinOperatorBlockItem(AllBlocks block, Properties builder) {
|
||||||
|
super(block.get(), builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResultType tryPlace(BlockItemUseContext context) {
|
||||||
|
|
||||||
|
BlockPos placedOnPos = context.getPos().offset(context.getFace().getOpposite());
|
||||||
|
BlockState placedOnState = context.getWorld().getBlockState(placedOnPos);
|
||||||
|
if (AllBlocks.BASIN.typeOf(placedOnState)) {
|
||||||
|
if (context.getWorld().getBlockState(placedOnPos.up(2)).getMaterial().isReplaceable())
|
||||||
|
context = BlockItemUseContext.func_221536_a(context, placedOnPos.up(2), Direction.UP);
|
||||||
|
else
|
||||||
|
return ActionResultType.FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.tryPlace(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,9 +12,7 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ActionResultType;
|
|
||||||
import net.minecraft.util.BlockRenderLayer;
|
import net.minecraft.util.BlockRenderLayer;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
@ -24,7 +22,7 @@ import net.minecraft.util.math.shapes.ISelectionContext;
|
|||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
|
|
||||||
public class MechanicalMixerBlock extends KineticBlock
|
public class MechanicalMixerBlock extends KineticBlock
|
||||||
implements IWithTileEntity<MechanicalMixerTileEntity>, IHaveScrollableValue, IHaveCustomBlockItem {
|
implements IWithTileEntity<MechanicalMixerTileEntity>, IHaveScrollableValue, IHaveCustomBlockItem {
|
||||||
@ -44,6 +42,11 @@ public class MechanicalMixerBlock extends KineticBlock
|
|||||||
protected boolean hasStaticPart() {
|
protected boolean hasStaticPart() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
||||||
|
return !AllBlocks.BASIN.typeOf(worldIn.getBlockState(pos.down()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||||
@ -64,38 +67,15 @@ public class MechanicalMixerBlock extends KineticBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasCogsTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis().isHorizontal();
|
return face.getAxis().isHorizontal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MechanicalMixerBlockItem extends BlockItem {
|
|
||||||
|
|
||||||
public MechanicalMixerBlockItem(Properties builder) {
|
|
||||||
super(AllBlocks.MECHANICAL_MIXER.get(), builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResultType tryPlace(BlockItemUseContext context) {
|
|
||||||
|
|
||||||
BlockPos placedOnPos = context.getPos().offset(context.getFace().getOpposite());
|
|
||||||
BlockState placedOnState = context.getWorld().getBlockState(placedOnPos);
|
|
||||||
if (AllBlocks.BASIN.typeOf(placedOnState)) {
|
|
||||||
if (context.getWorld().getBlockState(placedOnPos.up(2)).getMaterial().isReplaceable())
|
|
||||||
context = BlockItemUseContext.func_221536_a(context, placedOnPos.up(2), Direction.UP);
|
|
||||||
else
|
|
||||||
return ActionResultType.FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.tryPlace(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueName(BlockState state, IWorld world, BlockPos pos) {
|
public String getValueName(BlockState state, IWorld world, BlockPos pos) {
|
||||||
return Lang.translate("mechanical_mixer.min_ingredients");
|
return Lang.translate("mechanical_mixer.min_ingredients");
|
||||||
@ -156,7 +136,7 @@ public class MechanicalMixerBlock extends KineticBlock
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockItem getCustomItem(net.minecraft.item.Item.Properties properties) {
|
public BlockItem getCustomItem(net.minecraft.item.Item.Properties properties) {
|
||||||
return new MechanicalMixerBlockItem(properties);
|
return new BasinOperatorBlockItem(AllBlocks.MECHANICAL_MIXER, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import net.minecraft.util.math.shapes.ISelectionContext;
|
|||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
|
|
||||||
public class MotorBlock extends HorizontalKineticBlock
|
public class MotorBlock extends HorizontalKineticBlock
|
||||||
implements IWithTileEntity<MotorTileEntity>, IHaveScrollableValue {
|
implements IWithTileEntity<MotorTileEntity>, IHaveScrollableValue {
|
||||||
@ -50,7 +50,7 @@ public class MotorBlock extends HorizontalKineticBlock
|
|||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face == state.get(HORIZONTAL_FACING);
|
return face == state.get(HORIZONTAL_FACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,14 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
|
import com.simibubi.create.foundation.block.IHaveCustomBlockItem;
|
||||||
import com.simibubi.create.foundation.block.IRenderUtilityBlock;
|
import com.simibubi.create.foundation.block.IRenderUtilityBlock;
|
||||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
||||||
import com.simibubi.create.foundation.item.ItemHelper;
|
import com.simibubi.create.foundation.item.ItemHelper;
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
import com.simibubi.create.foundation.utility.AllShapes;
|
||||||
import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock;
|
import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock;
|
||||||
|
import com.simibubi.create.modules.contraptions.components.mixer.BasinOperatorBlockItem;
|
||||||
import com.simibubi.create.modules.contraptions.components.press.MechanicalPressTileEntity.Mode;
|
import com.simibubi.create.modules.contraptions.components.press.MechanicalPressTileEntity.Mode;
|
||||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState;
|
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState;
|
||||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment;
|
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment;
|
||||||
@ -24,6 +26,7 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.HorizontalBlock;
|
import net.minecraft.block.HorizontalBlock;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
import net.minecraft.state.StateContainer.Builder;
|
||||||
@ -35,10 +38,11 @@ import net.minecraft.util.math.shapes.ISelectionContext;
|
|||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class MechanicalPressBlock extends HorizontalKineticBlock
|
public class MechanicalPressBlock extends HorizontalKineticBlock
|
||||||
implements IWithTileEntity<MechanicalPressTileEntity>, IBeltAttachment {
|
implements IWithTileEntity<MechanicalPressTileEntity>, IBeltAttachment, IHaveCustomBlockItem {
|
||||||
|
|
||||||
public MechanicalPressBlock() {
|
public MechanicalPressBlock() {
|
||||||
super(Properties.from(Blocks.PISTON));
|
super(Properties.from(Blocks.PISTON));
|
||||||
@ -52,6 +56,11 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||||||
return AllShapes.MECHANICAL_PROCESSOR_SHAPE;
|
return AllShapes.MECHANICAL_PROCESSOR_SHAPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
||||||
|
return !AllBlocks.BASIN.typeOf(worldIn.getBlockState(pos.down()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||||
boolean isMoving) {
|
boolean isMoving) {
|
||||||
@ -89,7 +98,7 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.get(HORIZONTAL_FACING).getAxis();
|
return face.getAxis() == state.get(HORIZONTAL_FACING).getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,10 +166,10 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||||||
if (pressTe.running) {
|
if (pressTe.running) {
|
||||||
if (pressTe.runningTicks == 30) {
|
if (pressTe.runningTicks == 30) {
|
||||||
Optional<PressingRecipe> recipe = pressTe.getRecipe(transportedStack.stack);
|
Optional<PressingRecipe> recipe = pressTe.getRecipe(transportedStack.stack);
|
||||||
|
|
||||||
pressTe.pressedItems.clear();
|
pressTe.pressedItems.clear();
|
||||||
pressTe.pressedItems.add(transportedStack.stack);
|
pressTe.pressedItems.add(transportedStack.stack);
|
||||||
|
|
||||||
if (!recipe.isPresent())
|
if (!recipe.isPresent())
|
||||||
return false;
|
return false;
|
||||||
ItemStack out = recipe.get().getRecipeOutput().copy();
|
ItemStack out = recipe.get().getRecipeOutput().copy();
|
||||||
@ -192,5 +201,10 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||||||
super.fillStateContainer(builder);
|
super.fillStateContainer(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockItem getCustomItem(net.minecraft.item.Item.Properties properties) {
|
||||||
|
return new BasinOperatorBlockItem(AllBlocks.MECHANICAL_PRESS, properties);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import net.minecraft.util.math.MathHelper;
|
|||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class SawBlock extends DirectionalAxisKineticBlock
|
public class SawBlock extends DirectionalAxisKineticBlock
|
||||||
@ -112,7 +113,7 @@ public class SawBlock extends DirectionalAxisKineticBlock
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return isHorizontal(state) ? face == state.get(FACING).getOpposite()
|
return isHorizontal(state) ? face == state.get(FACING).getOpposite()
|
||||||
: super.hasShaftTowards(world, pos, state, face);
|
: super.hasShaftTowards(world, pos, state, face);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import net.minecraft.util.math.Vec3d;
|
|||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TurntableBlock extends KineticBlock {
|
public class TurntableBlock extends KineticBlock {
|
||||||
@ -85,7 +86,7 @@ public class TurntableBlock extends KineticBlock {
|
|||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face == Direction.DOWN;
|
return face == Direction.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return state.get(HORIZONTAL_FACING).getAxis() == face.getAxis();
|
return state.get(HORIZONTAL_FACING).getAxis() == face.getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ import net.minecraft.util.math.shapes.ISelectionContext;
|
|||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.Tags;
|
import net.minecraftforge.common.Tags;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
@ -63,7 +64,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IHaveNoBlockIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
if (face.getAxis() != getRotationAxis(state))
|
if (face.getAxis() != getRotationAxis(state))
|
||||||
return false;
|
return false;
|
||||||
BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos);
|
BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos);
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
package com.simibubi.create.modules.contraptions.relays.elementary;
|
package com.simibubi.create.modules.contraptions.relays.elementary;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
|
import com.simibubi.create.foundation.block.IHaveCustomBlockItem;
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
import com.simibubi.create.foundation.utility.AllShapes;
|
||||||
import com.simibubi.create.modules.contraptions.base.IRotate;
|
import com.simibubi.create.modules.contraptions.base.IRotate;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
|
import net.minecraft.util.Direction.Axis;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorldReader;
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class CogWheelBlock extends ShaftBlock {
|
public class CogWheelBlock extends ShaftBlock implements IHaveCustomBlockItem {
|
||||||
|
|
||||||
private boolean isLarge;
|
private boolean isLarge;
|
||||||
|
|
||||||
@ -53,8 +55,12 @@ public class CogWheelBlock extends ShaftBlock {
|
|||||||
Block block = placedAgainst.getBlock();
|
Block block = placedAgainst.getBlock();
|
||||||
|
|
||||||
if (!(block instanceof IRotate) || !(((IRotate) block).hasCogsTowards(context.getWorld(), placedOnPos,
|
if (!(block instanceof IRotate) || !(((IRotate) block).hasCogsTowards(context.getWorld(), placedOnPos,
|
||||||
placedAgainst, context.getFace())))
|
placedAgainst, context.getFace()))) {
|
||||||
return super.getStateForPlacement(context);
|
Axis preferredAxis = getPreferredAxis(context);
|
||||||
|
if (preferredAxis != null)
|
||||||
|
return this.getDefaultState().with(AXIS, preferredAxis);
|
||||||
|
return this.getDefaultState().with(AXIS, context.getFace().getAxis());
|
||||||
|
}
|
||||||
|
|
||||||
return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst));
|
return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst));
|
||||||
}
|
}
|
||||||
@ -76,8 +82,13 @@ public class CogWheelBlock extends ShaftBlock {
|
|||||||
// IRotate
|
// IRotate
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCogsTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasCogsTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return !isLarge && face.getAxis() != state.get(AXIS);
|
return !isLarge && face.getAxis() != state.get(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockItem getCustomItem(net.minecraft.item.Item.Properties properties) {
|
||||||
|
return new CogwheelBlockItem(this, properties, isLarge);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.simibubi.create.modules.contraptions.relays.elementary;
|
||||||
|
|
||||||
|
import com.simibubi.create.AllBlocks;
|
||||||
|
import com.simibubi.create.foundation.utility.Debug;
|
||||||
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
|
import net.minecraft.util.ActionResultType;
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
|
import net.minecraft.util.Direction.Axis;
|
||||||
|
import net.minecraft.util.Direction.AxisDirection;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
public class CogwheelBlockItem extends BlockItem {
|
||||||
|
|
||||||
|
boolean large;
|
||||||
|
|
||||||
|
public CogwheelBlockItem(Block block, Properties builder, boolean isLarge) {
|
||||||
|
super(block, builder);
|
||||||
|
large = isLarge;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResultType tryPlace(BlockItemUseContext context) {
|
||||||
|
Direction face = context.getFace();
|
||||||
|
BlockPos placedOnPos = context.getPos().offset(face.getOpposite());
|
||||||
|
BlockState placedOnState = context.getWorld().getBlockState(placedOnPos);
|
||||||
|
|
||||||
|
if (!(placedOnState.getBlock() instanceof CogWheelBlock))
|
||||||
|
return super.tryPlace(context);
|
||||||
|
if (face.getAxis() == placedOnState.get(CogWheelBlock.AXIS))
|
||||||
|
return super.tryPlace(context);
|
||||||
|
|
||||||
|
boolean placedOnLarge = AllBlocks.LARGE_COGWHEEL.typeOf(placedOnState);
|
||||||
|
if (placedOnLarge || large) {
|
||||||
|
|
||||||
|
boolean largeOnLarge = placedOnLarge && large;
|
||||||
|
Axis offsetAxis = Axis.X;
|
||||||
|
for (Axis axis : Axis.values()) {
|
||||||
|
if (placedOnState.get(CogWheelBlock.AXIS) == axis)
|
||||||
|
continue;
|
||||||
|
if (axis == face.getAxis())
|
||||||
|
continue;
|
||||||
|
offsetAxis = axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (largeOnLarge)
|
||||||
|
offsetAxis = placedOnState.get(CogWheelBlock.AXIS);
|
||||||
|
|
||||||
|
Vec3d hitVec = context.getHitVec().subtract(VecHelper.getCenterOf(placedOnPos));
|
||||||
|
hitVec = hitVec
|
||||||
|
.mul(new Vec3d(Direction.getFacingFromAxis(AxisDirection.POSITIVE, offsetAxis).getDirectionVec()));
|
||||||
|
|
||||||
|
BlockPos correctPos = context.getPos().add(Math.signum(hitVec.x), Math.signum(hitVec.y),
|
||||||
|
Math.signum(hitVec.z));
|
||||||
|
|
||||||
|
if (context.getWorld().getBlockState(correctPos).getMaterial().isReplaceable())
|
||||||
|
context = BlockItemUseContext.func_221536_a(context, correctPos, largeOnLarge ? face
|
||||||
|
: Direction.getFacingFromAxis(AxisDirection.POSITIVE, placedOnState.get(CogWheelBlock.AXIS)));
|
||||||
|
else
|
||||||
|
return ActionResultType.FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.tryPlace(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,7 +15,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
|
|
||||||
public class ShaftBlock extends RotatedPillarKineticBlock {
|
public class ShaftBlock extends RotatedPillarKineticBlock {
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class ShaftBlock extends RotatedPillarKineticBlock {
|
|||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.get(AXIS);
|
return face.getAxis() == state.get(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,13 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.state.BooleanProperty;
|
import net.minecraft.state.BooleanProperty;
|
||||||
import net.minecraft.state.EnumProperty;
|
import net.minecraft.state.EnumProperty;
|
||||||
import net.minecraft.state.IProperty;
|
import net.minecraft.state.IProperty;
|
||||||
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.Direction.AxisDirection;
|
import net.minecraft.util.Direction.AxisDirection;
|
||||||
@ -19,7 +21,7 @@ import net.minecraft.util.IStringSerializable;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
|
|
||||||
public class EncasedBeltBlock extends RotatedPillarKineticBlock {
|
public class EncasedBeltBlock extends RotatedPillarKineticBlock {
|
||||||
|
|
||||||
@ -106,7 +108,7 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.get(AXIS);
|
return face.getAxis() == state.get(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,6 +146,19 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
|
|||||||
return new EncasedShaftTileEntity();
|
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
|
@Override
|
||||||
protected boolean hasStaticPart() {
|
protected boolean hasStaticPart() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -11,7 +11,7 @@ import net.minecraft.util.Direction;
|
|||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
|
|
||||||
public class EncasedShaftBlock extends RotatedPillarKineticBlock {
|
public class EncasedShaftBlock extends RotatedPillarKineticBlock {
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class EncasedShaftBlock extends RotatedPillarKineticBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.get(AXIS);
|
return face.getAxis() == state.get(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class GearshiftBlock extends EncasedShaftBlock {
|
public class GearshiftBlock extends EncasedShaftBlock {
|
||||||
@ -55,7 +56,7 @@ public class GearshiftBlock extends EncasedShaftBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return super.hasShaftTowards(world, pos, state, face);
|
return super.hasShaftTowards(world, pos, state, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import net.minecraft.util.NonNullList;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.storage.loot.LootContext.Builder;
|
import net.minecraft.world.storage.loot.LootContext.Builder;
|
||||||
|
|
||||||
public class GearboxBlock extends RotatedPillarKineticBlock {
|
public class GearboxBlock extends RotatedPillarKineticBlock {
|
||||||
@ -69,7 +69,7 @@ public class GearboxBlock extends RotatedPillarKineticBlock {
|
|||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(World world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||||
return face.getAxis() != state.get(AXIS);
|
return face.getAxis() != state.get(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user