Waterlog the slope blocks

This commit is contained in:
quat1024 2023-07-06 01:14:50 -04:00
parent c96dc09e46
commit 71d21cd98a
3 changed files with 59 additions and 10 deletions

View File

@ -50,7 +50,10 @@ public class TemplateInteractionUtil {
}
public static BlockState setDefaultStates(BlockState in) {
return in.with(LIGHT, false).with(REDSTONE, false).with(SOLID, true);
if(in.contains(LIGHT)) in = in.with(LIGHT, false);
if(in.contains(REDSTONE)) in = in.with(REDSTONE, false);
if(in.contains(SOLID)) in = in.with(SOLID, true);
return in;
}
public static ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {

View File

@ -21,7 +21,7 @@ import net.minecraft.world.BlockView;
import javax.annotation.Nullable;
public class TemplateSlopeBlock extends TemplateBlock {
public class TemplateSlopeBlock extends WaterloggableTemplateBlock {
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;
public static final EnumProperty<BlockHalf> HALF = Properties.BLOCK_HALF;
@ -51,15 +51,16 @@ public class TemplateSlopeBlock extends TemplateBlock {
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockHalf half = switch(ctx.getSide()) {
BlockState sup = super.getPlacementState(ctx);
if(sup != null) sup = sup
.with(FACING, ctx.getHorizontalPlayerFacing())
.with(HALF, switch(ctx.getSide()) {
case UP -> BlockHalf.BOTTOM;
case DOWN -> BlockHalf.TOP;
default -> (ctx.getHitPos().getY() - (double) ctx.getBlockPos().getY() < 0.5) ? BlockHalf.BOTTOM : BlockHalf.TOP;
};
});
return getDefaultState()
.with(FACING, ctx.getHorizontalPlayerFacing())
.with(HALF, half);
return sup;
}
@Override

View File

@ -0,0 +1,45 @@
package io.github.cottonmc.templates.block;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Waterloggable;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;
public class WaterloggableTemplateBlock extends TemplateBlock implements Waterloggable {
public WaterloggableTemplateBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(Properties.WATERLOGGED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder.add(Properties.WATERLOGGED));
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockState sup = super.getPlacementState(ctx);
if(sup != null) sup = sup.with(Properties.WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).isOf(Fluids.WATER));
return sup;
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(Properties.WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState otherState, WorldAccess world, BlockPos pos, BlockPos moved) {
if(state.get(Properties.WATERLOGGED)) world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
return super.getStateForNeighborUpdate(state, direction, otherState, world, pos, moved);
}
}