diff --git a/main/java/ella/techia/Techia.java b/main/java/ella/techia/Techia.java index f2ad302..e4b02d7 100644 --- a/main/java/ella/techia/Techia.java +++ b/main/java/ella/techia/Techia.java @@ -17,10 +17,11 @@ public class Techia implements ModInitializer { public void onInitialize(){ TechiaRegistry.register(); - FabricItemGroupBuilder.create(new Identifier(MOD_ID, "items")).icon(() -> TechiaBlocks.LETIUM.asItem().getDefaultStack()).appendItems(stacks -> Registry.ITEM.forEach(item -> { + FabricItemGroupBuilder.create(new Identifier(MOD_ID, "items")).icon(() -> TechiaRegistry.LETIUM.getDefaultStack()).appendItems(stacks -> Registry.ITEM.forEach(item -> { if(Registry.ITEM.getId(item).getNamespace().equals(MOD_ID)){ item.appendStacks(item.getGroup(), (DefaultedList) stacks); } })).build(); + ItemGroup LETI = FabricItemGroupBuilder.create(new Identifier(MOD_ID, "leti")).icon(() -> TechiaRegistry.CONNECTOR.asItem().getDefaultStack()).build(); } } diff --git a/main/java/ella/techia/block/Connector.java b/main/java/ella/techia/block/Connector.java index bc0b7ff..5ccd9f9 100644 --- a/main/java/ella/techia/block/Connector.java +++ b/main/java/ella/techia/block/Connector.java @@ -1,5 +1,6 @@ package ella.techia.block; +import ella.techia.leti.LetiNetwork; import net.minecraft.block.*; import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.player.PlayerEntity; @@ -13,126 +14,31 @@ import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.DirectionProperty; import net.minecraft.state.property.Properties; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldView; -public class Connector extends Block implements LetiBlock, Waterloggable { +public class Connector extends LetiConnectable /*implements LetiBlock, Waterloggable*/ { static final VoxelShape BASE_SHAPE = createCuboidShape( 5d, 5d, 5d, 11d, 11d, 11d); static final VoxelShape NORTH_SHAPE = createCuboidShape( 6d, 6d, 0d, 10d, 10d, 5d); static final VoxelShape SOUTH_SHAPE = createCuboidShape( 6d, 6d, 11d, 10d, 10d, 16d); static final VoxelShape EAST_SHAPE = createCuboidShape(11d, 6d, 6d, 16d, 10d, 10d); static final VoxelShape WEST_SHAPE = createCuboidShape( 0d, 6d, 6d, 5d, 10d, 10d); - static final VoxelShape UP_SHAPE = createCuboidShape( 6d, 6d, 6d, 10d, 16d, 10d); + static final VoxelShape UP_SHAPE = createCuboidShape( 6d, 11d, 6d, 10d, 16d, 10d); static final VoxelShape DOWN_SHAPE = createCuboidShape( 6d, 0d, 6d, 10d, 5d, 10d); - public EllasModLampBlock(net.minecraft.block.AbstractBlock.Settings settings){ + public Connector(net.minecraft.block.AbstractBlock.Settings settings){ super(settings); - this.setDefaultState( - this.stateManager.getDefaultState() - .with(Properties.WATERLOGGED, false) - .with(Properties.UP , false) - .with(Properties.DOWN , false) - .with(Properties.NORTH, false) - .with(Properties.SOUTH, false) - .with(Properties.EAST , false) - .with(Properties.WEST , false) - .with(Properties.POWERED, false)); } - - //getShapeForState - @Override - protected void appendProperties(StateManager.Builder builder){ - super.appendProperties(builder); - builder.add(Properties.DOWN, Properties.EAST, Properties.FACING, Properties.NORTH, Properties.SOUTH, Properties.WATERLOGGED); - } - /*@Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){ - return ActionResult.SUCCESS; - }*/ - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context){ - VoxelShape shape = BASE_SHAPE; - if(((Boolean)state.get(Properties.NORTH)).booleanValue()){ - shape = VoxelShapes.union(shape, NORTH_SHAPE); - } - if(((Boolean)state.get(Properties.SOUTH)).booleanValue()){ - shape = VoxelShapes.union(shape, SOUTH_SHAPE); - } - if(((Boolean)state.get(Properties.EAST)).booleanValue()){ - shape = VoxelShapes.union(shape, EAST_SHAPE); - } - if(((Boolean)state.get(Properties.WEST)).booleanValue()){ - shape = VoxelShapes.union(shape, WEST_SHAPE); - } - if(((Boolean)state.get(Properties.UP)).booleanValue()){ - shape = VoxelShapes.union(shape, UP_SHAPE); - } - if(((Boolean)state.get(Properties.DOWN)).booleanValue()){ - shape = VoxelShapes.union(shape, DOWN_SHAPE); - } - return state; - } - - @Override - public BlockState getPlacementState(ItemPlacementContext context){ - var world = context.getWorld(); - var pos = context.getBlockPos(); - return super.getPlacementState(context) - .with(Properties.WATERLOGGED, world.getFluidState(pos).getFluid() == Fluids.WATER) - .with(Properties.NORTH, connects(world.getBlockState(pos.north()).getBlock())) - .with(Properties.SOUTH, connects(world.getBlockState(pos.south()).getBlock())) - .with(Properties.EAST , connects(world.getBlockState(pos.east() ).getBlock())) - .with(Properties.WEST , connects(world.getBlockState(pos.west() ).getBlock())) - .with(Properties.UP , connects(world.getBlockState(pos.up() ).getBlock())) - .with(Properties.DOWN , connects(world.getBlockState(pos.down() ).getBlock())) - .with(Properties.POWERED, /*powered(world.getBlockState(pos).getBlock())*/false); - } - public boolean connects(Block block){ - if(block instanceof LetiBlock) - return (LetiBlock)block.connects; - return false; - } - /*@Override - public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type){ - return false; - }*/ - @Override - public FluidState getFluidState(BlockState state){ - if(state.get(Properties.WATERLOGGED)) return Fluids.WATER.getStill(false); - else return super.getFluidState(state); - } - @Override - public BlockState getStateForNeighborUpdate( - BlockState state, - Direction side, - BlockState neighborState, - WorldAccess world, - BlockPos pos, - BlockPos neighborPos - ){ - // can't be assed to only update one side - return state - .with(Properties.NORTH, connects(world.getBlockState(pos.north()).getBlock())) - .with(Properties.SOUTH, connects(world.getBlockState(pos.south()).getBlock())) - .with(Properties.EAST , connects(world.getBlockState(pos.east() ).getBlock())) - .with(Properties.WEST , connects(world.getBlockState(pos.west() ).getBlock())) - .with(Properties.UP , connects(world.getBlockState(pos.up() ).getBlock())) - .with(Properties.DOWN , connects(world.getBlockState(pos.down() ).getBlock())) - /*.with(Properties.POWERED, /*powered(world.getBlockState(pos).getBlock())* /false)*/; - } - /*@Override - rotate(BlockState state, BlockRotation rotation): BlockState { - - return state; - }*/ -} \ No newline at end of file + @Override + public void onPlace(){ + LetiNetwork.new(pos); + } +} diff --git a/main/java/ella/techia/block/Delayer.java b/main/java/ella/techia/block/Delayer.java new file mode 100644 index 0000000..aba6051 --- /dev/null +++ b/main/java/ella/techia/block/Delayer.java @@ -0,0 +1,39 @@ +package ella.techia.block; + +import net.minecraft.block.*; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; + +public class Delayer extends FacingLeti /*implements LetiBlock, Waterloggable*/ { + public static final IntProperty DELAY = IntProperty.of("delay", 1, 6); + + public Delayer(net.minecraft.block.AbstractBlock.Settings settings){ + super(settings); + this.setDefaultState( + this.stateManager.getDefaultState() + .with(DELAY, 1)); + } + + @Override + protected void appendProperties(StateManager.Builder builder){ + super.appendProperties(builder); + builder.add(DELAY); + } + + @Override + public BlockState getPlacementState(ItemPlacementContext context){ + return super.getPlacementState(context).with(DELAY, 1); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){ + world.setBlockState(pos, state.with(DELAY, (state.get(DELAY) - 1) % 6 + 2)); + return ActionResult.SUCCESS; + } +} diff --git a/main/java/ella/techia/block/FacingLeti.java b/main/java/ella/techia/block/FacingLeti.java new file mode 100644 index 0000000..7c3b364 --- /dev/null +++ b/main/java/ella/techia/block/FacingLeti.java @@ -0,0 +1,96 @@ +package ella.techia.block; + +import net.minecraft.block.*; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.state.property.DirectionProperty; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; + +public class FacingLeti extends Block implements LetiBlock, Waterloggable { + + static final VoxelShape BASE_SHAPE = createCuboidShape( 5d, 5d, 5d, 11d, 11d, 11d); + static final VoxelShape Z_SHAPE = VoxelShapes.union( + BASE_SHAPE, createCuboidShape( 6d, 6d, 0d, 10d, 10d, 16d)); + static final VoxelShape X_SHAPE = VoxelShapes.union( + BASE_SHAPE, createCuboidShape( 0d, 6d, 6d, 16d, 10d, 10d)); + static final VoxelShape Y_SHAPE = VoxelShapes.union( + BASE_SHAPE, createCuboidShape( 6d, 0d, 6d, 10d, 16d, 10d)); + + public FacingLeti(net.minecraft.block.AbstractBlock.Settings settings){ + super(settings); + this.setDefaultState( + this.stateManager.getDefaultState() + .with(Properties.WATERLOGGED, false) + .with(Properties.FACING, Direction.UP) + .with(Properties.POWERED, false)); + } + + @Override + protected void appendProperties(StateManager.Builder builder){ + super.appendProperties(builder); + builder.add(Properties.FACING, Properties.POWERED, Properties.WATERLOGGED); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context){ + switch((net.minecraft.util.math.Direction)state.get(Properties.FACING)){ + case NORTH: + case SOUTH: + return Z_SHAPE; + case EAST: + case WEST: + return X_SHAPE; + case UP: + case DOWN: + default: + return Y_SHAPE; + } + } + + @Override + public BlockState getPlacementState(ItemPlacementContext context){ + var world = context.getWorld(); + var pos = context.getBlockPos(); + return super.getPlacementState(context) + .with(Properties.WATERLOGGED, world.getFluidState(pos).getFluid() == Fluids.WATER) + .with(Properties.FACING, context.getPlayerLookDirection()); + .with(Properties.POWERED, false); + } + + @Override + public FluidState getFluidState(BlockState state){ + if(state.get(Properties.WATERLOGGED)) return Fluids.WATER.getStill(false); + else return super.getFluidState(state); + } + + @Override + public boolean connects(BlockState state, Direction direction){ + return direction.equals(state.get(Properties.FACING)) || direction.equals(state.get(Properties.FACING).opposite()); + } + @Override + public boolean output(/*ServerWorld world, BlockPos pos,*/ BlockState state, Direction direction){ + return state.get(Properties.POWERED) && direction.equals(state.get(Properties.FACING)); + } + + // TODO update output of network in front after placing + /*@Override + BlockState rotate(BlockState state, BlockRotation rotation){ + return state; + }*/ +} diff --git a/main/java/ella/techia/block/Inverter.java b/main/java/ella/techia/block/Inverter.java new file mode 100644 index 0000000..1d178a5 --- /dev/null +++ b/main/java/ella/techia/block/Inverter.java @@ -0,0 +1,25 @@ +package ella.techia.block; + +import net.minecraft.block.*; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.IntProperty; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + +public class Inverter extends FacingLeti /*implements LetiBlock, Waterloggable*/ { + + public Inverter(net.minecraft.block.AbstractBlock.Settings settings){ + super(settings); + } + + @Override + public BlockState getPlacementState(ItemPlacementContext context){ + return super.getPlacementState(context).with(DELAY, 1); + } + + @Override + public void tick(){ + // TODO update to what the output behind wasn't + } +} diff --git a/main/java/ella/techia/block/LetiBlock.java b/main/java/ella/techia/block/LetiBlock.java index a8db1f8..164dcdf 100644 --- a/main/java/ella/techia/block/LetiBlock.java +++ b/main/java/ella/techia/block/LetiBlock.java @@ -1,6 +1,11 @@ package ella.techia.block; +import net.minecraft.block.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.ServerWorld; + public interface LetiBlock { - public boolean connects; // TODO maybe a method? - public boolean output(); -} \ No newline at end of file + public boolean connects(BlockState state, Direction direction); + public boolean output(/*ServerWorld world, BlockPos pos,*/ BlockState state, Direction direction); +} diff --git a/main/java/ella/techia/block/LetiConnectable.java b/main/java/ella/techia/block/LetiConnectable.java new file mode 100644 index 0000000..4998c9f --- /dev/null +++ b/main/java/ella/techia/block/LetiConnectable.java @@ -0,0 +1,134 @@ +package ella.techia.block; + +import ella.techia.leti.LetiNetwork; +import net.minecraft.block.*; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.state.property.DirectionProperty; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; + +public class LetiConnectable extends Block implements LetiBlock, Waterloggable { + + static final VoxelShape BASE_SHAPE; + static final VoxelShape NORTH_SHAPE; + static final VoxelShape SOUTH_SHAPE; + static final VoxelShape EAST_SHAPE; + static final VoxelShape WEST_SHAPE; + static final VoxelShape UP_SHAPE; + static final VoxelShape DOWN_SHAPE; + + public LetiToggle(net.minecraft.block.AbstractBlock.Settings settings){ + super(settings); + this.setDefaultState( + this.stateManager.getDefaultState() + .with(Properties.WATERLOGGED, false) + .with(Properties.UP , false) + .with(Properties.DOWN , false) + .with(Properties.NORTH, false) + .with(Properties.SOUTH, false) + .with(Properties.EAST , false) + .with(Properties.WEST , false) + .with(Properties.POWERED, false)); + } + + @Override + protected void appendProperties(StateManager.Builder builder){ + super.appendProperties(builder); + builder.add(Properties.DOWN, Properties.EAST, Properties.NORTH, Properties.POWERED, + Properties.SOUTH, Properties.UP, Properties.WEST, Properties.WATERLOGGED); + } + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context){ + VoxelShape shape = BASE_SHAPE; + if(((Boolean)state.get(Properties.NORTH)).booleanValue()){ + shape = VoxelShapes.union(shape, NORTH_SHAPE); + } + if(((Boolean)state.get(Properties.SOUTH)).booleanValue()){ + shape = VoxelShapes.union(shape, SOUTH_SHAPE); + } + if(((Boolean)state.get(Properties.EAST)).booleanValue()){ + shape = VoxelShapes.union(shape, EAST_SHAPE); + } + if(((Boolean)state.get(Properties.WEST)).booleanValue()){ + shape = VoxelShapes.union(shape, WEST_SHAPE); + } + if(((Boolean)state.get(Properties.UP)).booleanValue()){ + shape = VoxelShapes.union(shape, UP_SHAPE); + } + if(((Boolean)state.get(Properties.DOWN)).booleanValue()){ + shape = VoxelShapes.union(shape, DOWN_SHAPE); + } + return shape; + } + + @Override + public BlockState getPlacementState(ItemPlacementContext context){ + var world = context.getWorld(); + var pos = context.getBlockPos(); + return super.getPlacementState(context) + .with(Properties.WATERLOGGED, world.getFluidState(pos).getFluid() == Fluids.WATER) + .with(Properties.NORTH, LetiNetwork.connects(world.getBlockState(pos.north()), Direction.SOUTH)) + .with(Properties.SOUTH, LetiNetwork.connects(world.getBlockState(pos.south()), Direction.NORTH)) + .with(Properties.EAST , LetiNetwork.connects(world.getBlockState(pos.east() ), Direction.WEST )) + .with(Properties.WEST , LetiNetwork.connects(world.getBlockState(pos.west() ), Direction.EAST )) + .with(Properties.UP , LetiNetwork.connects(world.getBlockState(pos.up() ), Direction.DOWN )) + .with(Properties.DOWN , LetiNetwork.connects(world.getBlockState(pos.down() ), Direction.UP )) + .with(Properties.POWERED, /*powered(world.getBlockState(pos))*/false); + } + + @Override + public FluidState getFluidState(BlockState state){ + if(state.get(Properties.WATERLOGGED)) return Fluids.WATER.getStill(false); + else return super.getFluidState(state); + } + + @Override + public BlockState getStateForNeighborUpdate( + BlockState state, + Direction side, + BlockState neighborState, + WorldAccess world, + BlockPos pos, + BlockPos neighborPos + ){ + // can't be assed to only update one side + // FIXME probably extremely laggy on medium to big networks + return state + .with(Properties.NORTH, LetiNetwork.connects(world.getBlockState(pos.north()), Direction.SOUTH)) + .with(Properties.SOUTH, LetiNetwork.connects(world.getBlockState(pos.south()), Direction.NORTH)) + .with(Properties.EAST , LetiNetwork.connects(world.getBlockState(pos.east() ), Direction.WEST )) + .with(Properties.WEST , LetiNetwork.connects(world.getBlockState(pos.west() ), Direction.EAST )) + .with(Properties.UP , LetiNetwork.connects(world.getBlockState(pos.up() ), Direction.DOWN )) + .with(Properties.DOWN , LetiNetwork.connects(world.getBlockState(pos.down() ), Direction.UP )) + /*.with(Properties.POWERED, /*powered(world.getBlockState(pos))* /false)*/; + } + + @Override + public boolean connects(BlockState state, Direction direction){ + return true; + } + @Override + public boolean output(/*ServerWorld world, BlockPos pos,*/ BlockState state, Direction direction){ + return state.get(Properties.POWERED); + } + /*@Override + BlockState rotate(BlockState state, BlockRotation rotation){ + return state; + }*/ +} diff --git a/main/java/ella/techia/block/LetiToggle.java b/main/java/ella/techia/block/LetiToggle.java new file mode 100644 index 0000000..6cbe5cd --- /dev/null +++ b/main/java/ella/techia/block/LetiToggle.java @@ -0,0 +1,49 @@ +package ella.techia.block; + +import ella.techia.leti.LetiNetwork; +import net.minecraft.block.*; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.state.property.DirectionProperty; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.WorldView; + +public class LetiToggle extends LetiConnectable /*implements LetiBlock, Waterloggable*/ { + + static final VoxelShape BASE_SHAPE = createCuboidShape( 3d, 3d, 3d, 13d, 13d, 13d); + static final VoxelShape NORTH_SHAPE = createCuboidShape( 6d, 6d, 0d, 10d, 10d, 3d); + static final VoxelShape SOUTH_SHAPE = createCuboidShape( 6d, 6d, 13d, 10d, 10d, 16d); + static final VoxelShape EAST_SHAPE = createCuboidShape(13d, 6d, 6d, 16d, 10d, 10d); + static final VoxelShape WEST_SHAPE = createCuboidShape( 0d, 6d, 6d, 3d, 10d, 10d); + static final VoxelShape UP_SHAPE = createCuboidShape( 6d, 13d, 6d, 10d, 16d, 10d); + static final VoxelShape DOWN_SHAPE = createCuboidShape( 6d, 0d, 6d, 10d, 3d, 10d); + + public LetiToggle(net.minecraft.block.AbstractBlock.Settings settings){ + super(settings); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){ + boolean pow = state.get(Properties.POWERED); + world.setBlockState(pos, state.with(Properties.POWERED, !pow)); + // Will this play the sound for only the player? probably not what we want + world.playSound(player, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3f, pow? 0.5f: 0.6f); + //world.playSound(pos.x, pos.y, pos.z, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3f, pow? 0.5f: 0.6f, true); + return ActionResult.SUCCESS; + } +} diff --git a/main/java/ella/techia/block/Piston.java b/main/java/ella/techia/block/Piston.java new file mode 100644 index 0000000..0e51ba1 --- /dev/null +++ b/main/java/ella/techia/block/Piston.java @@ -0,0 +1,10 @@ +package ella.techia.block; + +import net.minecraft.block.*; + +public class Piston extends Block { + + public Piston(net.minecraft.block.AbstractBlock.Settings settings){ + super(settings); + } +} diff --git a/main/java/ella/techia/block/entity/.BoxBlockEntity.java.kate-swp b/main/java/ella/techia/block/entity/.BoxBlockEntity.java.kate-swp index 181fd7a..6cb5c3d 100644 Binary files a/main/java/ella/techia/block/entity/.BoxBlockEntity.java.kate-swp and b/main/java/ella/techia/block/entity/.BoxBlockEntity.java.kate-swp differ diff --git a/main/java/ella/techia/leti/LetiNetwork.java b/main/java/ella/techia/leti/LetiNetwork.java new file mode 100644 index 0000000..0d42a4d --- /dev/null +++ b/main/java/ella/techia/leti/LetiNetwork.java @@ -0,0 +1,108 @@ +package ella.techia.leti; + +import java.util.*; +import java.util.Map.Entry; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ServerWorld; + +public class LetiNetwork { + private static final Map, LetiNetwork> networks = Maps.newHashMap(); + private ServerWorld world; + + ArrayList nodes; + public LetiNetwork(ServerWorld world, BlockPos pos){ + this.world = world; + nodes = new ArrayList<>(); + nodes.add(pos); + } + + public void set(boolean powered){ + for(BlockPos pos : nodes){ + world.setBlockState(pos, world.getBlockState(pos).with(Properties.POWERED, powered)); + } + } + + // assumes that there is no node here already + public static void new(ServerWorld world, BlockPos pos){ + if(!(world.getBlockState(pos).getBlock() instanceof Connector)) + throw new IllegalArgumentException("Only connectors may be in a network"); + // check adjacent positions for networks, if >1 join them together, if >0 join the network, if 0 create a network + LetiNetwork current = null; + for(BlockPos np : neighbors(pos)){ + Entry key = new Entry<>(world, pos); + if(networks.containsKey(key)){ + if(current == null){ + current = networks.get(key); + current.add(pos); + } + else current.mergeWith(networks.get(key)); + } + } + if(current == null){ + networks.set(new Entry(world, pos), new LetiNetwork(world, pos)); + } + } + + private void add(BlockPos pos){ + nodes.add(pos); + networks.set(new Entry(world, pos), this); + } + private void remove(BlockPos pos){ + nodes.remove(pos); + networks.remove(new Entry(world, pos)); + } + + private void mergeWith(LetiNetwork network){ + for(BlockPos pos : nodes){ + Entry entry = new Entry<>(world, pos) + //networks.remove(entry); (not needed because we replace) + network.add(pos); + networks.set(entry, network); + } + } + + public static boolean connects(BlockState state, Direction direction){ + Block block = state.getBlock(); + if(block instanceof LetiBlock) + return ((LetiBlock)block).connects(state, direction); + return false; + } + + public static boolean output(BlockState state, Direction direction){ + Block block = state.getBlock(); + if(block instanceof LetiBlock) + return ((LetiBlock)block).output(state, direction); + return false; + } + + // borrowed from yttr + public static Entry neighbors(BlockPos pos){ + BlockPos fpos = pos.toImmutable(); + return new AbstractEntry(){ + @Override + public Iterator iterator() { + return new AbstractIterator(){ + private final BlockPos.Mutable mut = new BlockPos.Mutable(); + private final Iterator dirIter = DIRECTIONS.iterator(); + + @Override + protected BlockPos computeNext(){ + if (!dirIter.hasNext()) return endOfData(); + return mut.set(fpos).move(dirIter.next()); + } + }; + } + + @Override + public boolean contains(Object o){ + return o instanceof BlockPos && fpos.getManhattanDistance((BlockPos)o) == 1; + } + + @Override + public int size(){ + return DIRECTIONS.size(); + } + }; + } +} diff --git a/main/java/ella/techia/registry/.TechiaRegistry.java.kate-swp b/main/java/ella/techia/registry/.TechiaRegistry.java.kate-swp deleted file mode 100644 index d31c653..0000000 Binary files a/main/java/ella/techia/registry/.TechiaRegistry.java.kate-swp and /dev/null differ diff --git a/main/java/ella/techia/registry/TechiaRegistry.java b/main/java/ella/techia/registry/TechiaRegistry.java index 0409657..e7f4c87 100644 --- a/main/java/ella/techia/registry/TechiaRegistry.java +++ b/main/java/ella/techia/registry/TechiaRegistry.java @@ -2,6 +2,7 @@ package ella.techia.registry; import ella.techia.Techia; import ella.techia.block.*; +import ella.techia.block.entity.*; //import net.fabricmc.api.FabricLoader; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; @@ -29,73 +30,27 @@ public class TechiaRegistry { new Block(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)), ItemGroup.BUILDING_BLOCKS); public static final Item ASMITE_INGOT = addI("asmite_ingot", new Item(new Item.Settings().group(ItemGroup.MISC))); public static final Item LETIUM = addI("letium", new Item(new Item.Settings().group(ItemGroup.MISC))); - public static final Block CONNECTOR = add("connector", new Connector(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), ItemGroup.MISC); - public static final Block INTERSECTOR = add("intersector", new Intersector(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), ItemGroup.MISC); - public static final Block INVERTER = add("inverter", new Inverter(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), ItemGroup.MISC); - public static final Block DELAYER = add("delayer", new Delayer(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), ItemGroup.MISC); + public static final Block CONNECTOR = add("connector", new Connector(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI); + //public static final Block INTERSECTOR = add("intersector", new Intersector(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI); NOPE + public static final Block INVERTER = add("inverter", new Inverter(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI); + public static final Block DELAYER = add("delayer", new Delayer(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.1f).resistance(0f)), Techia.LETI); + public static final Block ASMITE_TOGGLE = add("asmite_toggle", new LetiToggle(FabricBlockSettings.copyOf(Blocks.IRON_BARS).hardness(0.2f).resistance(0.2f)), Techia.LETI); + public static final Block BOX_BLOCK = add("smelter", new Smelter(FabricBlockSettings.copyOf(Blocks.FURNACE)), ItemGroup.MISC); + public static BlockEntityType SMELTER_ENTITY; public static final Item BLOCK_SHAPE = addI("block_shape", new Item(new Item.Settings().group(ItemGroup.MISC))); public static final Item INGOT_SHAPE = addI("ingot_shape", new Item(new Item.Settings().group(ItemGroup.MISC))); - /*public static final Block NONBINARY_BLOCK = add("nonbinary_block", - new EFacingBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).mapColor(MapColor.WHITE)), ItemGroup.BUILDING_BLOCKS); + public static final Block BOX_BLOCK = add("box", new BoxBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).hardness(0.5f)), ItemGroup.MISC); + public static BlockEntityType BOX_BLOCK_ENTITY; + public static final Block BOX_BLOCK = add("workbench", new WorkbenchBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).hardness(0.5f)), ItemGroup.MISC); + public static BlockEntityType WORKBENCH_BLOCK_ENTITY; - /*public static final Block SPARKWOOD_LADDER = add("sparkwood_ladder", - new SparkwoodLadderBlock(FabricBlockSettings.copyOf(Blocks.LADDER)), ItemGroup.DECORATIONS);*/ - /*public static final Block SPARKWOOD_FENCE = add("sparkwood_fence", - new FenceBlock(FabricBlockSettings.copyOf(Blocks.OAK_FENCE)), ItemGroup.DECORATIONS);*/ - /*private static final Identifier SPARKWOOD_SIGN_TEXTURE = new Identifier(Techia.MOD_ID, "entity/signs/sparkwood"); - public static final TerraformSignBlock SPARKWOOD_SIGN = add("sparkwood_sign", - new TerraformSignBlock(SPARKWOOD_SIGN_TEXTURE, FabricBlockSettings.copyOf(Blocks.OAK_SIGN))); - public static final Block SPARKWOOD_WALL_SIGN = add("sparkwood_wall_sign", - new TerraformWallSignBlock(SPARKWOOD_SIGN_TEXTURE, FabricBlockSettings.copyOf(Blocks.OAK_WALL_SIGN))); - public static final Item SPARKWOOD_SIGN_ITEM = add("sparkwood_sign", - new SignItem(new Item.Settings().maxCount(16).group(ItemGroup.DECORATIONS), SPARKWOOD_SIGN, SPARKWOOD_WALL_SIGN));* / + public static final Block PISTON = add("piston", + new Block(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)), Techia.LETI); - public static final Block STONE_BRICK_TILES = add("stone_brick_tiles", - new Block(FabricBlockSettings.copyOf(Blocks.STONE_BRICKS)), ItemGroup.BUILDING_BLOCKS); - - public static final Block LARGE_OAK_TILE_SLAB = add("large_oak_tile_slab", - new SlabBlock(FabricBlockSettings.copyOf(Blocks.OAK_SLAB)), ItemGroup.DECORATIONS); - - public static final Block LARGE_OAK_TILE_STAIRS = add("large_oak_tile_stairs", - new TerraformStairsBlock(LARGE_OAK_TILES, FabricBlockSettings.copyOf(Blocks.OAK_STAIRS)), ItemGroup.DECORATIONS); - - public static final Block LAMP_BLOCK = add("lamp_block", - new Block(FabricBlockSettings.copyOf(Blocks.REDSTONE_LAMP).nonOpaque().luminance(15)), ItemGroup.DECORATIONS); - public static final Block CAGED_GLASS = add("clear_glass", - new GlassBlock(FabricBlockSettings.copyOf(Blocks.GLASS)), ItemGroup.BUILDING_BLOCKS); - public static final Block LAMP = add("lamp", - new TechiaLampBlock(FabricBlockSettings.copyOf(Blocks.END_ROD) - .luminance(state -> state.get(Properties.LIT)? 15: 0) - .sounds(BlockSoundGroup.LANTERN) - ), ItemGroup.DECORATIONS); - public static final Block SMALL_LAMP = add("small_lamp", - new TechiaSmallLampBlock(FabricBlockSettings.copyOf(Blocks.END_ROD) - .luminance(state -> state.get(Properties.LIT)? 15: 0) - .sounds(BlockSoundGroup.LANTERN) - ), ItemGroup.DECORATIONS); - public static final Block CAGE = add("cage", - new CageBlock(FabricBlockSettings.copyOf(Blocks.IRON_BARS) - //.luminance(state -> state.get(Properties.LIT)? 15: 0) - //.suffocates(TechiaBlocks::never) - //.blockVision(TechiaBlocks::never) - ), ItemGroup.DECORATIONS); - - /*public static final Block _PLATFORM = add("_platform", - new PlatformBlock(FabricBlockSettings.copyOf(Blocks.COBBLESTONE)), ItemGroup.BUILDING_BLOCKS); - - public static final Block OAK_WALL_FENCE = add("oak_wall_fence", - new WallFenceBlock(FabricBlockSettings.copyOf(Blocks.OAK_FENCE)), ItemGroup.DECORATIONS); - - public static final Block WINDOWED_IRON_DOOR = add("windowed_iron_door", - new TerraformDoorBlock(FabricBlockSettings.copyOf(Blocks.IRON_DOOR)), ItemGroup.REDSTONE); - public static final Block YELLOW_BRICK_STAIRS = add("yellow_brick_stairs", - new TerraformStairsBlock(YELLOW_BRICKS, FabricBlockSettings.copyOf(Blocks.BRICKS).mapColor(MapColor.PALE_YELLOW)), ItemGroup.BUILDING_BLOCKS); - public static final Block YELLOW_BRICK_SLAB = add("yellow_brick_slab", - new SlabBlock(FabricBlockSettings.copyOf(Blocks.BRICKS).mapColor(MapColor.PALE_YELLOW)), ItemGroup.BUILDING_BLOCKS); - public static final Block YELLOW_BRICK_WALL = add("yellow_brick_wall", - new EWallBlock(FabricBlockSettings.copyOf(Blocks.BRICKS).mapColor(MapColor.PALE_YELLOW)), ItemGroup.BUILDING_BLOCKS);*/ + public static final RecipeType WORKBENCH_RECIPE = RecipeType.register(new Identifier(Techia.MOD_ID, "smelting")); + public static final RecipeType WORKBENCH_RECIPE = RecipeType.register(new Identifier(Techia.MOD_ID, "workbench")); private static B add(String name, B block, ItemGroup tab){ return add(name, block, new BlockItem(block, new Item.Settings().group(tab))); @@ -131,30 +86,48 @@ public class TechiaRegistry { }*/ /*for(String id : ITEMS.keySet()){ - Registry.register(Registry.ITEM, new Identifier(Techia.MOD_ID, id), ITEMS.get(id)); + register(id), ITEMS.get(id)); } for(String id : BLOCKS.keySet()){ - Registry.register(Registry.BLOCK, new Identifier(Techia.MOD_ID, id), BLOCKS.get(id)); + register(id), BLOCKS.get(id)); }*/ - //FuelRegistry fuelRegistry = FuelRegistry.INSTANCE; - //fuelRegistry.add(, ticks); - //FlammableBlockRegistry flammableRegistry = FlammableBlockRegistry.getDefaultInstance(); // could be bad? maybe don't use hash maps? //BLOCKS = null; //ITEMS = null; - Registry.register(Registry.BLOCK, new Identifier(Techia.MOD_ID, "asmite_block"), ASMITE_BLOCK); - Registry.register(Registry.ITEM, new Identifier(Techia.MOD_ID, "asmite_ingot"), ASMITE_INGOT); - Registry.register(Registry.ITEM, new Identifier(Techia.MOD_ID, "letium"), LETIUM); - Registry.register(Registry.BLOCK, new Identifier(Techia.MOD_ID, "connector"), CONNECTOR); - Registry.register(Registry.BLOCK, new Identifier(Techia.MOD_ID, "intersector"), INTERSECTOR); - Registry.register(Registry.BLOCK, new Identifier(Techia.MOD_ID, "inverter"), INVERTER); - Registry.register(Registry.BLOCK, new Identifier(Techia.MOD_ID, "delayer"), DELAYER); - Registry.register(Registry.ITEM, new Identifier(Techia.MOD_ID, "block_shape"), BLOCK_SHAPE); - Registry.register(Registry.ITEM, new Identifier(Techia.MOD_ID, "ingot_shape"), INGOT_SHAPE); + register("asmite_block", ASMITE_BLOCK); + register("asmite_ingot", ASMITE_INGOT); + register("letium", LETIUM); + register("connector", CONNECTOR); + //register("intersector", INTERSECTOR); NOPE + register("inverter", INVERTER); + register("delayer", DELAYER); + //register("leti_source", LETI_SOURCE); + //register("asmite_button", ASMITE_BUTTON); + register("asmite_toggle", ASMITE_TOGGLE); + //register("asmite_wall_button", ASMITE_WALL_BUTTON); + //register("asmite_wall_toggle", ASMITE_WALL_TOGGLE); + register("smelter", SMELTER); + SMELTER_ENTITY = register("smelter", FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX_BLOCK).build(null)); + register("block_shape", BLOCK_SHAPE); + register("ingot_shape", INGOT_SHAPE); + register("box", BOX_BLOCK); + BOX_BLOCK_ENTITY = register("box", FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX_BLOCK).build(null)); + register("workbench", WORKBENCH_BLOCK); + WORKBENCH_BLOCK_ENTITY = register("workbench", FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, WORKBENCH_BLOCK).build(null)); + register("piston", PISTON); + } + public void register(String id, Block block){ + register(id), block); + } + public void register(String id, Item item){ + register(id), item); + } + public BlockEntityType register(String id, BlockEntityType entity){ + Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(Techia.MOD_ID, id), entity); } /*public static boolean never(BlockState state, BlockView world, BlockPos pos) { diff --git a/main/resources/assets/techia/lang/en_us.json b/main/resources/assets/techia/lang/en_us.json new file mode 100644 index 0000000..199ad7a --- /dev/null +++ b/main/resources/assets/techia/lang/en_us.json @@ -0,0 +1,21 @@ +{ +"block.techia.asmite_block":"Asmite Block", +"block.techia.asmite_button":"Asmite Button", +"block.techia.asmite_toggle":"Asmite Toggle", +"block.techia.asmite_wall_button":"Asmite Wall Button", +"block.techia.asmite_wall_toggle":"Asmite Wall Toggle", +"block.techia.box":"Box", +"block.techia.connector":"Connector", +"block.techia.delayer":"Delayer", +"block.techia.leti_source":"Leti Source", +"block.techia.intersector":"Intersector", +"block.techia.inverter":"Inverter", +"block.techia.piston":"Piston", +"block.techia.smelter":"Smelter", +"block.techia.workbench":"Workbench", +"item.techia.asmite_ingot":"Asmite Ingot", +"item.techia.block_shape":"Block Shape", +"item.techia.letium":"Letium", +"item.techia.ingot_shape":"Ingot Shape", +"itemGroup.ellas_mod.items":"Techia", +"itemGroup.ellas_mod.leti":"Leti"} diff --git a/main/resources/assets/techia/lang/sv_se.json b/main/resources/assets/techia/lang/sv_se.json new file mode 100644 index 0000000..6d857ca --- /dev/null +++ b/main/resources/assets/techia/lang/sv_se.json @@ -0,0 +1,21 @@ +{ +"block.techia.asmite_block":"Asmitblock", +"block.techia.asmite_button":"Asmitknapp", +"block.techia.asmite_toggle":"Asmitflipp", +"block.techia.asmite_wall_button":"Asmitv\u00e4ggknapp", +"block.techia.asmite_wall_toggle":"Asmitv\u00e4ggflipp", +"block.techia.box":"L\u00e5da", +"block.techia.connector":"Kopplare", +"block.techia.delayer":"F\u00f6rdr\u00f6jare", +"block.techia.leti_source":"Letik\u00e4lla", +"block.techia.intersector":"Korsare", +"block.techia.inverter":"Inverterare", +"block.techia.piston":"Kolv", +"block.techia.smelter":"Sm\u00e4ltare", +"block.techia.workbench":"Arbetsb\u00e4nk", +"item.techia.asmite_ingot":"Asmittacka", +"item.techia.block_shape":"Blockform", +"item.techia.letium":"Letium", +"item.techia.ingot_shape":"Tackform", +"itemGroup.ellas_mod.items":"Techia", +"itemGroup.ellas_mod.leti":"Leti"}