Skip to content

Commit

Permalink
Made sure previous commit actually work
Browse files Browse the repository at this point in the history
Made grave waterlogging actually work
  • Loading branch information
B1n-ry committed Feb 15, 2024
1 parent eb74bdd commit 524f808
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/b1n_ry/yigd/DeathHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onPlayerDeath(ServerPlayerEntity player, ServerWorld world, Vec3d po
assert graveWorld != null; // Should never be able to be null on server

Direction direction = dirGravePos.dir();
boolean waterlogged = graveWorld.getFluidState(gravePos).equals(Fluids.WATER.getDefaultState()); // Grave generated in full water block (submerged)
boolean waterlogged = graveWorld.getFluidState(gravePos).isOf(Fluids.WATER); // Grave generated in full water block (submerged)
BlockState graveBlock = Yigd.GRAVE_BLOCK.getDefaultState()
.with(Properties.HORIZONTAL_FACING, direction)
.with(Properties.WATERLOGGED, waterlogged);
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/com/b1n_ry/yigd/block/GraveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand All @@ -38,6 +40,8 @@
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.tick.OrderedTick;
import org.jetbrains.annotations.Nullable;

import java.util.*;
Expand All @@ -50,6 +54,7 @@ public class GraveBlock extends BlockWithEntity implements BlockEntityProvider,

public GraveBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH).with(Properties.WATERLOGGED, false));
}

@Override
Expand All @@ -73,7 +78,23 @@ public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable Livi
public BlockState getPlacementState(ItemPlacementContext ctx) {
Direction dir = ctx.getHorizontalPlayerFacing().getOpposite(); // Have the grave facing you, not away from you
BlockState state = this.getDefaultState();
return state.with(Properties.HORIZONTAL_FACING, dir);
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
return state.with(Properties.HORIZONTAL_FACING, dir).with(Properties.WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
}

@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(Properties.WATERLOGGED)) {
world.getFluidTickScheduler().scheduleTick(OrderedTick.create(Fluids.WATER, pos));
}
return direction.getAxis().isHorizontal() ? state : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}

@SuppressWarnings("deprecation")
@Override
public FluidState getFluidState(BlockState state) {
return state.get(Properties.WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}

@Override
Expand Down Expand Up @@ -225,7 +246,10 @@ public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockStat
Optional<GraveComponent> component = DeathInfoManager.INSTANCE.getGrave(grave.getGraveId());
component.ifPresent(graveBlockEntity::setComponent);

world.updateListeners(pos, state, state, Block.NOTIFY_ALL);
Yigd.END_OF_TICK.add(() -> { // Required because it might take a tick for the game to realize the block is replaced
graveBlockEntity.markDirty();
world.updateListeners(pos, state, state, Block.NOTIFY_ALL);
});

return;
}
Expand All @@ -237,8 +261,7 @@ public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockStat
@Override
@SuppressWarnings("deprecation")
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
if (world.getBlockEntity(pos) instanceof GraveBlockEntity grave && grave.getComponent() != null
&& grave.getComponent().getStatus() != GraveStatus.CLAIMED
if (world.getBlockEntity(pos) instanceof GraveBlockEntity grave && grave.isUnclaimed()
&& !YigdConfig.getConfig().graveConfig.retrieveMethods.onBreak) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void setGraveSkull(@Nullable GameProfile skull) {
public @Nullable BlockState getPreviousState() {
return this.previousState;
}
public boolean isClaimed() {
return this.claimed;
public boolean isUnclaimed() {
return !this.claimed;
}
public void setClaimed(boolean claimed) {
this.claimed = claimed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void render(GraveBlockEntity entity, float tickDelta, MatrixStack matrice

matrices.multiply(RotationAxis.POSITIVE_Y.rotation(rotation), .5f, .5f, .5f);

if (config.useGlowingEffect && !entity.isClaimed()) {
if (config.useGlowingEffect && entity.isUnclaimed()) {
// Get the actual outline vertex consumer, instead of the normal one
OutlineVertexConsumerProvider consumerProvider = ((WorldRendererAccessor) this.client.worldRenderer).getBufferBuilders().getOutlineVertexConsumers();
this.renderGlowingOutline(entity, tickDelta, matrices, consumerProvider, light, overlay);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"values": [
"#minecraft:replacable"
"#minecraft:replaceable"
]
}

0 comments on commit 524f808

Please sign in to comment.