mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 12:43:42 +01:00
Placement logic please
This commit is contained in:
parent
0231b32866
commit
72596f63d4
1 changed files with 37 additions and 1 deletions
|
@ -1,14 +1,19 @@
|
|||
package com.simibubi.create.content.contraptions.components.tracks;
|
||||
|
||||
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.block.AbstractRailBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.*;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.state.properties.RailShape;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -23,7 +28,7 @@ import static net.minecraft.state.properties.RailShape.*;
|
|||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ControllerRailBlock extends AbstractRailBlock {
|
||||
public class ControllerRailBlock extends AbstractRailBlock implements IWrenchable {
|
||||
public static final EnumProperty<RailShape> SHAPE = BlockStateProperties.RAIL_SHAPE_STRAIGHT;
|
||||
public static final IntegerProperty POWERED = BlockStateProperties.POWER_0_15;
|
||||
public static final BooleanProperty BACKWARDS = BooleanProperty.create("backwards");
|
||||
|
@ -33,6 +38,13 @@ public class ControllerRailBlock extends AbstractRailBlock {
|
|||
this.setDefaultState(this.stateContainer.getBaseState().with(POWERED, 0).with(BACKWARDS, false).with(SHAPE, NORTH_SOUTH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext p_196258_1_) {
|
||||
Direction direction = p_196258_1_.getPlacementHorizontalFacing();
|
||||
BlockState base = super.getStateForPlacement(p_196258_1_);
|
||||
return (base == null ? getDefaultState() : base).with(BACKWARDS, direction == Direction.SOUTH || direction == Direction.EAST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty<RailShape> getShapeProperty() {
|
||||
return SHAPE;
|
||||
|
@ -163,4 +175,28 @@ public class ControllerRailBlock extends AbstractRailBlock {
|
|||
|
||||
return super.mirror(p_185471_1_, p_185471_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getPos();
|
||||
world.setBlockState(pos, rotate(state, Rotation.CLOCKWISE_90));
|
||||
world.notifyNeighborsOfStateChange(pos.down(), this);
|
||||
if (state.get(SHAPE).isAscending()) {
|
||||
world.notifyNeighborsOfStateChange(pos.up(), this);
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onSneakWrenched(BlockState state, ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getPos();
|
||||
world.setBlockState(pos, rotate(state, Rotation.COUNTERCLOCKWISE_90));
|
||||
world.notifyNeighborsOfStateChange(pos.down(), this);
|
||||
if (state.get(SHAPE).isAscending()) {
|
||||
world.notifyNeighborsOfStateChange(pos.up(), this);
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue