Improve landmine

This commit is contained in:
Andrew-71 2023-10-02 12:00:01 +03:00
parent f1bf483b87
commit bcdda97438
5 changed files with 31 additions and 13 deletions

View file

@ -30,11 +30,18 @@ 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 float explosion_power;
public boolean creates_fire;
public World.ExplosionSourceType explosion_type; // None for no destruction, TNT for destruction
public boolean mob_detonation;
public LandMineBlock(Settings settings) {
public LandMineBlock(Settings settings, float explosion_power, World.ExplosionSourceType explosion_type, boolean creates_fire, boolean mob_detonation) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(WATERLOGGED, false).with(Properties.HORIZONTAL_FACING, Direction.NORTH));
this.explosion_type = explosion_type;
this.creates_fire = creates_fire;
this.explosion_power = explosion_power;
this.mob_detonation = mob_detonation;
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
@ -47,17 +54,21 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
@Override
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
if (!world.isClient && entity.canModifyAt(world, pos)) {
if (!world.isClient && entity.canModifyAt(world, pos) && (this.mob_detonation || entity instanceof PlayerEntity)) {
if (!((PlayerEntity) entity).isCreative()) {
explode(world, pos);
}
}
super.onLandedUpon(world, state, pos, entity, fallDistance);
}
@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if (!world.isClient) {
if (!world.isClient && entity.canModifyAt(world, pos) && (this.mob_detonation || entity instanceof PlayerEntity)) {
if (!((PlayerEntity) entity).isCreative()) {
explode(world, pos);
}
}
super.onSteppedOn(world, pos, state, entity);
}
@ -80,11 +91,11 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
super.onBreak(world, pos, state, player);
}
// Only chain explode every 20% of times to prevent instant&long explosion chains
// Only chain explode every 10% 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(1, 5);
int chance = NewSoviet.RANDOM.nextBetween(1, 10);
if (chance == 1) {
explode(world, pos);
}
@ -106,7 +117,7 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
// On contact explode
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {
if (!world.isClient && player.canModifyAt(world, pos)) {
explode(world, pos);
}
return ActionResult.success(world.isClient);
@ -115,7 +126,7 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
public void explode(World world, BlockPos pos) {
if (world.isClient()) return;
world.removeBlock(pos, false);
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), explosion_power, World.ExplosionSourceType.TNT);
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), explosion_power, creates_fire, explosion_type);
}
@Nullable

View file

@ -17,6 +17,7 @@ import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.World;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.blocks.*;
import su.a71.new_soviet.blocks.lamps.GoldenTableLampBlock;
@ -71,7 +72,9 @@ public class NSE_Custom extends NSE_BaseRegistration {
public static final SirenBlock SIREN = new SirenBlock();
public static final LandMineBlock LANDMINE = new LandMineBlock(FabricBlockSettings.create().mapColor(MapColor.LIGHT_GRAY).offset(AbstractBlock.OffsetType.XZ).dynamicBounds());
// incendiary - creates fire
// HE - destroys blocks
public static final LandMineBlock AP_LANDMINE = new LandMineBlock(FabricBlockSettings.create().mapColor(MapColor.LIGHT_GRAY).offset(AbstractBlock.OffsetType.XZ).dynamicBounds(), 4.0f, World.ExplosionSourceType.NONE, false, false);
public static final CheckerBlock WHITE_CHECKER = new CheckerBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).hardness(0.1f).nonOpaque().mapColor(MapColor.WHITE));
public static final CheckerBlock BLACK_CHECKER = new CheckerBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.DECORATED_POT).hardness(0.1f).nonOpaque().mapColor(MapColor.BLACK));
@ -114,7 +117,7 @@ public class NSE_Custom extends NSE_BaseRegistration {
registerBlock("lamp_post_base", () -> LAMP_POST_BASE, NSE_CUSTOM_TAB);
registerBlock("ceiling_fan", () -> CEILING_FAN, NSE_CUSTOM_TAB);
registerBlock("siren", () -> SIREN, NSE_CUSTOM_TAB);
registerBlock("landmine", () -> LANDMINE, NSE_CUSTOM_TAB);
registerBlock("ap_landmine", () -> AP_LANDMINE, NSE_CUSTOM_TAB);
registerBlock("switch", () -> SWITCH, NSE_CUSTOM_TAB);
registerBlock("dark_switch", () -> DARK_SWITCH, NSE_CUSTOM_TAB);
registerBlock("white_checker", () -> WHITE_CHECKER, NSE_CUSTOM_TAB);

View file

@ -469,5 +469,9 @@
"block.new_soviet.barbed_wire": "Barbed Wire",
"advancement.new_soviet.root.name": "A New Era",
"advancement.new_soviet.root.desc": "Time to create something great"
"advancement.new_soviet.root.desc": "Time to create something great",
"advancement.new_soviet.sickle.name": "Tool of a worker",
"advancement.new_soviet.sickle.desc": "Acquire a sickle",
"advancement.new_soviet.sickle_kill.name": "Kolkhoz Warrior",
"advancement.new_soviet.sickle_kill.desc": "Kill someone with a sickle"
}