Add concrete with bars functionality and other minor improvements
This commit is contained in:
parent
55c1976583
commit
c1d7208ae8
15 changed files with 212 additions and 140 deletions
|
@ -1,26 +1,71 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.enums.Thickness;
|
||||
import net.minecraft.entity.Entity;
|
||||
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.BooleanProperty;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ConcreteWithBarsBlock extends HorizontalFacingBlock implements Waterloggable {
|
||||
public static final DirectionProperty VERTICAL_DIRECTION;
|
||||
public static final BooleanProperty WATERLOGGED;
|
||||
|
||||
public class ConcreteWithBarsBlock extends HorizontalFacingBlock {
|
||||
public ConcreteWithBarsBlock(Settings settings) {
|
||||
super(settings);
|
||||
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
|
||||
setDefaultState(getDefaultState()
|
||||
.with(Properties.HORIZONTAL_FACING, Direction.NORTH)
|
||||
.with(VERTICAL_DIRECTION, Direction.UP)
|
||||
.with(WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(Properties.HORIZONTAL_FACING);
|
||||
builder.add(Properties.HORIZONTAL_FACING, VERTICAL_DIRECTION, WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
|
||||
|
||||
return super.getPlacementState(ctx)
|
||||
.with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(VERTICAL_DIRECTION, ctx.getVerticalPlayerLookDirection().getOpposite())
|
||||
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
}
|
||||
|
||||
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
|
||||
if (state.get(VERTICAL_DIRECTION) == Direction.UP) {
|
||||
entity.handleFallDamage(fallDistance + 2.0F, 2.0F, world.getDamageSources().stalagmite());
|
||||
} else {
|
||||
super.onLandedUpon(world, state, pos, entity, fallDistance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (state.get(WATERLOGGED)) {
|
||||
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
|
||||
}
|
||||
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
static {
|
||||
VERTICAL_DIRECTION = Properties.VERTICAL_DIRECTION;
|
||||
WATERLOGGED = Properties.WATERLOGGED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import su.a71.new_soviet.NewSoviet;
|
|||
public class LandMineBlock extends HorizontalFacingBlock implements Waterloggable {
|
||||
public static final BooleanProperty WATERLOGGED;
|
||||
protected static final VoxelShape SHAPE;
|
||||
public float explosion_power = 4.0f;
|
||||
|
||||
public LandMineBlock(Settings settings) {
|
||||
super(settings);
|
||||
|
@ -69,34 +70,34 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
|
|||
}
|
||||
}
|
||||
|
||||
// We would have a 25% chance of explosion on break with a shovel, but I can't implement brushing yet.
|
||||
// 20% chance of explosion on break without a shovel
|
||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
// if (!world.isClient() && !player.isCreative() && !(player.getHandItems().iterator().next().getItem() instanceof ShovelItem)) {
|
||||
// if (NewSoviet.RANDOM.nextBetween(1, 4) != 1) {
|
||||
// explode(world, pos);
|
||||
// }
|
||||
// }
|
||||
if (!world.isClient() && !player.isCreative() && !(player.getHandItems().iterator().next().getItem() instanceof ShovelItem)) {
|
||||
if (NewSoviet.RANDOM.nextBetween(1, 5) == 1) {
|
||||
explode(world, pos);
|
||||
}
|
||||
}
|
||||
super.onBreak(world, pos, state, player);
|
||||
}
|
||||
|
||||
// Only chain explode every 2/3rd of times to nerf instant long range explosions
|
||||
// Only chain explode every 20% of times to prevent instant&long explosion chains
|
||||
@Override
|
||||
public void onDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) {
|
||||
if (!world.isClient) {
|
||||
int chance = NewSoviet.RANDOM.nextBetween(0, 2);
|
||||
if (chance != 0) {
|
||||
int chance = NewSoviet.RANDOM.nextBetween(1, 5);
|
||||
if (chance == 1) {
|
||||
explode(world, pos);
|
||||
}
|
||||
}
|
||||
super.onDestroyedByExplosion(world, pos, explosion);
|
||||
}
|
||||
|
||||
// Without a shovel, 80% chance of explosion on breaking start
|
||||
// Without a shovel, 5% chance of explosion on breaking start
|
||||
@Override
|
||||
public void onBlockBreakStart(BlockState state, World world, BlockPos pos, PlayerEntity player) {
|
||||
if (!world.isClient() && !(player.getHandItems().iterator().next().getItem() instanceof ShovelItem))
|
||||
{
|
||||
if (NewSoviet.RANDOM.nextBetween(1, 10) < 2) {
|
||||
if (NewSoviet.RANDOM.nextBetween(1, 100) < 5) {
|
||||
explode(world, pos);
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +115,7 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
|
|||
public void explode(World world, BlockPos pos) {
|
||||
if (world.isClient()) return;
|
||||
world.removeBlock(pos, false);
|
||||
float f = 4.0F;
|
||||
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), 4.0F, World.ExplosionSourceType.TNT);
|
||||
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), explosion_power, World.ExplosionSourceType.TNT);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -152,8 +152,6 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
|
|||
|
||||
static {
|
||||
SHAPE = Block.createCuboidShape(4, 0, 4, 12, 4, 12); // VoxelShapes.cuboid(0.4, 0, 0.4, 0.6, 0.3, 0.6); //
|
||||
|
||||
// SHAPE = Block.createCuboidShape(5, 0, 5, 11, 3, 11); // VoxelShapes.cuboid(0.4, 0, 0.4, 0.6, 0.3, 0.6); //
|
||||
WATERLOGGED = Properties.WATERLOGGED;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue