Rifts are now waterloggable, and breaking DimensionalDoorBlocks that are water logged now make the subesquent DetachedRiftBlock waterlogged.

This commit is contained in:
MalekiRe 2021-06-13 20:43:05 -07:00
parent ad69c22281
commit f9bec88432
3 changed files with 91 additions and 11 deletions

View file

@ -2,18 +2,16 @@ package org.dimdev.dimdoors.block;
import java.util.Random;
import net.minecraft.block.*;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.particle.client.RiftParticleEffect;
import org.dimdev.dimdoors.world.ModDimensions;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.MapColor;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
@ -26,13 +24,13 @@ import net.minecraft.world.World;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public class DetachedRiftBlock extends BlockWithEntity implements RiftProvider<DetachedRiftBlockEntity> {
public class DetachedRiftBlock extends WaterLoggableBlockWithEntity implements RiftProvider<DetachedRiftBlockEntity>, Waterloggable {
public static final String ID = "rift";
public DetachedRiftBlock(Block.Settings settings) {
super(settings);
}
@Override
public MapColor getDefaultMapColor() {
return MapColor.BLACK;

View file

@ -0,0 +1,82 @@
package org.dimdev.dimdoors.block;
import net.minecraft.block.*;
import net.minecraft.block.enums.DoubleBlockHalf;
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.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.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;
public abstract class WaterLoggableBlockWithEntity extends BlockWithEntity implements Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
protected WaterLoggableBlockWithEntity(Settings settings) {
super(settings);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(WATERLOGGED);
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ActionResult result = super.onUse(state, world, pos, player, hand, hit);
if (result.isAccepted()) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return result;
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
BlockPos up = pos.up();
world.setBlockState(up, state.with(WATERLOGGED, world.getFluidState(up).getFluid() == Fluids.WATER), 3);
}
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
super.neighborUpdate(state, world, pos, block, fromPos, notify);
if (state.get(WATERLOGGED)) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
boolean water = ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER;
BlockState state = super.getPlacementState(ctx);
if (state == null) return null;
if (water) return state.with(WATERLOGGED, true);
return state;
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
BlockState newState = super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
if (newState.isAir() && state.getFluidState().getFluid() == Fluids.WATER) return Blocks.WATER.getDefaultState();
return newState;
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
}

View file

@ -111,7 +111,7 @@ public class DimensionalDoorBlock extends WaterLoggableDoorBlock implements Rift
}
if (blockEntity instanceof EntranceRiftBlockEntity
&& blockState.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(blockPos, ModBlocks.DETACHED_RIFT.getDefaultState());
world.setBlockState(blockPos, ModBlocks.DETACHED_RIFT.getDefaultState().with(WATERLOGGED, blockState.get(WATERLOGGED)));
((DetachedRiftBlockEntity) world.getBlockEntity(blockPos)).setData(((EntranceRiftBlockEntity) blockEntity).getData());
}
}
@ -175,7 +175,7 @@ public class DimensionalDoorBlock extends WaterLoggableDoorBlock implements Rift
&& !DimensionalDoorsInitializer.getConfig().getDoorsConfig().placeRiftsInCreativeMode
)
) {
world.setBlockState(blockPos, ModBlocks.DETACHED_RIFT.getDefaultState());
world.setBlockState(blockPos, ModBlocks.DETACHED_RIFT.getDefaultState().with(WATERLOGGED, blockState.get(WATERLOGGED)));
((DetachedRiftBlockEntity) world.getBlockEntity(blockPos)).setData(((EntranceRiftBlockEntity) blockEntity).getData());
}
}
@ -219,7 +219,7 @@ public class DimensionalDoorBlock extends WaterLoggableDoorBlock implements Rift
return;
}
if (blockEntity instanceof EntranceRiftBlockEntity && state.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState().with(WATERLOGGED, state.get(WATERLOGGED)));
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).setData(((EntranceRiftBlockEntity) blockEntity).getData());
}
});