Skip to content

Commit

Permalink
Portal block + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MegDuck committed Oct 1, 2023
1 parent 52a5377 commit b147b75
Show file tree
Hide file tree
Showing 36 changed files with 1,143 additions and 3 deletions.
107 changes: 107 additions & 0 deletions src/main/java/com/kpabr/backrooms/block/CrackedCopperPipeBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.kpabr.backrooms.block;

import net.minecraft.block.*;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager.Builder;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.function.BooleanBiFunction;
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.WorldAccess;

import java.util.Map;

public class CrackedCopperPipeBlock extends Block implements Waterloggable{
public static final BooleanProperty NORTH = ConnectingBlock.NORTH;
public static final BooleanProperty EAST = ConnectingBlock.EAST;
public static final BooleanProperty SOUTH = ConnectingBlock.SOUTH;
public static final BooleanProperty WEST = ConnectingBlock.WEST;
public static final BooleanProperty UP = ConnectingBlock.UP;
public static final BooleanProperty DOWN = ConnectingBlock.DOWN;
private static final Map<Direction, BooleanProperty> FACING_PROPERTIES = ConnectingBlock.FACING_PROPERTIES;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

public CrackedCopperPipeBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(NORTH, true).with(EAST, true).with(SOUTH, true).with(WEST, true).with(UP, true).with(DOWN, true).with(WATERLOGGED, false));
}

public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockView blockView = ctx.getWorld();
BlockPos blockPos = ctx.getBlockPos();
return this.getDefaultState()
.with(DOWN, blockView.getBlockState(blockPos.down()).isOf(this))
.with(UP, blockView.getBlockState(blockPos.up()).isOf(this))
.with(NORTH, blockView.getBlockState(blockPos.north()).isOf(this))
.with(EAST, blockView.getBlockState(blockPos.east()).isOf(this))
.with(SOUTH, blockView.getBlockState(blockPos.south()).isOf(this))
.with(WEST, blockView.getBlockState(blockPos.west()).isOf(this))
.with(WATERLOGGED, blockView.getFluidState(blockPos).getFluid() == Fluids.WATER);
}

@SuppressWarnings("deprecation")
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) {
world. createAndScheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
if(neighborState.isOf(this)) return state.with(FACING_PROPERTIES.get(direction), true);
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}

@SuppressWarnings("deprecation")
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.NORTH)), state.get(NORTH))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.SOUTH)), state.get(SOUTH))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.EAST)), state.get(EAST))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.WEST)), state.get(WEST))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.DOWN)), state.get(DOWN))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.UP)), state.get(UP));
}

@SuppressWarnings("deprecation")
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state
.with(FACING_PROPERTIES.get(mirror.apply(Direction.NORTH)), state.get(NORTH))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.SOUTH)), state.get(SOUTH))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.EAST)), state.get(EAST))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.WEST)), state.get(WEST))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.DOWN)), state.get(DOWN))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.UP)), state.get(UP));
}

protected void appendProperties(Builder<Block, BlockState> builder) {
builder.add(UP, DOWN, NORTH, EAST, SOUTH, WEST, WATERLOGGED);
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
VoxelShape finalShape = VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f);
if (state.get(NORTH))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.0f, 0.75f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(SOUTH))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 1.0f), BooleanBiFunction.OR);
if (state.get(EAST))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 1.0f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(WEST))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.0f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(DOWN))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.0f, 0.25f, 0.75f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(UP))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 0.75f, 1.0f, 0.75f), BooleanBiFunction.OR);

return finalShape;
}
}
107 changes: 107 additions & 0 deletions src/main/java/com/kpabr/backrooms/block/CrackedPipeBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.kpabr.backrooms.block;

import net.minecraft.block.*;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager.Builder;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.function.BooleanBiFunction;
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.WorldAccess;

import java.util.Map;

