Skip to content

Commit

Permalink
Fix VoxelShapes
Browse files Browse the repository at this point in the history
  • Loading branch information
a0a7 committed Aug 23, 2023
1 parent a3680d7 commit 08613e0
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 919 deletions.
31 changes: 6 additions & 25 deletions src/main/java/net/aaw/bellsandwhistles/block/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
package net.aaw.bellsandwhistles.block;

import static com.simibubi.create.Create.REGISTRATE;

import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllTags;
import com.simibubi.create.content.contraptions.actors.seat.SeatBlock;
import com.simibubi.create.content.contraptions.actors.seat.SeatInteractionBehaviour;
import com.simibubi.create.content.contraptions.actors.seat.SeatMovementBehaviour;
import com.simibubi.create.content.decoration.MetalLadderBlock;
import com.simibubi.create.foundation.block.DyedBlockList;
import com.simibubi.create.foundation.data.BuilderTransformers;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.simibubi.create.foundation.data.SharedProperties;
import com.simibubi.create.foundation.utility.CreateRegistry;
import com.tterrag.registrate.Registrate;
import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.util.DataIngredient;
import com.tterrag.registrate.util.entry.BlockEntry;
import net.aaw.bellsandwhistles.BellsAndWhistles;
import net.aaw.bellsandwhistles.block.custom.MetalBogieStepsBlock;
import net.aaw.bellsandwhistles.block.custom.MetalGrabRailsBlock;
import net.aaw.bellsandwhistles.block.custom.MetalPilotBlock;
import net.aaw.bellsandwhistles.block.custom.StoolSeatBlock;
import net.aaw.bellsandwhistles.block.custom.PilotBlock;
import net.aaw.bellsandwhistles.item.ModItems;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LadderBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.common.util.NonNullFunction;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
Expand All @@ -46,7 +27,7 @@ public static <T extends Block, P> NonNullFunction<BlockBuilder<T, P>, BlockBuil
public static final DeferredRegister<Block> BLOCKS =
DeferredRegister.create(ForgeRegistries.BLOCKS, BellsAndWhistles.MOD_ID);
public static final RegistryObject<Block> METAL_PILOT = registerBlock("metal_pilot",
() -> new MetalPilotBlock(BlockBehaviour.Properties.copy(Blocks.IRON_TRAPDOOR)));
() -> new PilotBlock(BlockBehaviour.Properties.copy(Blocks.IRON_BLOCK).noOcclusion()));
public static final RegistryObject<Block> ANDESITE_GRAB_RAILS = registerBlock("andesite_grab_rails",
() -> new MetalGrabRailsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));
public static final RegistryObject<Block> BRASS_GRAB_RAILS = registerBlock("brass_grab_rails",
Expand All @@ -55,11 +36,11 @@ public static <T extends Block, P> NonNullFunction<BlockBuilder<T, P>, BlockBuil
() -> new MetalGrabRailsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));

public static final RegistryObject<Block> ANDESITE_BOGIE_STEPS = registerBlock("andesite_bogie_steps",
() -> new MetalGrabRailsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));
() -> new MetalBogieStepsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));
public static final RegistryObject<Block> BRASS_BOGIE_STEPS = registerBlock("brass_bogie_steps",
() -> new MetalGrabRailsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));
() -> new MetalBogieStepsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));
public static final RegistryObject<Block> COPPER_BOGIE_STEPS = registerBlock("copper_bogie_steps",
() -> new MetalGrabRailsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));
() -> new MetalBogieStepsBlock(BlockBehaviour.Properties.copy(Blocks.LADDER).sound(SoundType.METAL).noOcclusion()));


private static <T extends Block>RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package net.aaw.bellsandwhistles.block.custom;

import com.simibubi.create.content.decoration.MetalLadderBlock;
import com.simibubi.create.content.equipment.wrench.IWrenchable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.stream.Stream;

public class MetalBogieStepsBlock extends MetalLadderBlock implements IWrenchable {
public MetalBogieStepsBlock(Properties pProperties) {
super(pProperties);
}
public float getShadeBrightness(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
return 1.0F;
}

public boolean propagatesSkylightDown(BlockState pState, BlockGetter pReader, BlockPos pPos) {
return true;
}

@Override
public boolean isLadder(BlockState state, LevelReader level, BlockPos pos, LivingEntity entity) {
return super.isLadder(state, level, pos, entity);
}

private static final VoxelShape SHAPE = Stream.of(
Block.box(2, -9, 14, 14, 16, 16),
Block.box(1, -3, 12, 15, -2, 16),
Block.box(3, -9, 12, 13, -8, 16)
).reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR)).get();
public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{shape, Shapes.empty()};

