added waterlogging to non-full blocks

Closes #75
This commit is contained in:
Ellpeck 2020-02-05 14:30:17 +01:00
parent f5ae1d59b4
commit 3319a9673a
14 changed files with 107 additions and 15 deletions

View file

@ -24,6 +24,11 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
super("animal_container", TileEntityAnimalContainer::new, ModBlocks.prop(Blocks.STONE)); super("animal_container", TileEntityAnimalContainer::new, ModBlocks.prop(Blocks.STONE));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;

View file

@ -21,12 +21,13 @@ public class BlockAutoCrafter extends BlockContainerImpl implements ICustomBlock
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(FACING); builder.add(FACING);
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(FACING, context.getPlayer().getHorizontalFacing()); return super.getStateForPlacement(context).with(FACING, context.getPlayer().getHorizontalFacing());
} }
@Override @Override

View file

@ -24,6 +24,11 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus
super("blast_furnace_booster", TileEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE)); super("blast_furnace_booster", TileEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;
@ -31,12 +36,13 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(FACING); builder.add(FACING);
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); return super.getStateForPlacement(context).with(FACING, context.getPlacementHorizontalFacing().getOpposite());
} }
@Override @Override

View file

@ -29,6 +29,11 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
super("chunk_loader", TileEntityChunkLoader::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); super("chunk_loader", TileEntityChunkLoader::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {

View file

@ -7,8 +7,15 @@ import de.ellpeck.naturesaura.reg.ModTileType;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tags.FluidTags;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
@ -17,6 +24,7 @@ import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.loot.LootContext; import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootParameters; import net.minecraft.world.storage.loot.LootParameters;
import net.minecraft.world.storage.loot.conditions.BlockStateProperty;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
@ -36,6 +44,41 @@ public class BlockContainerImpl extends ContainerBlock implements IModItem {
ModRegistry.add(this); ModRegistry.add(this);
ModRegistry.add(this.tileType); ModRegistry.add(this.tileType);
if(this.hasWaterlogging())
this.setDefaultState(this.stateContainer.getBaseState().with(BlockStateProperties.WATERLOGGED, false));
}
protected boolean hasWaterlogging() {
return false;
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
if (this.hasWaterlogging())
builder.add(BlockStateProperties.WATERLOGGED);
}
@Override
public IFluidState getFluidState(BlockState state) {
return this.hasWaterlogging() && state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}
@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
if (this.hasWaterlogging() && stateIn.get(BlockStateProperties.WATERLOGGED))
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
}
@Override
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) {
if (this.hasWaterlogging()) {
IFluidState state = context.getWorld().getFluidState(context.getPos());
return this.getDefaultState().with(BlockStateProperties.WATERLOGGED, state.isTagged(FluidTags.WATER) && state.getLevel() == 8);
}
return super.getStateForPlacement(context);
} }
@Nullable @Nullable

View file

@ -28,7 +28,7 @@ import java.util.function.Supplier;
public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType { public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType {
public BlockFieldCreator() { public BlockFieldCreator() {
super("field_creator", TileEntityFieldCreator::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); super("field_creator", TileEntityFieldCreator::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE));
} }
@Override @Override

View file

@ -41,6 +41,11 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
super("furnace_heater", TileEntityFurnaceHeater::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("furnace_heater", TileEntityFurnaceHeater::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) { public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
@ -86,13 +91,14 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(FACING); builder.add(FACING);
} }
@Nullable @Nullable
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(FACING, context.getFace()); return super.getStateForPlacement(context).with(FACING, context.getFace());
} }
@Override @Override

View file

@ -52,6 +52,11 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
super("grated_chute", TileEntityGratedChute::new, ModBlocks.prop(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL)); super("grated_chute", TileEntityGratedChute::new, ModBlocks.prop(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
switch (state.get(FACING)) { switch (state.get(FACING)) {
@ -109,7 +114,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
Direction newFacing = context.getFace().getOpposite(); Direction newFacing = context.getFace().getOpposite();
if (newFacing == Direction.UP) if (newFacing == Direction.UP)
newFacing = Direction.DOWN; newFacing = Direction.DOWN;
return this.getDefaultState().with(FACING, newFacing); return super.getStateForPlacement(context).with(FACING, newFacing);
} }
@Override @Override
@ -137,6 +142,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(FACING); builder.add(FACING);
} }

View file

@ -36,6 +36,11 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
super("nature_altar", TileEntityNatureAltar::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); super("nature_altar", TileEntityNatureAltar::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;

View file

@ -36,6 +36,11 @@ public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvi
super("offering_table", TileEntityOfferingTable::new, ModBlocks.prop(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); super("offering_table", TileEntityOfferingTable::new, ModBlocks.prop(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true); return Helper.putStackOnTile(player, handIn, pos, 0, true);

View file

@ -20,6 +20,11 @@ public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBloc
super("powder_placer", TileEntityPowderPlacer::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE)); super("powder_placer", TileEntityPowderPlacer::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE));
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;

View file

@ -42,6 +42,11 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@SubscribeEvent @SubscribeEvent
public void onSpawn(LivingSpawnEvent.CheckSpawn event) { public void onSpawn(LivingSpawnEvent.CheckSpawn event) {
if (event.getSpawner() != null) if (event.getSpawner() != null)

View file

@ -52,6 +52,11 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@Override
protected boolean hasWaterlogging() {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE; return SHAPE;

View file

@ -11,8 +11,7 @@
"faces": { "faces": {
"down": { "down": {
"uv": [0, 4, 12, 16], "uv": [0, 4, 12, 16],
"texture": "#texture", "texture": "#texture"
"cullface": "down"
}, },
"up": { "up": {
"uv": [0, 4, 12, 16], "uv": [0, 4, 12, 16],
@ -20,23 +19,19 @@
}, },
"north": { "north": {
"uv": [0, 0, 12, 4], "uv": [0, 0, 12, 4],
"texture": "#texture", "texture": "#texture"
"cullface": "north"
}, },
"south": { "south": {
"uv": [0, 0, 12, 4], "uv": [0, 0, 12, 4],
"texture": "#texture", "texture": "#texture"
"cullface": "south"
}, },
"west": { "west": {
"uv": [0, 0, 12, 4], "uv": [0, 0, 12, 4],
"texture": "#texture", "texture": "#texture"
"cullface": "west"
}, },
"east": { "east": {
"uv": [0, 0, 12, 4], "uv": [0, 0, 12, 4],
"texture": "#texture", "texture": "#texture"
"cullface": "east"
} }
} }
} }