+ Link Block

This commit is contained in:
Glitchlabs
2026-08-04 13:36:12 +02:00
parent 47c6da6bd1
commit 35faf12e0e
11 changed files with 192 additions and 1 deletions
+1 -1
View File
@@ -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
@@ -17,6 +17,9 @@ public class ModBlocks {
public static final DeferredRegister.Blocks BLOCKS =
DeferredRegister.createBlocks(Ornamentum.MODID);
public static final DeferredBlock<Block> LINK_BLOCK = registerBlock("link_block",
() -> new LinkBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.BLACK_CONCRETE).isRedstoneConductor((bs, br, bp) -> true).noOcclusion()));
public static final DeferredBlock<Block> DUCK = registerBlock("duck",
() -> new duckBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.YELLOW_CARPET).noOcclusion()));
@@ -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<LinkBlock> 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<? extends DirectionalBlock> codec() {
return CODEC;
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> 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<BlockPos> visited = new HashSet<>();
Deque<BlockPos> 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);
}
}
}
}
}
@@ -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");
@@ -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
}
}
}
@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "ornamentum:block/link_block_off"
}
}
@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "ornamentum:block/link_block_on"
}
}
@@ -0,0 +1,3 @@
{
"parent": "ornamentum:block/link_block"
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

@@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}