Improve and fix landmine

This commit is contained in:
Andrew-71 2023-08-11 14:49:19 +03:00
parent 497ae9149b
commit b43a0668aa
6 changed files with 50 additions and 27 deletions

View file

@ -17,9 +17,7 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
@ -28,19 +26,14 @@ import net.minecraft.world.explosion.Explosion;
import org.jetbrains.annotations.Nullable;
import su.a71.new_soviet.NewSoviet;
import net.minecraft.block.BrushableBlock;
import net.minecraft.block.TorchBlock;
import net.minecraft.item.BrushItem;
public class LandMineBlock extends Block implements Waterloggable {
public class LandMineBlock extends HorizontalFacingBlock implements Waterloggable {
public static final BooleanProperty WATERLOGGED;
protected static final VoxelShape SHAPE;
public LandMineBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(WATERLOGGED, false));
this.setDefaultState(this.stateManager.getDefaultState().with(WATERLOGGED, false).with(Properties.HORIZONTAL_FACING, Direction.NORTH));
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
@ -71,24 +64,22 @@ public class LandMineBlock extends Block implements Waterloggable {
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
if (!world.isClient) {
BlockPos blockPos = hit.getBlockPos();
if (projectile.canModifyAt(world, blockPos)) {
if (projectile.canModifyAt(world, blockPos))
explode(world, blockPos);
}
}
}
// With a shovel, 25% chance of explosion on break
// We would have a 25% chance of explosion on break with a shovel, but I can't implement brushing yet.
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, 4) != 1) {
// explode(world, pos);
// }
// }
super.onBreak(world, pos, state, player);
}
// Only explode every 2/3rd of times to prevent instant explosion chains
// Only chain explode every 2/3rd of times to nerf instant long range explosions
@Override
public void onDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) {
if (!world.isClient) {
@ -100,7 +91,7 @@ public class LandMineBlock extends Block implements Waterloggable {
super.onDestroyedByExplosion(world, pos, explosion);
}
// Without a shovel, 80% chance of explosion on contact
// Without a shovel, 80% 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))
@ -130,7 +121,7 @@ public class LandMineBlock extends Block implements Waterloggable {
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
return (BlockState)this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
return (BlockState)this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
@ -139,7 +130,7 @@ public class LandMineBlock extends Block implements Waterloggable {
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED);
builder.add(WATERLOGGED, Properties.HORIZONTAL_FACING);
}
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {