Use static fuse in static way. cherry-pick from: 8cac9a9315

This commit is contained in:
drcrazy 2018-09-07 11:31:38 +01:00 committed by Modmuss50
parent f01d75404c
commit c56da8cf18
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
4 changed files with 38 additions and 32 deletions

View file

@ -33,17 +33,19 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.World; import net.minecraft.world.World;
import prospector.shootingstar.ShootingStar; import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound; import prospector.shootingstar.model.ModelCompound;
import reborncore.common.BaseBlock; import reborncore.common.BaseBlock;
import techreborn.utils.TechRebornCreativeTab;
import techreborn.entities.EntityNukePrimed; import techreborn.entities.EntityNukePrimed;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import techreborn.utils.TechRebornCreativeTab;
/** /**
* Created by Mark on 13/03/2016. * Created by Mark on 13/03/2016.
@ -59,13 +61,13 @@ public class BlockNuke extends BaseBlock {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this)); ShootingStar.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) { if (!worldIn.isRemote) {
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F), 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.spawnEntity(entitynukeprimed);
// worldIn.playSoundAtEntity(entitynukeprimed, "game.tnt.primed", worldIn.playSound((EntityPlayer) null, entitynukeprimed.posX, entitynukeprimed.posY, entitynukeprimed.posZ,
// 1.0F, 1.0F); SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
} }
} }
@ -73,8 +75,8 @@ public class BlockNuke extends BaseBlock {
public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) { public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) {
if (!worldIn.isRemote) { if (!worldIn.isRemote) {
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F), EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy()); (double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
entitynukeprimed.fuse = worldIn.rand.nextInt(entitynukeprimed.fuse / 4) + entitynukeprimed.fuse / 8; entitynukeprimed.setFuse(worldIn.rand.nextInt(EntityNukePrimed.fuseTime / 4) + EntityNukePrimed.fuseTime / 8);
worldIn.spawnEntity(entitynukeprimed); worldIn.spawnEntity(entitynukeprimed);
} }
} }
@ -83,10 +85,12 @@ public class BlockNuke extends BaseBlock {
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (!worldIn.isRemote && entityIn instanceof EntityArrow) { if (!worldIn.isRemote && entityIn instanceof EntityArrow) {
EntityArrow entityarrow = (EntityArrow) entityIn; EntityArrow entityarrow = (EntityArrow) entityIn;
EntityLivingBase shooter = null;
if (entityarrow.shootingEntity instanceof EntityLivingBase) {
shooter = (EntityLivingBase) entityarrow.shootingEntity;
}
if (entityarrow.isBurning()) { if (entityarrow.isBurning()) {
this.explode(worldIn, pos, state, entityarrow.shootingEntity instanceof EntityLivingBase ignite(worldIn, pos, state, shooter);
? (EntityLivingBase) entityarrow.shootingEntity : null);
worldIn.setBlockToAir(pos); worldIn.setBlockToAir(pos);
} }
} }
@ -96,25 +100,22 @@ public class BlockNuke extends BaseBlock {
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state); super.onBlockAdded(worldIn, pos, state);
if (worldIn.isBlockPowered(pos)) { if (worldIn.isBlockPowered(pos)) {
this.explode(worldIn, pos, state, null); ignite(worldIn, pos, state, null);
worldIn.setBlockToAir(pos); worldIn.setBlockToAir(pos);
} }
} }
/**
* Called when a neighboring block changes.
*/
@Override @Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_) { public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_) {
if (worldIn.isBlockPowered(pos)) { if (worldIn.isBlockPowered(pos)) {
this.explode(worldIn, pos, state, null); ignite(worldIn, pos, state, null);
worldIn.setBlockToAir(pos); worldIn.setBlockToAir(pos);
} }
} }
@Override @Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, 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; return false;
} }

View file

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

View file

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

View file

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