Skip to content

Commit

Permalink
Fixed crates being not waterloggable.
Browse files Browse the repository at this point in the history
  • Loading branch information
MegDuck committed Sep 14, 2024
1 parent 166bb77 commit 95e9317
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
34 changes: 25 additions & 9 deletions src/main/java/com/kpabr/backrooms/block/CrateBlock.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.kpabr.backrooms.block;

import net.minecraft.util.math.random.Random;
import net.minecraft.block.*;
import com.kpabr.backrooms.BackroomsMod;
import com.kpabr.backrooms.block.entity.CrateBlockEntity;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.PiglinBrain;
Expand All @@ -15,18 +15,22 @@
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.stat.Stats;
import net.minecraft.state.StateManager.Builder;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
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 org.jetbrains.annotations.Nullable;

public class CrateBlock extends BlockWithEntity implements Waterloggable {
Expand Down Expand Up @@ -55,6 +59,15 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}
}

@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
VoxelShape finalShape = VoxelShapes.cuboid(0f, 0.875f, 0f, 1f, 1, 1f);
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0.0625, 0.125f, 0.0625, 0.9375, 0.875f, 0.9375), BooleanBiFunction.OR);
finalShape = VoxelShapes.combine(finalShape, VoxelShapes.cuboid(0f, 0f, 0f, 1f, 0.125f, 1f), BooleanBiFunction.OR);
return finalShape;
}

@SuppressWarnings("deprecation")
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
Expand All @@ -74,6 +87,8 @@ public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Ran
if (blockEntity instanceof CrateBlockEntity crateBlockEntity) {
crateBlockEntity.tick();
}

super.scheduledTick(state, world, pos, random);
}

@Override
Expand All @@ -84,17 +99,18 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {

FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
return (BlockState) this.getDefaultState()
return this.getDefaultState()
.with(OPEN, false)
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
}

@SuppressWarnings("deprecation")
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
FluidState fs = state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
BackroomsMod.LOGGER.info(fs.toString());
return fs;
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -132,8 +148,8 @@ public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
}

@Override
protected void appendProperties(Builder<Block, BlockState> builder) {
builder.add(OPEN, WATERLOGGED);
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(OPEN).add(WATERLOGGED);
}

static {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/kpabr/backrooms/block/PipeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Waterloggable;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
Expand All @@ -15,7 +16,7 @@
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.world.World;

public class PipeBlock extends AbstractPipeBlock {
public class PipeBlock extends AbstractPipeBlock implements Waterloggable {
public final Block crackedPipe;

public PipeBlock(Settings settings, Block crackedPipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PyroilLineBlock extends BlockWithEntity {
Direction.SOUTH, WIRE_CONNECTION_SOUTH, Direction.WEST, WIRE_CONNECTION_WEST));
private static final Map<BlockState, VoxelShape> SHAPES = Maps.newHashMap();

// Idk what does that means, TODO:
// Idk what does that mean, TODO:
private static final Map<Direction, VoxelShape> field_24414 = Maps.newEnumMap(ImmutableMap.of(
Direction.NORTH, Block.createCuboidShape(3.0, 0.0, 0.0, 13.0, 1.0, 13.0),
Direction.SOUTH, Block.createCuboidShape(3.0, 0.0, 3.0, 13.0, 1.0, 16.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ public void tick() {
if (!this.removed) {
this.stateManager.updateViewerCount(this.getWorld(), this.getPos(), this.getCachedState());
}

}

void setOpen(BlockState state, boolean open) {
this.world.setBlockState(this.getPos(), (BlockState) state.with(CrateBlock.OPEN, open), 3);
this.world.setBlockState(this.getPos(), state.with(CrateBlock.OPEN, open), 3);
}

void playSound(BlockState state, SoundEvent soundEvent) {
Expand Down

0 comments on commit 95e9317

Please sign in to comment.