Use static fuse in static way.

This commit is contained in:
drcrazy 2018-09-07 13:31:38 +03:00
parent 67226de701
commit 8cac9a9315
4 changed files with 37 additions and 31 deletions

View file

@ -33,8 +33,10 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
@ -59,13 +61,13 @@ public class BlockNuke extends BaseBlock {
RebornModelRegistry.registerModel(new ModelCompound(ModInfo.MOD_ID, this));
}
public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter) {
public void ignite(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter) {
if (!worldIn.isRemote) {
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), igniter);
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), igniter);
worldIn.spawnEntity(entitynukeprimed);
// worldIn.playSoundAtEntity(entitynukeprimed, "game.tnt.primed",
// 1.0F, 1.0F);
worldIn.playSound((EntityPlayer) null, entitynukeprimed.posX, entitynukeprimed.posY, entitynukeprimed.posZ,
SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
@ -73,8 +75,8 @@ public class BlockNuke extends BaseBlock {
public void onExplosionDestroy(World worldIn, BlockPos pos, Explosion explosionIn) {
if (!worldIn.isRemote) {
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
entitynukeprimed.fuse = worldIn.rand.nextInt(entitynukeprimed.fuse / 4) + entitynukeprimed.fuse / 8;
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
entitynukeprimed.setFuse(worldIn.rand.nextInt(EntityNukePrimed.fuseTime / 4) + EntityNukePrimed.fuseTime / 8);
worldIn.spawnEntity(entitynukeprimed);
}
}
@ -83,10 +85,12 @@ public class BlockNuke extends BaseBlock {
public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (!worldIn.isRemote && entityIn instanceof EntityArrow) {
EntityArrow entityarrow = (EntityArrow) entityIn;
EntityLivingBase shooter = null;
if (entityarrow.shootingEntity instanceof EntityLivingBase) {
shooter = (EntityLivingBase) entityarrow.shootingEntity;
}
if (entityarrow.isBurning()) {
this.explode(worldIn, pos, state, entityarrow.shootingEntity instanceof EntityLivingBase
? (EntityLivingBase) entityarrow.shootingEntity : null);
ignite(worldIn, pos, state, shooter);
worldIn.setBlockToAir(pos);
}
}
@ -96,25 +100,22 @@ public class BlockNuke extends BaseBlock {
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state);
if (worldIn.isBlockPowered(pos)) {
this.explode(worldIn, pos, state, null);
ignite(worldIn, pos, state, null);
worldIn.setBlockToAir(pos);
}
}
/**
* Called when a neighboring block changes.
*/
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_) {
if (worldIn.isBlockPowered(pos)) {
this.explode(worldIn, pos, state, null);
ignite(worldIn, pos, state, null);
worldIn.setBlockToAir(pos);
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
return false;
}

View file

@ -37,7 +37,6 @@ public class ContainerDestructoPack extends RebornContainer {
private EntityPlayer player;
private Inventory inv;
@SuppressWarnings("deprecation")
public ContainerDestructoPack(EntityPlayer player) {
super(null);
this.player = player;

View file

@ -51,8 +51,8 @@ public class RenderNukePrimed extends Render<EntityNukePrimed> {
BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
GlStateManager.pushMatrix();
GlStateManager.translate((float) x, (float) y + 0.5F, (float) z);
if ((float) entity.fuse - partialTicks + 1.0F < 10.0F) {
float f = 1.0F - ((float) entity.fuse - partialTicks + 1.0F) / 10.0F;
if ((float) entity.getFuse() - partialTicks + 1.0F < 10.0F) {
float f = 1.0F - ((float) entity.getFuse() - partialTicks + 1.0F) / 10.0F;
f = MathHelper.clamp(f, 0.0F, 1.0F);
f = f * f;
f = f * f;
@ -64,7 +64,7 @@ public class RenderNukePrimed extends Render<EntityNukePrimed> {
blockrendererdispatcher.renderBlockBrightness(ModBlocks.NUKE.getDefaultState(),
entity.getBrightness());
GlStateManager.translate(0.0F, 0.0F, 1.0F);
if (entity.fuse / 5 % 2 == 0) {
if (entity.getFuse() / 5 % 2 == 0) {
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(770, 772);

View file

@ -41,8 +41,8 @@ import techreborn.lib.ModInfo;
@RebornRegistry(modID = ModInfo.MOD_ID)
public class EntityNukePrimed extends EntityTNTPrimed {
@ConfigRegistry(config = "misc", category = "nuke", key = "fuse", comment = "Nuke fuse time (ticks)")
public static int fuse = 400;
@ConfigRegistry(config = "misc", category = "nuke", key = "fusetime", comment = "Nuke fuse time (ticks)")
public static int fuseTime = 400;
@ConfigRegistry(config = "misc", category = "nuke", key = "radius", comment = "Nuke explision radius")
public static int radius = 40;
@ -52,48 +52,54 @@ public class EntityNukePrimed extends EntityTNTPrimed {
public EntityNukePrimed(World world) {
super(world);
setFuse(EntityNukePrimed.fuseTime);
}
public EntityNukePrimed(World world, double x, double y, double z, EntityLivingBase tntPlacedBy) {
super(world, x, y, z, tntPlacedBy);
setFuse(EntityNukePrimed.fuseTime);
}
@Override
public void onUpdate() {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
this.motionY -= 0.03999999910593033D;
if (!this.hasNoGravity()) {
this.motionY -= 0.03999999910593033D;
}
this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
this.motionX *= 0.9800000190734863D;
this.motionY *= 0.9800000190734863D;
this.motionZ *= 0.9800000190734863D;
if (this.onGround) {
this.motionX *= 0.699999988079071D;
this.motionZ *= 0.699999988079071D;
this.motionY *= -0.5D;
}
if (this.fuse-- <= 0) {
setFuse(getFuse() - 1);
if (getFuse() <= 0) {
this.setDead();
if (!this.world.isRemote) {
this.explodeNuke();
explodeNuke();
}
} else {
this.handleWaterMovement();
this.world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, this.posX, this.posY + 0.5D, this.posZ, 0.0D,
0.0D, 0.0D, new int[0]);
this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
}
}
public void explodeNuke() {
if(!enabled){
if (!enabled) {
return;
}
RebornExplosion nukeExplosion = new RebornExplosion(new BlockPos(this.posX, this.posY, this.posZ), world,
radius);
RebornExplosion nukeExplosion = new RebornExplosion(new BlockPos(posX, posY, posZ), world, radius);
nukeExplosion.setLivingBase(getTntPlacedBy());
nukeExplosion.explode();
}
}