diff --git a/src/main/java/me/parsell/glowstonewire/common/GlowWireConnection.java b/src/main/java/me/parsell/glowstonewire/common/GlowWireConnection.java new file mode 100644 index 0000000..acfe5b0 --- /dev/null +++ b/src/main/java/me/parsell/glowstonewire/common/GlowWireConnection.java @@ -0,0 +1,32 @@ +package me.parsell.glowstonewire.common; + +import net.minecraft.util.StringIdentifiable; + +public enum GlowWireConnection implements StringIdentifiable{ + UP("up"), + SIDE("side"), + BROKE("broke"), + NONE("none"); + + private final String name; + + private GlowWireConnection(String name){ + this.name = name; + } + + public String toString() { + return this.asString(); + } + + public String asString() { + return this.name; + } + + public boolean isBroken() { + return this != BROKE; + } + + public boolean isConnected() { + return this != NONE; + } +} diff --git a/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java b/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java index b032644..bef90be 100644 --- a/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java +++ b/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java @@ -8,7 +8,6 @@ import com.google.common.collect.Maps; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; -import net.minecraft.block.enums.WireConnection; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; @@ -29,13 +28,13 @@ import net.minecraft.world.WorldView; public class GlowstoneWireBlock extends Block{ // These are the states of the wires coming off our block - public static final net.minecraft.state.property.EnumProperty WIRE_CONNECTION_NORTH; - public static final net.minecraft.state.property.EnumProperty WIRE_CONNECTION_EAST; - public static final net.minecraft.state.property.EnumProperty WIRE_CONNECTION_SOUTH; - public static final net.minecraft.state.property.EnumProperty WIRE_CONNECTION_WEST; + public static final EnumProperty WIRE_CONNECTION_NORTH; + public static final EnumProperty WIRE_CONNECTION_SOUTH; + public static final EnumProperty WIRE_CONNECTION_EAST; + public static final EnumProperty WIRE_CONNECTION_WEST; // Locally defined DIRECTION <-> WIRE_CONNECTION_DIRECTION - public static final Map> DIRECTION_TO_WIRE_CONNECTION_PROPERTY; + public static final Map> DIRECTION_TO_WIRE_CONNECTION_PROPERTY; // Determines the hitbox for our block public static final VoxelShape DOT_SHAPE; @@ -46,8 +45,8 @@ public class GlowstoneWireBlock extends Block{ public GlowstoneWireBlock(Settings settings) { super(settings); // Set these properties to be none as start, so we start with a dot - this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, WireConnection.NONE)).with(WIRE_CONNECTION_EAST, WireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, WireConnection.NONE)).with(WIRE_CONNECTION_WEST, WireConnection.NONE))); - this.FULL_STATE = (BlockState)((BlockState)((BlockState)((BlockState)this.getDefaultState().with(WIRE_CONNECTION_NORTH, WireConnection.SIDE)).with(WIRE_CONNECTION_EAST, WireConnection.SIDE)).with(WIRE_CONNECTION_SOUTH, WireConnection.SIDE)).with(WIRE_CONNECTION_WEST, WireConnection.SIDE); + this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, GlowWireConnection.NONE)).with(WIRE_CONNECTION_EAST, GlowWireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, GlowWireConnection.NONE)).with(WIRE_CONNECTION_WEST, GlowWireConnection.NONE))); + this.FULL_STATE = (BlockState)((BlockState)((BlockState)((BlockState)this.getDefaultState().with(WIRE_CONNECTION_NORTH, GlowWireConnection.SIDE)).with(WIRE_CONNECTION_EAST, GlowWireConnection.SIDE)).with(WIRE_CONNECTION_SOUTH, GlowWireConnection.SIDE)).with(WIRE_CONNECTION_WEST, GlowWireConnection.SIDE); } // Make sure out block has the properties for us to manage @@ -57,24 +56,24 @@ public class GlowstoneWireBlock extends Block{ } private static boolean isFullyConnected(BlockState state) { - return ((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() && - ((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() && - ((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() && - ((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); + return ((GlowWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() && + ((GlowWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() && + ((GlowWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() && + ((GlowWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); } private static boolean isNotConnected(BlockState state) { - return !((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() && - !((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() && - !((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() && - !((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); + return !((GlowWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() && + !((GlowWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() && + !((GlowWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() && + !((GlowWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); } private static boolean hasConnection(BlockState state) { - return ((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() || - ((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() || - ((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() || - ((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); + return ((GlowWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() || + ((GlowWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() || + ((GlowWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() || + ((GlowWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); } private BlockState determineState(WorldAccess world, BlockState state, BlockPos pos){ @@ -89,12 +88,12 @@ public class GlowstoneWireBlock extends Block{ return state; } - private WireConnection determineConnection(WorldAccess world, BlockPos pos, Direction direction){ + private GlowWireConnection determineConnection(WorldAccess world, BlockPos pos, Direction direction){ if(world.getBlockState(pos.offset(direction).up()).isOf(this)) - return WireConnection.UP; + return GlowWireConnection.UP; if(world.getBlockState(pos.offset(direction)).isOf(this) || world.getBlockState(pos.offset(direction).down()).isOf(this)) - return WireConnection.SIDE; - return WireConnection.NONE; + return GlowWireConnection.SIDE; + return GlowWireConnection.NONE; } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { @@ -180,10 +179,10 @@ public class GlowstoneWireBlock extends Block{ } static { - WIRE_CONNECTION_NORTH = Properties.NORTH_WIRE_CONNECTION; - WIRE_CONNECTION_EAST = Properties.EAST_WIRE_CONNECTION; - WIRE_CONNECTION_SOUTH = Properties.SOUTH_WIRE_CONNECTION; - WIRE_CONNECTION_WEST = Properties.WEST_WIRE_CONNECTION; + WIRE_CONNECTION_NORTH = EnumProperty.of("north", GlowWireConnection.class); + WIRE_CONNECTION_EAST = EnumProperty.of("east", GlowWireConnection.class); + WIRE_CONNECTION_SOUTH = EnumProperty.of("south", GlowWireConnection.class); + WIRE_CONNECTION_WEST = EnumProperty.of("west", GlowWireConnection.class); DIRECTION_TO_WIRE_CONNECTION_PROPERTY = Maps.newEnumMap((Map)ImmutableMap.of(Direction.NORTH, WIRE_CONNECTION_NORTH, Direction.EAST, WIRE_CONNECTION_EAST, Direction.SOUTH, WIRE_CONNECTION_SOUTH, Direction.WEST, WIRE_CONNECTION_WEST));