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

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"new_soviet:landmine"
]
}

View file

@ -0,0 +1,20 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "new_soviet:landmine"
}
],
"rolls": 1.0
}
]
}

View file

@ -179,6 +179,7 @@ public class DataGeneration implements DataGeneratorEntrypoint {
addDrop(NSE_Custom.SIREN);
addDrop(NSE_Custom.LAMP);
addDrop(NSE_Custom.CEILING_FAN);
addDrop(NSE_Custom.LANDMINE);
}
}
@ -310,6 +311,9 @@ public class DataGeneration implements DataGeneratorEntrypoint {
.add(NSE_Blocks.CYAN_LINOLEUM)
.add(NSE_Blocks.CROSS_ORANGE_LINOLEUM)
.add(NSE_Blocks.CROSS_BROWN_LINOLEUM);
getOrCreateTagBuilder(BlockTags.SHOVEL_MINEABLE)
.add(NSE_Custom.LANDMINE);
}
}

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) {

View file

@ -5,6 +5,7 @@ import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.MapColor;
import net.minecraft.block.entity.BlockEntityType;
@ -44,7 +45,7 @@ public class NSE_Custom {
public static final SirenBlock SIREN = new SirenBlock();
public static final SoundEvent SIREN_SOUND = SoundEvent.of(new Identifier(NewSoviet.MOD_ID, "siren_sound"));
public static final LandMineBlock LANDMINE = new LandMineBlock(FabricBlockSettings.create().mapColor(MapColor.LIGHT_GRAY));
public static final LandMineBlock LANDMINE = new LandMineBlock(FabricBlockSettings.create().mapColor(MapColor.LIGHT_GRAY).offset(AbstractBlock.OffsetType.XZ).dynamicBounds().strength(3f, 2f));
private static final ItemGroup NSE_CUSTOM_TAB = FabricItemGroup.builder()
.icon(() -> new ItemStack(TV))

View file

@ -1,7 +1,8 @@
{
"variants": {
"": {
"model": "new_soviet:block/landmine"
}
"facing=north": { "model": "new_soviet:block/landmine", "uvlock": true },
"facing=east": { "model": "new_soviet:block/landmine", "y": 90, "uvlock": false },
"facing=south": { "model": "new_soviet:block/landmine", "y": 180, "uvlock": false },
"facing=west": { "model": "new_soviet:block/landmine", "y": 270, "uvlock": false }
}
}