added WaterLoggableDoorBlock,

DimensionalDoorBlock is subclass now
This commit is contained in:
CreepyCre 2021-04-17 03:54:46 +02:00
parent 523e238390
commit 1135a8188a
4 changed files with 126 additions and 1 deletions

View file

@ -1,7 +1,9 @@
package org.dimdev.dimdoors.block.door;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.event.GameEvent;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.CoordinateTransformerBlock;
import org.dimdev.dimdoors.block.ModBlocks;
@ -30,7 +32,7 @@ import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<EntranceRiftBlockEntity>, CoordinateTransformerBlock {
public class DimensionalDoorBlock extends WaterLoggableDoorBlock implements RiftProvider<EntranceRiftBlockEntity>, CoordinateTransformerBlock {
public DimensionalDoorBlock(Settings settings) {
super(settings);
}
@ -66,7 +68,11 @@ public class DimensionalDoorBlock extends DoorBlock implements RiftProvider<Entr
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
state = state.cycle(OPEN);
world.setBlockState(pos, state, 10);
if (!world.isClient && state.get(WATERLOGGED)) {
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
world.syncWorldEvent(player, state.get(OPEN) ? this.material == Material.METAL ? 1005 : 1006 : this.material == Material.METAL ? 1011 : 1012, pos, 0);
world.emitGameEvent(player, this.isOpen(state) ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, pos);
return ActionResult.SUCCESS;
}

View file

@ -0,0 +1,104 @@
package org.dimdev.dimdoors.block.door;
import net.minecraft.block.*;
import net.minecraft.block.enums.DoorHinge;
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 class WaterLoggableDoorBlock extends DoorBlock implements Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
protected WaterLoggableDoorBlock(Settings settings) {
super(settings);
setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(OPEN, false).with(HINGE, DoorHinge.LEFT).with(POWERED, false).with(HALF, DoubleBlockHalf.LOWER).with(WATERLOGGED, false));
}
@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(HALF, DoubleBlockHalf.UPPER).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) {
boolean bl = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN));
super.neighborUpdate(state, world, pos, block, fromPos, notify);
if (bl && !world.isClient && 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 (state.getFluidState().getFluid() == Fluids.WATER) {
if (newState.isAir()) return Blocks.WATER.getDefaultState();
if (newState.getProperties().contains(WATERLOGGED)) return newState.with(WATERLOGGED, true);
}
return newState;
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
DoubleBlockHalf doubleBlockHalf = state.get(HALF);
if (doubleBlockHalf == DoubleBlockHalf.UPPER) {
BlockPos blockPos = pos.down();
BlockState blockState = world.getBlockState(blockPos);
if (blockState.isOf(state.getBlock()) && blockState.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(blockPos, world.getFluidState(blockPos).getFluid() == Fluids.WATER ? Blocks.WATER.getDefaultState() : Blocks.AIR.getDefaultState(), 35);
world.syncWorldEvent(player, 2001, blockPos, Block.getRawIdFromState(blockState));
}
}
super.onBreak(world, pos, state, player);
}
}

View file

@ -11,6 +11,8 @@ import org.dimdev.dimdoors.block.door.DimensionalDoorBlockRegistrar;
import org.dimdev.dimdoors.item.DimensionalDoorItemRegistrar;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
public class DimensionalDoorModelVariantProvider implements ModelVariantProvider {
private static final Identifier childItem = new Identifier("dimdoors:item/child_item");
@ -22,6 +24,14 @@ public class DimensionalDoorModelVariantProvider implements ModelVariantProvider
if (blockRegistrar.isMapped(identifier)) {
Identifier mapped = blockRegistrar.get(identifier);
ModelIdentifier newId = new ModelIdentifier(mapped, modelId.getVariant());
UnbakedModel model = context.loadModel(newId);
if (model != null) return model;
ArrayList<String> variantArray = new ArrayList<>();
for (String part : modelId.getVariant().split(",")) {
if (!part.startsWith("waterlogged")) variantArray.add(part);
}
String variant = String.join(",", variantArray);
newId = new ModelIdentifier(mapped, variant);
return context.loadModel(newId);
} else if (identifier.getPath().startsWith(DimensionalDoorItemRegistrar.PREFIX)) {
return context.loadModel(childItem);

View file

@ -88,6 +88,11 @@ public class DimensionalDoorItem extends TallBlockItem {
return result;
}
@Override
protected boolean place(ItemPlacementContext context, BlockState state) {
return context.getWorld().setBlockState(context.getBlockPos(), state, 11);
}
public static boolean isRiftNear(World world, BlockPos pos) {
for (int x = pos.getX() - 5; x < pos.getX() + 5; x++) {
for (int y = pos.getY() - 5; y < pos.getY() + 5; y++) {