public class CrackedPipeBlock extends Block implements Waterloggable{
public static final BooleanProperty NORTH = ConnectingBlock.NORTH;
public static final BooleanProperty EAST = ConnectingBlock.EAST;
public static final BooleanProperty SOUTH = ConnectingBlock.SOUTH;
public static final BooleanProperty WEST = ConnectingBlock.WEST;
public static final BooleanProperty UP = ConnectingBlock.UP;
public static final BooleanProperty DOWN = ConnectingBlock.DOWN;
private static final Map<Direction, BooleanProperty> FACING_PROPERTIES = ConnectingBlock.FACING_PROPERTIES;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

public CrackedPipeBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(NORTH, true).with(EAST, true).with(SOUTH, true).with(WEST, true).with(UP, true).with(DOWN, true).with(WATERLOGGED, false));
}

public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockView blockView = ctx.getWorld();
BlockPos blockPos = ctx.getBlockPos();
return this.getDefaultState()
.with(DOWN, blockView.getBlockState(blockPos.down()).isOf(this))
.with(UP, blockView.getBlockState(blockPos.up()).isOf(this))
.with(NORTH, blockView.getBlockState(blockPos.north()).isOf(this))
.with(EAST, blockView.getBlockState(blockPos.east()).isOf(this))
.with(SOUTH, blockView.getBlockState(blockPos.south()).isOf(this))
.with(WEST, blockView.getBlockState(blockPos.west()).isOf(this))
.with(WATERLOGGED, blockView.getFluidState(blockPos).getFluid() == Fluids.WATER);
}

@SuppressWarnings("deprecation")
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) {
world. createAndScheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
if(neighborState.isOf(this)) return state.with(FACING_PROPERTIES.get(direction), true);
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}

@SuppressWarnings("deprecation")
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.NORTH)), state.get(NORTH))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.SOUTH)), state.get(SOUTH))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.EAST)), state.get(EAST))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.WEST)), state.get(WEST))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.DOWN)), state.get(DOWN))
.with(FACING_PROPERTIES.get(rotation.rotate(Direction.UP)), state.get(UP));
}

@SuppressWarnings("deprecation")
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state
.with(FACING_PROPERTIES.get(mirror.apply(Direction.NORTH)), state.get(NORTH))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.SOUTH)), state.get(SOUTH))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.EAST)), state.get(EAST))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.WEST)), state.get(WEST))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.DOWN)), state.get(DOWN))
.with(FACING_PROPERTIES.get(mirror.apply(Direction.UP)), state.get(UP));
}

protected void appendProperties(Builder<Block, BlockState> builder) {
builder.add(UP, DOWN, NORTH, EAST, SOUTH, WEST, WATERLOGGED);
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
VoxelShape finalShape = VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f);
if (state.get(NORTH))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.0f, 0.75f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(SOUTH))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 1.0f), BooleanBiFunction.OR);
if (state.get(EAST))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 1.0f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(WEST))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.0f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(DOWN))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.0f, 0.25f, 0.75f, 0.75f, 0.75f), BooleanBiFunction.OR);
if (state.get(UP))
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.25f, 0.25f, 0.25f, 0.75f, 1.0f, 0.75f), BooleanBiFunction.OR);

return finalShape;
}
}
1 change: 1 addition & 0 deletions src/main/java/com/kpabr/backrooms/block/PipeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected void appendProperties(Builder<Block, BlockState> builder) {
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}

@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/kpabr/backrooms/block/PlateDoor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kpabr.backrooms.block;

import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.DoorBlock;

