diff --git a/gradle.properties b/gradle.properties index f89bdd1..5be21c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ mod_name=Ornamentum ## The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=1.2.3 +mod_version=1.3.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/ovh/glitchlabs/ornamentum/blocks/ModBlocks.java b/src/main/java/ovh/glitchlabs/ornamentum/blocks/ModBlocks.java index 25b8321..7b7d3fd 100644 --- a/src/main/java/ovh/glitchlabs/ornamentum/blocks/ModBlocks.java +++ b/src/main/java/ovh/glitchlabs/ornamentum/blocks/ModBlocks.java @@ -17,6 +17,9 @@ public class ModBlocks { public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(Ornamentum.MODID); + public static final DeferredBlock LINK_BLOCK = registerBlock("link_block", + () -> new LinkBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.BLACK_CONCRETE).isRedstoneConductor((bs, br, bp) -> true).noOcclusion())); + public static final DeferredBlock DUCK = registerBlock("duck", () -> new duckBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.YELLOW_CARPET).noOcclusion())); diff --git a/src/main/java/ovh/glitchlabs/ornamentum/blocks/custom/LinkBlock.java b/src/main/java/ovh/glitchlabs/ornamentum/blocks/custom/LinkBlock.java new file mode 100644 index 0000000..ab27504 --- /dev/null +++ b/src/main/java/ovh/glitchlabs/ornamentum/blocks/custom/LinkBlock.java @@ -0,0 +1,114 @@ +package ovh.glitchlabs.ornamentum.blocks.custom; + +import com.mojang.serialization.MapCodec; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.DirectionalBlock; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.BlockHitResult; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.HashSet; +import java.util.Set; + +public class LinkBlock extends DirectionalBlock { + + public static final MapCodec CODEC = simpleCodec(LinkBlock::new); + + public static final BooleanProperty ON = BooleanProperty.create("on"); + + private static final int MAX_NETWORK_SIZE = 4096; + + public LinkBlock(Properties properties) { + super(properties); + this.registerDefaultState(this.stateDefinition.any() + .setValue(ON, false) + .setValue(FACING, Direction.NORTH)); + } + + @Override + protected MapCodec codec() { + return CODEC; + } + + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING); + builder.add(ON); + } + + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + BlockState state = super.getStateForPlacement(context); + if (state == null) + return null; + return state.setValue(FACING, context.getClickedFace()).setValue(ON, false); + } + + public BlockState rotate(BlockState state, Rotation rot) { + return state.setValue(FACING, rot.rotate(state.getValue(FACING))); + } + + public BlockState mirror(BlockState state, Mirror mirrorIn) { + return state.rotate(mirrorIn.getRotation(state.getValue(FACING))); + } + + + @Override + protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { + if (player.isShiftKeyDown()) { + if (!level.isClientSide) { + toggleNetwork(level, pos, !state.getValue(ON)); + } + return InteractionResult.SUCCESS; + } + return InteractionResult.PASS; + } + + + private void toggleNetwork(Level level, BlockPos origin, boolean newState) { + Set visited = new HashSet<>(); + Deque queue = new ArrayDeque<>(); + + visited.add(origin.immutable()); + queue.add(origin); + + while (!queue.isEmpty() && visited.size() <= MAX_NETWORK_SIZE) { + BlockPos pos = queue.poll(); + BlockState state = level.getBlockState(pos); + + if (!(state.getBlock() instanceof LinkBlock)) { + continue; + } + + if (state.getValue(ON) != newState) { + level.setBlock(pos, state.setValue(ON, newState), Block.UPDATE_ALL); + } + + for (Direction direction : Direction.values()) { + BlockPos neighborPos = pos.relative(direction); + if (visited.contains(neighborPos)) { + continue; + } + + BlockState neighborState = level.getBlockState(neighborPos); + if (neighborState.getBlock() instanceof LinkBlock) { + visited.add(neighborPos.immutable()); + queue.add(neighborPos); + } + } + } + } +} diff --git a/src/main/java/ovh/glitchlabs/ornamentum/datagen/ModLanguageProvider.java b/src/main/java/ovh/glitchlabs/ornamentum/datagen/ModLanguageProvider.java index e29eaf6..a4d84f0 100644 --- a/src/main/java/ovh/glitchlabs/ornamentum/datagen/ModLanguageProvider.java +++ b/src/main/java/ovh/glitchlabs/ornamentum/datagen/ModLanguageProvider.java @@ -341,6 +341,8 @@ public class ModLanguageProvider extends LanguageProvider { add(ModBlocks.CRACKED_OBSIDIAN_BRICKS.get(), "Cracked Obsidian Bricks"); add(ModBlocks.CRACKED_OBSIDIAN_TILES.get(), "Cracked Obsidian Tiles"); + add(ModBlocks.LINK_BLOCK.get(), "Link Block"); + add(ModBlocks.IRON_SHELF.get(), "Iron Shelf"); add(ModBlocks.DUCK.get(), "Duck"); add(ModBlocks.BABY_TURTLE.get(), "Baby Turtle"); diff --git a/src/main/resources/assets/ornamentum/blockstates/link_block.json b/src/main/resources/assets/ornamentum/blockstates/link_block.json new file mode 100644 index 0000000..e729c18 --- /dev/null +++ b/src/main/resources/assets/ornamentum/blockstates/link_block.json @@ -0,0 +1,52 @@ + +{ + "variants": { + "facing=north,on=false": { + "model": "ornamentum:block/link_block" + }, + "facing=east,on=false": { + "model": "ornamentum:block/link_block", + "y": 90 + }, + "facing=south,on=false": { + "model": "ornamentum:block/link_block", + "y": 180 + }, + "facing=west,on=false": { + "model": "ornamentum:block/link_block", + "y": 270 + }, + "facing=up,on=false": { + "model": "ornamentum:block/link_block", + "x": 270 + }, + "facing=down,on=false": { + "model": "ornamentum:block/link_block", + "x": 90 + }, + + "facing=north,on=true": { + "model": "ornamentum:block/link_block_on" + }, + "facing=east,on=true": { + "model": "ornamentum:block/link_block_on", + "y": 90 + }, + "facing=south,on=true": { + "model": "ornamentum:block/link_block_on", + "y": 180 + }, + "facing=west,on=true": { + "model": "ornamentum:block/link_block_on", + "y": 270 + }, + "facing=up,on=true": { + "model": "ornamentum:block/link_block_on", + "x": 270 + }, + "facing=down,on=true": { + "model": "ornamentum:block/link_block_on", + "x": 90 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/ornamentum/models/block/link_block.json b/src/main/resources/assets/ornamentum/models/block/link_block.json new file mode 100644 index 0000000..70ad2ac --- /dev/null +++ b/src/main/resources/assets/ornamentum/models/block/link_block.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "ornamentum:block/link_block_off" + } +} diff --git a/src/main/resources/assets/ornamentum/models/block/link_block_on.json b/src/main/resources/assets/ornamentum/models/block/link_block_on.json new file mode 100644 index 0000000..f95304c --- /dev/null +++ b/src/main/resources/assets/ornamentum/models/block/link_block_on.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "ornamentum:block/link_block_on" + } +} diff --git a/src/main/resources/assets/ornamentum/models/item/link_block.json b/src/main/resources/assets/ornamentum/models/item/link_block.json new file mode 100644 index 0000000..a82ba82 --- /dev/null +++ b/src/main/resources/assets/ornamentum/models/item/link_block.json @@ -0,0 +1,3 @@ +{ + "parent": "ornamentum:block/link_block" +} diff --git a/src/main/resources/assets/ornamentum/textures/block/link_block_off.png b/src/main/resources/assets/ornamentum/textures/block/link_block_off.png new file mode 100644 index 0000000..aea04b0 Binary files /dev/null and b/src/main/resources/assets/ornamentum/textures/block/link_block_off.png differ diff --git a/src/main/resources/assets/ornamentum/textures/block/link_block_on.png b/src/main/resources/assets/ornamentum/textures/block/link_block_on.png new file mode 100644 index 0000000..f8536af Binary files /dev/null and b/src/main/resources/assets/ornamentum/textures/block/link_block_on.png differ diff --git a/src/main/resources/assets/ornamentum/textures/block/link_block_on.png.mcmeta b/src/main/resources/assets/ornamentum/textures/block/link_block_on.png.mcmeta new file mode 100644 index 0000000..0645f48 --- /dev/null +++ b/src/main/resources/assets/ornamentum/textures/block/link_block_on.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation": { + "frametime": 2 + } +}