bedrock tnt & entity tnt
This commit is contained in:
parent
1b2908660a
commit
b6b1dd464f
@ -0,0 +1,59 @@
|
||||
package com.jenny.enhancedexplosives.blocks;
|
||||
|
||||
import com.jenny.enhancedexplosives.entities.tnt.bedrockPrimedTNT;
|
||||
import com.jenny.enhancedexplosives.entities.tnt.selectivePrimedTNT;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.TntBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class bedrockTNTBlock extends TntBlock {
|
||||
public final float pRadius;
|
||||
public final int fuseTime;
|
||||
|
||||
public bedrockTNTBlock(Properties p_57422_, float pRadius, int fuseTime) {
|
||||
super(p_57422_);
|
||||
this.pRadius = pRadius;
|
||||
this.fuseTime = fuseTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
||||
explode(world, pos, igniter, this.pRadius, this.fuseTime);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void explode(Level p_57434_, BlockPos p_57435_, float pRadius, int fuseTime) {
|
||||
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void explode(Level p_57437_, BlockPos p_57438_, @Nullable LivingEntity p_57439_, float pRadius, int fuseTime) {
|
||||
if (!p_57437_.isClientSide) {
|
||||
bedrockPrimedTNT primedtnt = new bedrockPrimedTNT(p_57437_, (double)p_57438_.getX() + (double)0.5F, (double)p_57438_.getY(), (double)p_57438_.getZ() + (double)0.5F, p_57439_, pRadius, fuseTime);
|
||||
p_57437_.addFreshEntity(primedtnt);
|
||||
p_57437_.playSound((Player)null, primedtnt.getX(), primedtnt.getY(), primedtnt.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
p_57437_.gameEvent(p_57439_, GameEvent.PRIME_FUSE, p_57438_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wasExploded(Level level, @NotNull BlockPos blockPos, @NotNull Explosion pExplosion) {
|
||||
if (!level.isClientSide) {
|
||||
int ft = (short) (level.random.nextInt(fuseTime / 4) + fuseTime / 8);
|
||||
bedrockPrimedTNT primedtnt = new bedrockPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, ft);
|
||||
level.addFreshEntity(primedtnt);
|
||||
}
|
||||
}
|
||||
}
|
@ -61,6 +61,12 @@ public class blocks {
|
||||
public static final RegistryObject<Block> TNT_REPULSIVE = BLOCKS.register("tnt_repulsive", () -> new repulsiveTNTBlock(DEFAULT_PROPS, 4.0f, 80, 1));
|
||||
public static final RegistryObject<Item> TNT_REPULSIVE_ITEM = ITEMS.register("tnt_repulsive", () -> new BlockItemTooltip(TNT_REPULSIVE.get(), new Item.Properties()));
|
||||
|
||||
public static final RegistryObject<Block> TNT_BEDROCK = BLOCKS.register("tnt_bedrock", () -> new bedrockTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80));
|
||||
public static final RegistryObject<Item> TNT_BEDROCK_ITEM = ITEMS.register("tnt_bedrock", () -> new BlockItemTooltip(TNT_BEDROCK.get(), new Item.Properties()));
|
||||
|
||||
public static final RegistryObject<Block> TNT_ENTITY = BLOCKS.register("tnt_entity", () -> new entityTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80));
|
||||
public static final RegistryObject<Item> TNT_ENTITY_ITEM = ITEMS.register("tnt_entity", () -> new BlockItemTooltip(TNT_BEDROCK.get(), new Item.Properties()));
|
||||
|
||||
|
||||
public static void register(IEventBus bus) {
|
||||
BLOCKS.register(bus);
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.jenny.enhancedexplosives.blocks;
|
||||
|
||||
import com.jenny.enhancedexplosives.entities.tnt.EntityPrimedTNT;
|
||||
import com.jenny.enhancedexplosives.entities.tnt.bedrockPrimedTNT;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.TntBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class entityTNTBlock extends TntBlock {
|
||||
public final float pRadius;
|
||||
public final int fuseTime;
|
||||
|
||||
public entityTNTBlock(Properties p_57422_, float pRadius, int fuseTime) {
|
||||
super(p_57422_);
|
||||
this.pRadius = pRadius;
|
||||
this.fuseTime = fuseTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
||||
explode(world, pos, igniter, this.pRadius, this.fuseTime);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void explode(Level p_57434_, BlockPos p_57435_, float pRadius, int fuseTime) {
|
||||
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void explode(Level p_57437_, BlockPos p_57438_, @Nullable LivingEntity p_57439_, float pRadius, int fuseTime) {
|
||||
if (!p_57437_.isClientSide) {
|
||||
EntityPrimedTNT primedtnt = new EntityPrimedTNT(p_57437_, (double)p_57438_.getX() + (double)0.5F, (double)p_57438_.getY(), (double)p_57438_.getZ() + (double)0.5F, p_57439_, pRadius, fuseTime);
|
||||
p_57437_.addFreshEntity(primedtnt);
|
||||
p_57437_.playSound((Player)null, primedtnt.getX(), primedtnt.getY(), primedtnt.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
p_57437_.gameEvent(p_57439_, GameEvent.PRIME_FUSE, p_57438_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wasExploded(Level level, @NotNull BlockPos blockPos, @NotNull Explosion pExplosion) {
|
||||
if (!level.isClientSide) {
|
||||
int ft = (short) (level.random.nextInt(fuseTime / 4) + fuseTime / 8);
|
||||
EntityPrimedTNT primedtnt = new EntityPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, ft);
|
||||
level.addFreshEntity(primedtnt);
|
||||
}
|
||||
}
|
||||
}
|
@ -50,6 +50,15 @@ public class entities {
|
||||
ENTITY_TYPES.register("tnt_repulsive", () -> EntityType.Builder.<repulsivePrimedTNT>of(repulsivePrimedTNT::new, MobCategory.MISC)
|
||||
.fireImmune().sized(0.98F, 0.98F).clientTrackingRange(10).updateInterval(10).build("tnt_repulsive"));
|
||||
|
||||
public static final RegistryObject<EntityType<bedrockPrimedTNT>> TNT_BEDROCK =
|
||||
ENTITY_TYPES.register("tnt_bedrock", () -> EntityType.Builder.<bedrockPrimedTNT>of(bedrockPrimedTNT::new, MobCategory.MISC)
|
||||
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_bedrock"));
|
||||
|
||||
public static final RegistryObject<EntityType<EntityPrimedTNT>> TNT_ENTITY =
|
||||
ENTITY_TYPES.register("tnt_entity", () -> EntityType.Builder.<EntityPrimedTNT>of(EntityPrimedTNT::new, MobCategory.MISC)
|
||||
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_entity"));
|
||||
|
||||
|
||||
public static final RegistryObject<EntityType<tntArrow>> ARROW_TNT =
|
||||
ENTITY_TYPES.register("arrow_tnt", () -> EntityType.Builder.<tntArrow>of(tntArrow::new, MobCategory.MISC)
|
||||
.sized(0.48F, 0.48F).clientTrackingRange(64).build("arrow_tnt"));
|
||||
@ -89,6 +98,8 @@ public class entities {
|
||||
EntityRenderers.register(TNT_CLAYMORE.get(), BaseTNTRenderer::new);
|
||||
EntityRenderers.register(TNT_ENDER.get(), BaseTNTRenderer::new);
|
||||
EntityRenderers.register(TNT_REPULSIVE.get(), BaseTNTRenderer::new);
|
||||
EntityRenderers.register(TNT_BEDROCK.get(), BaseTNTRenderer::new);
|
||||
EntityRenderers.register(TNT_ENTITY.get(), BaseTNTRenderer::new);
|
||||
|
||||
EntityRenderers.register(TNT_SELECTIVE.get(), SelectiveTNTRenderer::new);
|
||||
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.jenny.enhancedexplosives.entities.tnt;
|
||||
|
||||
import com.jenny.enhancedexplosives.blocks.blocks;
|
||||
import com.jenny.enhancedexplosives.entities.entities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.ExplosionDamageCalculator;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EntityPrimedTNT extends basePrimedTNT {
|
||||
static class noEntityExplosionCalculator extends ExplosionDamageCalculator {
|
||||
public boolean shouldBlockExplode(@NotNull Explosion pExplosion, @NotNull BlockGetter pReader, @NotNull BlockPos pPos, @NotNull BlockState pState, float pPower) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public EntityPrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
|
||||
super(entities.TNT_ENTITY.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
|
||||
}
|
||||
|
||||
public EntityPrimedTNT(EntityType<EntityPrimedTNT> entityType, Level level) {
|
||||
super(entityType, level, null);
|
||||
}
|
||||
@Override
|
||||
protected void explode() {
|
||||
noEntityExplosionCalculator dmgCalc = new noEntityExplosionCalculator();
|
||||
this.level().explode(this, null, dmgCalc, position(), getPower(), false, Level.ExplosionInteraction.TNT);
|
||||
}
|
||||
|
||||
public BlockPos getBlockBelow() {
|
||||
return new BlockPos((int) Math.floor(getX()), (int) Math.floor(getY()) - 1, (int) Math.floor(getZ()));
|
||||
}
|
||||
|
||||
public String getBlock() {
|
||||
return level().getBlockState(getBlockBelow()).getBlock().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block renderBlock() {
|
||||
return blocks.TNT_ENTITY.get();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.jenny.enhancedexplosives.entities.tnt;
|
||||
|
||||
import com.jenny.enhancedexplosives.blocks.blocks;
|
||||
import com.jenny.enhancedexplosives.entities.entities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.ExplosionDamageCalculator;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class bedrockPrimedTNT extends basePrimedTNT {
|
||||
static class noExplosionCalculator extends ExplosionDamageCalculator {
|
||||
public boolean shouldBlockExplode(@NotNull Explosion pExplosion, @NotNull BlockGetter pReader, @NotNull BlockPos pPos, @NotNull BlockState pState, float pPower) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bedrockPrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
|
||||
super(entities.TNT_BEDROCK.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
|
||||
}
|
||||
|
||||
public bedrockPrimedTNT(EntityType<bedrockPrimedTNT> entityType, Level level) {
|
||||
super(entityType, level, null);
|
||||
}
|
||||
@Override
|
||||
protected void explode() {
|
||||
noExplosionCalculator dmgCalc = new noExplosionCalculator();
|
||||
this.level().explode(this, null, dmgCalc, position(), getPower(), false, Level.ExplosionInteraction.TNT);
|
||||
explodeBelow();
|
||||
}
|
||||
|
||||
public BlockPos getBlockBelow() {
|
||||
return new BlockPos((int) Math.floor(getX()), (int) Math.floor(getY()) - 1, (int) Math.floor(getZ()));
|
||||
}
|
||||
|
||||
public String getBlock() {
|
||||
return level().getBlockState(getBlockBelow()).getBlock().toString();
|
||||
}
|
||||
|
||||
private void explodeBelow()
|
||||
{
|
||||
if (Objects.equals(getBlock(), Blocks.BEDROCK.toString())) {
|
||||
level().destroyBlock(getBlockBelow(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block renderBlock() {
|
||||
return blocks.TNT_BEDROCK.get();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user