int times = (to.ordinal() - from.get2DDataValue() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.create(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = Shapes.empty();
}

return buffer[0];
}
@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
switch ((Direction)pState.getValue(FACING)) {
case NORTH:
return SHAPE;
case SOUTH:
return rotateShape(Direction.NORTH, Direction.WEST, SHAPE);
case WEST:
return rotateShape(Direction.NORTH, Direction.EAST, SHAPE);
case EAST:
default:
return rotateShape(Direction.NORTH, Direction.SOUTH, SHAPE);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package net.aaw.bellsandwhistles.block.custom;

import com.simibubi.create.content.decoration.MetalLadderBlock;
import com.simibubi.create.content.equipment.wrench.IWrenchable;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.GlassBlock;
import net.minecraft.world.level.block.state.BlockState;

public class MetalGrabRailsBlock extends MetalLadderBlock {
public class MetalGrabRailsBlock extends MetalLadderBlock implements IWrenchable {
public MetalGrabRailsBlock(Properties pProperties) {
super(pProperties);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.aaw.bellsandwhistles.block.custom;

import com.simibubi.create.content.equipment.wrench.IWrenchable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.stream.Stream;

public class PilotBlock extends Block implements IWrenchable{
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public PilotBlock(Properties properties) {
super(properties);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite());
}

@Override
public BlockState rotate(BlockState pState, Rotation pRotation) {
return pState.setValue(FACING, pRotation.rotate(pState.getValue(FACING)));
}

@Override
public BlockState mirror(BlockState pState, Mirror pMirror) {
return pState.rotate(pMirror.getRotation(pState.getValue(FACING)));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(FACING);
}
public float getShadeBrightness(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
return 1.0F;
}

public boolean propagatesSkylightDown(BlockState pState, BlockGetter pReader, BlockPos pPos) {
return true;
}
private static final VoxelShape SHAPE = Stream.of(
Block.box(0.25, -11, 3, 16.25, 5, 19),
Block.box(16.25, -11, 10, 22.25, 5, 19),
Block.box(-5.75, -11, 10, 0.25, 5, 19),
Block.box(0.25, 5, 7, 16.25, 14, 19),
Block.box(-5.75, -12, 9, 22.25, -11, 20),
Block.box(-6.75, -12, 11, 23.25, -11, 20),
Block.box(1.25, -12, 2, 15.25, -11, 9),
Block.box(-0.75, -12, 4, 17.25, -11, 9)
).reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR)).get();

public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape shape) {
VoxelShape[] buffer = new VoxelShape[]{shape, Shapes.empty()};

int times = (to.ordinal() - from.get2DDataValue() + 4) % 4;
for (int i = 0; i < times; i++) {
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.create(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = Shapes.empty();
}

return buffer[0];
}
@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
switch ((Direction)pState.getValue(FACING)) {
case NORTH:
return SHAPE;
case SOUTH:
return rotateShape(Direction.NORTH, Direction.WEST, SHAPE);
case WEST:
return rotateShape(Direction.NORTH, Direction.EAST, SHAPE);
case EAST:
default:
return rotateShape(Direction.NORTH, Direction.SOUTH, SHAPE);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"credit": "Made with Blockbench",
"render_type" : "cutout",
"render_type": "cutout",
"textures": {
"0": "bellsandwhistles:block/metal_rails/ladder_andesite_hoop",
"1": "bellsandwhistles:block/metal_rails/hand_rails_andesite",
Expand Down Expand Up @@ -137,9 +137,38 @@
"south": {"uv": [14, 4, 16, 6], "rotation": 180, "texture": "#0", "cullface": "up"},
"down": {"uv": [14, 0, 16, 4], "rotation": 180, "texture": "#0", "cullface": "up"}
}
},
{
"name": "ladder",
"from": [2, -9, 14],
"to": [14, 16, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]},
"color": 0,
"faces": {
"north": {"uv": [2, 0, 14, 16], "texture": "#missing"}
}
},
{
"name": "ladder",
"from": [1, -3, 12],
"to": [15, -2, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]},
"color": 0,
"faces": {
"north": {"uv": [2, 0, 14, 16], "texture": "#missing"}
}
},
{
"name": "ladder",
"from": [3, -9, 12],
"to": [13, -8, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]},
"color": 0,
"faces": {
"north": {"uv": [2, 0, 14, 16], "texture": "#missing"}
}
}
],
"display": {},
"groups": [
{
"name": "ladder",
Expand Down Expand Up @@ -171,6 +200,12 @@
"children": [8, 9, 10, 11]
}
]
},
{
"name": "VoxelShapes",
"origin": [8, 8, 8],
"color": 0,
"children": [12, 13, 14]
}
]
}
Loading

0 comments on commit 08613e0

Please sign in to comment.