From bafe5feca364b207815f7a0015da73a28907682d Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 29 Apr 2021 09:52:08 -0400 Subject: [PATCH] attempt to get lines to work --- .../common/GlowstoneWireBlock.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java b/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java index 5acf48d..59cb2e2 100644 --- a/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java +++ b/src/main/java/me/parsell/glowstonewire/common/GlowstoneWireBlock.java @@ -1,10 +1,14 @@ package me.parsell.glowstonewire.common; +import java.util.Iterator; import java.util.Map; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; +import org.jetbrains.annotations.Nullable; + +import me.parsell.glowstonewire.core.glowBlocks; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -15,6 +19,7 @@ import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.Properties; +import net.minecraft.state.property.Property; import net.minecraft.util.ActionResult; import net.minecraft.util.BlockMirror; import net.minecraft.util.BlockRotation; @@ -25,6 +30,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldView; public class GlowstoneWireBlock extends Block{ @@ -73,8 +79,27 @@ public class GlowstoneWireBlock extends Block{ return DOT_SHAPE; } + // This decides what I should look like when I'm placed public BlockState getPlacecmentState(ItemPlacementContext ctx){ - return this.getDefaultState(); + World world = ctx.getWorld(); + BlockPos placePos = ctx.getBlockPos(); + BlockState state = this.getDefaultState(); + if(world.getBlockState(placePos.offset(Direction.NORTH)).isOf(this)) + state = state.with(WIRE_CONNECTION_NORTH, WireConnection.SIDE); + if(world.getBlockState(placePos.offset(Direction.SOUTH)).isOf(this)) + state = state.with(WIRE_CONNECTION_SOUTH, WireConnection.SIDE); + if(world.getBlockState(placePos.offset(Direction.EAST)).isOf(this)) + state = state.with(WIRE_CONNECTION_EAST, WireConnection.SIDE); + if(world.getBlockState(placePos.offset(Direction.WEST)).isOf(this)) + state = state.with(WIRE_CONNECTION_WEST, WireConnection.SIDE); + System.out.println(state.toString()); + return state; + } + + // This decides what I should look like whens something around me happens + public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) { + System.out.println("state for neighbor update w: " + state.toString() + ", " + direction.toString() + ", " + pos.toString() + ", " + posFrom.toString()); + return state; } public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { @@ -120,7 +145,7 @@ public class GlowstoneWireBlock extends Block{ 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"); } @@ -128,7 +153,7 @@ public class GlowstoneWireBlock extends Block{ // Check if I'm this, // then update all my neighbors // then tell my neighbors to update all their neighbors (why?) - public void updateNeighbors(World world, BlockPos pos){ + /* public void updateNeighbors(World world, BlockPos pos){ if (world.getBlockState(pos).isOf(this)) { world.updateNeighborsAlways(pos, this); //Direction[] d = Direction.values(); @@ -140,19 +165,19 @@ public class GlowstoneWireBlock extends Block{ //} } - } + } */ 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); + return; } else { dropStacks(state, world, pos); world.removeBlock(pos, false); } } - } + } static { WIRE_CONNECTION_NORTH = Properties.NORTH_WIRE_CONNECTION;