did some stuff iunno

This commit is contained in:
Justin Parsell 2021-04-27 21:34:20 -04:00
parent a38a20d523
commit 46e19769be
1 changed files with 89 additions and 67 deletions

View File

@ -7,6 +7,7 @@ import com.google.common.collect.Maps;
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.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.block.enums.WireConnection; import net.minecraft.block.enums.WireConnection;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -24,6 +25,7 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldView;
public class GlowstoneWireBlock extends Block{ public class GlowstoneWireBlock extends Block{
// These are the states of the wires coming off our block // These are the states of the wires coming off our block
@ -32,21 +34,21 @@ public class GlowstoneWireBlock extends Block{
public static final net.minecraft.state.property.EnumProperty<net.minecraft.block.enums.WireConnection> WIRE_CONNECTION_SOUTH; public static final net.minecraft.state.property.EnumProperty<net.minecraft.block.enums.WireConnection> WIRE_CONNECTION_SOUTH;
public static final net.minecraft.state.property.EnumProperty<net.minecraft.block.enums.WireConnection> WIRE_CONNECTION_WEST; public static final net.minecraft.state.property.EnumProperty<net.minecraft.block.enums.WireConnection> WIRE_CONNECTION_WEST;
// Locally defined DIRECTION <-> WIRE_CONNECTION_DIRECTION // Locally defined DIRECTION <-> WIRE_CONNECTION_DIRECTION
public static final Map<Direction, EnumProperty<WireConnection>> DIRECTION_TO_WIRE_CONNECTION_PROPERTY; public static final Map<Direction, EnumProperty<WireConnection>> DIRECTION_TO_WIRE_CONNECTION_PROPERTY;
// Determines the hitbox for our block // Determines the hitbox for our block
public static final VoxelShape DOT_SHAPE; public static final VoxelShape DOT_SHAPE;
// Full sided state // Full sided state
private BlockState FULL_STATE; private BlockState FULL_STATE;
public GlowstoneWireBlock(Settings settings) { public GlowstoneWireBlock(Settings settings) {
super(settings); super(settings);
// Set these properties to be none as start, so we start with a dot // 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.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.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);
} }
// Make sure out block has the properties for us to manage // Make sure out block has the properties for us to manage
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
@ -55,82 +57,102 @@ public class GlowstoneWireBlock extends Block{
private static boolean isFullyConnected(BlockState state) { private static boolean isFullyConnected(BlockState state) {
return ((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() && return ((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() &&
((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() && ((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() &&
((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() && ((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() &&
((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); ((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected();
} }
private static boolean isNotConnected(BlockState state) { private static boolean isNotConnected(BlockState state) {
return !((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() && return !((WireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() &&
!((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() && !((WireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() &&
!((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() && !((WireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() &&
!((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected(); !((WireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected();
} }
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return DOT_SHAPE; return DOT_SHAPE;
} }
public BlockState getPlacecmentState(ItemPlacementContext ctx){ public BlockState getPlacecmentState(ItemPlacementContext ctx){
return this.getDefaultState(); return this.getDefaultState();
} }
public BlockState rotate(BlockState state, BlockRotation rotation) { public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
switch(rotation) { BlockPos blockPos = pos.down();
case CLOCKWISE_180: BlockState blockState = world.getBlockState(blockPos);
return (BlockState)((BlockState)((BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_SOUTH))).with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_NORTH))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_EAST)); return this.canRunOnTop(world, blockPos, blockState);
case COUNTERCLOCKWISE_90: }
return (BlockState)((BlockState)((BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_EAST))).with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_SOUTH))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_NORTH));
case CLOCKWISE_90: private boolean canRunOnTop(BlockView world, BlockPos pos, BlockState floor) {
return (BlockState)((BlockState)((BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_NORTH))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_EAST))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_SOUTH)); return floor.isSideSolidFullSquare(world, pos, Direction.UP) || floor.isOf(Blocks.HOPPER);
default: }
return state;
} public BlockState rotate(BlockState state, BlockRotation rotation) {
switch(rotation) {
case CLOCKWISE_180:
return (BlockState)((BlockState)((BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_SOUTH))).with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_NORTH))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_EAST));
case COUNTERCLOCKWISE_90:
return (BlockState)((BlockState)((BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_EAST))).with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_SOUTH))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_NORTH));
case CLOCKWISE_90:
return (BlockState)((BlockState)((BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_NORTH))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_EAST))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_SOUTH));
default:
return state;
}
} }
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, BlockMirror mirror) {
switch(mirror) { switch(mirror) {
case LEFT_RIGHT: case LEFT_RIGHT:
return (BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_SOUTH))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_NORTH)); return (BlockState)((BlockState)state.with(WIRE_CONNECTION_NORTH, state.get(WIRE_CONNECTION_SOUTH))).with(WIRE_CONNECTION_SOUTH, state.get(WIRE_CONNECTION_NORTH));
case FRONT_BACK: case FRONT_BACK:
return (BlockState)((BlockState)state.with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_EAST)); return (BlockState)((BlockState)state.with(WIRE_CONNECTION_EAST, state.get(WIRE_CONNECTION_WEST))).with(WIRE_CONNECTION_WEST, state.get(WIRE_CONNECTION_EAST));
default: default:
return super.mirror(state, mirror); return super.mirror(state, mirror);
} }
} }
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
if(isNotConnected(state)) if(isNotConnected(state))
world.setBlockState(pos, FULL_STATE, 3); world.setBlockState(pos, FULL_STATE, 3);
else else
world.setBlockState(pos, this.getDefaultState(), 3); world.setBlockState(pos, this.getDefaultState(), 3);
System.out.println("onUse"); System.out.println("onUse");
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
public void update(World world, BlockPos pos, BlockState state){ public void update(World world, BlockPos pos, BlockState state){
System.out.println("Update"); System.out.println("Update");
}
// isnt system.out BUT will update neighors? }
public void updateNeighbors(World world, BlockPos pos){
System.out.println("Update neighbors");
if (world.getBlockState(pos).isOf(this)) {
world.updateNeighborsAlways(pos, this);
Direction[] var3 = Direction.values();
int var4 = var3.length;
for(int var5 = 0; var5 < var4; ++var5) { // Check if I'm this,
Direction direction = var3[var5]; // then update all my neighbors
world.updateNeighborsAlways(pos.offset(direction), this); // then tell my neighbors to update all their neighbors (why?)
} public void updateNeighbors(World world, BlockPos pos){
if (world.getBlockState(pos).isOf(this)) {
world.updateNeighborsAlways(pos, this);
//Direction[] d = Direction.values();
//int dl = d.length;
} //for(int i = 0; i < dl; ++i) {
} // Direction direction = d[i];
// world.updateNeighborsAlways(pos.offset(direction), this);
//}
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify){ }
System.out.println("Neighbor update"); }
}
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify){
if (!world.isClient) {
if (state.canPlaceAt(world, pos)) {
this.update(world, pos, state);
} else {
dropStacks(state, world, pos);
world.removeBlock(pos, false);
}
}
}
static { static {
WIRE_CONNECTION_NORTH = Properties.NORTH_WIRE_CONNECTION; WIRE_CONNECTION_NORTH = Properties.NORTH_WIRE_CONNECTION;
@ -138,9 +160,9 @@ public class GlowstoneWireBlock extends Block{
WIRE_CONNECTION_SOUTH = Properties.SOUTH_WIRE_CONNECTION; WIRE_CONNECTION_SOUTH = Properties.SOUTH_WIRE_CONNECTION;
WIRE_CONNECTION_WEST = Properties.WEST_WIRE_CONNECTION; WIRE_CONNECTION_WEST = Properties.WEST_WIRE_CONNECTION;
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)); 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));
DOT_SHAPE = Block.createCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D); DOT_SHAPE = Block.createCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D);
} }
} }