public class PlateDoor extends DoorBlock {
public PlateDoor(FabricBlockSettings settings) {
super(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(),
BackroomsBlocks.OFFICE_DOOR,
BackroomsBlocks.HARLEQUIN_MASK,
BackroomsBlocks.COLOMBINA_MASK);
BackroomsBlocks.COLOMBINA_MASK,
BackroomsBlocks.PLATE_DOOR
);
BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(),
BackroomsFluids.STILL_ALMOND_WATER,
BackroomsFluids.FLOWING_ALMOND_WATER);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/kpabr/backrooms/init/BackroomsBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public class BackroomsBlocks {
public static final Block COPPER_PIPE = add("copper_pipe",
new PipeBlock(FabricBlockSettings.copyOf(Blocks.STONE).nonOpaque().mapColor(DyeColor.ORANGE)), ItemGroup.BUILDING_BLOCKS);

public static final Block CRACKED_PIPE = add("cracked_pipe",
new CrackedPipeBlock(FabricBlockSettings.copyOf(Blocks.STONE).nonOpaque()), ItemGroup.BUILDING_BLOCKS);

public static final Block CRACKED_COPPER_PIPE = add("cracked_copper_pipe",
new CrackedCopperPipeBlock(FabricBlockSettings.copyOf(Blocks.STONE).nonOpaque()), ItemGroup.BUILDING_BLOCKS);

public static final BlockEntityType<PyroilLineBlockEntity> PYROIL_LINE_BLOCK_ENTITY = add("pyroil",
FabricBlockEntityTypeBuilder.create(PyroilLineBlockEntity::new, PYROIL).build(null));

Expand All @@ -129,7 +135,7 @@ public class BackroomsBlocks {
public static final Block CEMENT_SANDWICH = add("cement_sandwich", new Block(FabricBlockSettings.copyOf(Blocks.STONE).mapColor(DyeColor.YELLOW)), ItemGroup.BUILDING_BLOCKS);
public static final BlockEntityType<ComputerBlockEntity> TABLE_BLOCK_ENTITY = add("table", FabricBlockEntityTypeBuilder.create(ComputerBlockEntity::new, COMPUTER).build(null));
public static final Block OFFICE_DOOR = add("office_door", new BackroomsDoorBlock(FabricBlockSettings.copyOf(PATTERNED_WALLPAPER).nonOpaque()), ItemGroup.BUILDING_BLOCKS);

public static final Block PLATE_DOOR = add("plate_door", new PlateDoor(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque()), ItemGroup.BUILDING_BLOCKS);
public static final Block FIRESALT_BLOCK = add("firesalt_block", new Block(FabricBlockSettings.copyOf(Blocks.COBBLESTONE).mapColor(DyeColor.ORANGE).collidable(true).sounds(BlockSoundGroup.DRIPSTONE_BLOCK)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIRESALT_CRYSTAL = add("firesalt_crystal", new FiresaltCrystalBlock(FabricBlockSettings.copyOf(Blocks.AMETHYST_CLUSTER).mapColor(DyeColor.ORANGE)), ItemGroup.BUILDING_BLOCKS);
public static final Block BEDROCK_BRICKS = add("bedrock_bricks", new Block(FabricBlockSettings.copy(Blocks.BEDROCK)), ItemGroup.BUILDING_BLOCKS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"multipart": [
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_turn"
},
"when": {
"OR": [
{"up": "true", "north": "true"},
{"up": "true", "east": "true"},
{"up": "true", "south": "true"},
{"up": "true", "west": "true"},
{"north": "true", "east": "true"},
{"east": "true", "south": "true"},
{"south": "true", "west": "true"},
{"west": "true", "north": "true"},
{"down": "true", "north": "true"},
{"down": "true", "east": "true"},
{"down": "true", "south": "true"},
{"down": "true", "west": "true"},
{"north": "true", "south": "false"},
{"east": "true", "west": "false"},
{"south": "true", "north": "false"},
{"west": "true", "east": "false"},
{"up": "true", "down": "false"},
{"down": "true", "up": "false"},
{"north": "false", "south": "false", "east": "false", "west": "false", "up": "false", "down": "false"}
]
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_edge"
},
"when": {
"north": "true"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_edge",
"uvlock": "true",
"y": 90
},
"when": {
"east": "true"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_edge",
"uvlock": "true",
"y": 180
},
"when": {
"south": "true"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_edge",
"uvlock": "true",
"y": 270
},
"when": {
"west": "true"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_edge",
"uvlock": "true",
"x": 270
},
"when": {
"up": "true"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_edge",
"uvlock": "true",
"x": 90
},
"when": {
"down": "true"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_ns"
},
"when": {
"north": "true", "south": "true", "east": "false", "west": "false", "up": "false", "down": "false"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_ew"
},
"when": {
"north": "false", "south": "false", "east": "true", "west": "true", "up": "false", "down": "false"
}
},
{
"apply": {
"model": "backrooms:block/cracked_copper_pipe_ud"
},
"when": {
"north": "false", "south": "false", "east": "false", "west": "false", "up": "true", "down": "true"
}
}
]
}
Loading

0 comments on commit b147b75

Please sign in to comment.