From 2b9da4a0f048300e14bf359b705a4c04c05064ba Mon Sep 17 00:00:00 2001 From: Jordan Byrne Date: Sun, 24 Dec 2017 21:45:03 +1000 Subject: + Added the Tesla Tower for base defence. --- .../renderer/RenderMiningExplosivesPrimed.java | 11 +- .../core/client/renderer/RenderPlasmaBolt.java | 165 +++++++++++++++++++++ src/Java/gtPlusPlus/core/common/CommonProxy.java | 5 +- .../core/entity/EntityTeslaTowerLightning.java | 133 +++++++++++++++++ .../core/entity/InternalEntityRegistry.java | 24 ++- .../gtPlusPlus/core/handler/COMPAT_HANDLER.java | 1 + src/Java/gtPlusPlus/core/material/Material.java | 106 +++++++------ src/Java/gtPlusPlus/core/proxy/ClientProxy.java | 6 +- .../gtPlusPlus/core/util/entity/EntityUtils.java | 37 ++++- 9 files changed, 434 insertions(+), 54 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/client/renderer/RenderPlasmaBolt.java create mode 100644 src/Java/gtPlusPlus/core/entity/EntityTeslaTowerLightning.java (limited to 'src/Java/gtPlusPlus/core') diff --git a/src/Java/gtPlusPlus/core/client/renderer/RenderMiningExplosivesPrimed.java b/src/Java/gtPlusPlus/core/client/renderer/RenderMiningExplosivesPrimed.java index 42071428a7..359229adaa 100644 --- a/src/Java/gtPlusPlus/core/client/renderer/RenderMiningExplosivesPrimed.java +++ b/src/Java/gtPlusPlus/core/client/renderer/RenderMiningExplosivesPrimed.java @@ -6,6 +6,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.entity.EntityPrimedMiningExplosive; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.texture.TextureMap; @@ -28,7 +29,7 @@ public class RenderMiningExplosivesPrimed extends Render { * (Render= 0; --i) { + adouble[i] = d3; + adouble1[i] = d4; + d3 += (double) (random.nextInt(11) - 5); + d4 += (double) (random.nextInt(11) - 5); + } + + for (int k1 = 0; k1 < 4; ++k1) { + Random random1 = CSPRNG.generate(new Random(p_76986_1_.boltVertex)); + + for (int j = 0; j < 3; ++j) { + int k = 7; + int l = 0; + + if (j > 0) { + k = 7 - j; + } + + if (j > 0) { + l = k - 2; + } + + double d5 = adouble[k] - d3; + double d6 = adouble1[k] - d4; + + for (int i1 = k; i1 >= l; --i1) { + double d7 = d5; + double d8 = d6; + + if (j == 0) { + d5 += (double) (random1.nextInt(11) - 5); + d6 += (double) (random1.nextInt(11) - 5); + } + else { + d5 += (double) (random1.nextInt(31) - 15); + d6 += (double) (random1.nextInt(31) - 15); + } + + tessellator.startDrawing(5); + float f2 = 0.5F; + tessellator.setColorRGBA_F(0.9F * f2, 0.9F * f2, 1.0F * f2, 0.3F); + double d9 = 0.1D + (double) k1 * 0.2D; + + if (j == 0) { + d9 *= (double) i1 * 0.1D + 1.0D; + } + + double d10 = 0.1D + (double) k1 * 0.2D; + + if (j == 0) { + d10 *= (double) (i1 - 1) * 0.1D + 1.0D; + } + + for (int j1 = 0; j1 < 5; ++j1) { + double d11 = p_76986_2_ + 0.5D - d9; + double d12 = p_76986_6_ + 0.5D - d9; + + if (j1 == 1 || j1 == 2) { + d11 += d9 * 2.0D; + } + + if (j1 == 2 || j1 == 3) { + d12 += d9 * 2.0D; + } + + double d13 = p_76986_2_ + 0.5D - d10; + double d14 = p_76986_6_ + 0.5D - d10; + + if (j1 == 1 || j1 == 2) { + d13 += d10 * 2.0D; + } + + if (j1 == 2 || j1 == 3) { + d14 += d10 * 2.0D; + } + + tessellator.addVertex(d13 + d5, p_76986_4_ + (double) (i1 * 16), d14 + d6); + tessellator.addVertex(d11 + d7, p_76986_4_ + (double) ((i1 + 1) * 16), d12 + d8); + } + + tessellator.draw(); + } + } + } + + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called + * unless you call Render.bindEntityTexture. + */ + protected ResourceLocation getEntityTexture(EntityTeslaTowerLightning p_110775_1_) { + return null; + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called + * unless you call Render.bindEntityTexture. + */ + protected ResourceLocation getEntityTexture(Entity p_110775_1_) { + return this.getEntityTexture((EntityTeslaTowerLightning) p_110775_1_); + } + + /** + * Actually renders the given argument. This is a synthetic bridge method, + * always casting down its argument and then handing it off to a worker + * function which does the actual work. In all probabilty, the class Render + * is generic (Render= 0) + { + if (this.worldObj.isRemote) + { + this.worldObj.lastLightningBolt = 2; + } + else + { + double d0 = 3.0D; + List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.getBoundingBox(this.posX - d0, this.posY - d0, this.posZ - d0, this.posX + d0, this.posY + 6.0D + d0, this.posZ + d0)); + + for (int l = 0; l < list.size(); ++l) + { + Entity entity = (Entity)list.get(l); + //if (!net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(entity, this)) + EntityUtils.doFireDamage(entity, 5); + EntityUtils.doDamage(entity, new DamageTeslaTower(entity), 20); + } + } + } + } + + protected void entityInit() {} + + /** + * (abstract) Protected helper method to read subclass entity data from NBT. + */ + protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {} + + /** + * (abstract) Protected helper method to write subclass entity data to NBT. + */ + protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {} +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/entity/InternalEntityRegistry.java b/src/Java/gtPlusPlus/core/entity/InternalEntityRegistry.java index 5233c876e9..a33596b76a 100644 --- a/src/Java/gtPlusPlus/core/entity/InternalEntityRegistry.java +++ b/src/Java/gtPlusPlus/core/entity/InternalEntityRegistry.java @@ -15,14 +15,34 @@ public class InternalEntityRegistry { public static void registerEntities(){ Logger.INFO("Registering GT++ Entities."); - //EntityRegistry.registerModEntity(EntityMiningChargePrimed.class, "MiningCharge", 3, Main.modInstance, 64, 20, true); + + EntityRegistry.registerGlobalEntityID(EntityPrimedMiningExplosive.class, "MiningCharge", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntityPrimedMiningExplosive.class, "MiningCharge", mEntityID++, GTplusplus.instance, 64, 20, true); + + + EntityRegistry.registerGlobalEntityID(EntitySulfuricAcidPotion.class, "throwablePotionSulfuric", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntitySulfuricAcidPotion.class, "throwablePotionSulfuric", mEntityID++, GTplusplus.instance, 64, 20, true); + + + EntityRegistry.registerGlobalEntityID(EntityHydrofluoricAcidPotion.class, "throwablePotionHydrofluoric", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntityHydrofluoricAcidPotion.class, "throwablePotionHydrofluoric", mEntityID++, GTplusplus.instance, 64, 20, true); + + + EntityRegistry.registerGlobalEntityID(EntityToxinballSmall.class, "toxinBall", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntityToxinballSmall.class, "toxinBall", mEntityID++, GTplusplus.instance, 64, 20, true); + + + EntityRegistry.registerGlobalEntityID(EntityStaballoyConstruct.class, "constructStaballoy", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntityStaballoyConstruct.class, "constructStaballoy", mEntityID++, GTplusplus.instance, 64, 20, true); + + + EntityRegistry.registerGlobalEntityID(EntitySickBlaze.class, "sickBlaze", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntitySickBlaze.class, "sickBlaze", mEntityID++, GTplusplus.instance, 64, 20, true); - + + + EntityRegistry.registerGlobalEntityID(EntityTeslaTowerLightning.class, "plasmaBolt", EntityRegistry.findGlobalUniqueEntityId()); + EntityRegistry.registerModEntity(EntityTeslaTowerLightning.class, "plasmaBolt", mEntityID++, GTplusplus.instance, 64, 5, true); + } } diff --git a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java index 14f281b2e9..c6aff47c5b 100644 --- a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java +++ b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java @@ -101,6 +101,7 @@ public class COMPAT_HANDLER { GregtechIndustrialCuttingFactory.run(); GregtechMiniRaFusion.run(); GregtechComponentAssembler.run(); + GregtechTeslaTower.run(); //New Horizons Content NewHorizonsAccelerator.run(); diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index b04ce3baac..c8637f5aeb 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -761,66 +761,86 @@ public class Material { final public int calculateMeltingPoint(){ - int meltingPoint = 0; - for (MaterialStack part : this.vMaterialInput){ - if (part != null){ - int incrementor = part.getStackMaterial().getMeltingPointC(); - meltingPoint += incrementor; - Logger.WARNING("Melting Point for "+this.getLocalizedName()+" increased to "+ incrementor); - } - else { - Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + try { + int meltingPoint = 0; + for (MaterialStack part : this.vMaterialInput){ + if (part != null){ + int incrementor = part.getStackMaterial().getMeltingPointC(); + meltingPoint += incrementor; + Logger.WARNING("Melting Point for "+this.getLocalizedName()+" increased to "+ incrementor); + } + else { + Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + } } + int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); + Logger.WARNING("Dividing "+meltingPoint+" / "+divisor+" to get average melting point."); + meltingPoint = (meltingPoint/divisor); + return meltingPoint; + } + catch (Throwable r){ + return 500; } - int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); - Logger.WARNING("Dividing "+meltingPoint+" / "+divisor+" to get average melting point."); - meltingPoint = (meltingPoint/divisor); - return meltingPoint; } final public int calculateBoilingPoint(){ - int boilingPoint = 0; - for (MaterialStack part : this.vMaterialInput){ - if (part != null){ - boilingPoint += part.getStackMaterial().getBoilingPointC(); - } - else { - Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + try { + int boilingPoint = 0; + for (MaterialStack part : this.vMaterialInput){ + if (part != null){ + boilingPoint += part.getStackMaterial().getBoilingPointC(); + } + else { + Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + } } + int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); + boilingPoint = (boilingPoint/divisor); + return boilingPoint; + } + catch (Throwable r){ + return 2500; } - int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); - boilingPoint = (boilingPoint/divisor); - return boilingPoint; } final public long calculateProtons(){ - long protonCount = 0; - for (MaterialStack part : this.vMaterialInput){ - if (part != null){ - protonCount += (part.getStackMaterial().getProtons()); - } - else { - Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + try { + long protonCount = 0; + for (MaterialStack part : this.vMaterialInput){ + if (part != null){ + protonCount += (part.getStackMaterial().getProtons()); + } + else { + Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + } } + int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); + protonCount = (protonCount/divisor); + return protonCount; + } + catch (Throwable r){ + return 50; } - int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); - protonCount = (protonCount/divisor); - return protonCount; } final public long calculateNeutrons(){ - long neutronCount = 0; - for (MaterialStack part : this.vMaterialInput){ - if (part != null){ - neutronCount += (part.getStackMaterial().getNeutrons()); - } - else { - Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + try { + long neutronCount = 0; + for (MaterialStack part : this.vMaterialInput){ + if (part != null){ + neutronCount += (part.getStackMaterial().getNeutrons()); + } + else { + Logger.MATERIALS(this.getLocalizedName()+" has a really invalid composition."); + } } + int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); + neutronCount = (neutronCount/divisor); + return neutronCount; + } + catch (Throwable r){ + return 75; } - int divisor = (this.vMaterialInput.size()>0 ? this.vMaterialInput.size() : 1); - neutronCount = (neutronCount/divisor); - return neutronCount; } diff --git a/src/Java/gtPlusPlus/core/proxy/ClientProxy.java b/src/Java/gtPlusPlus/core/proxy/ClientProxy.java index 712df63e67..f20c3ef91a 100644 --- a/src/Java/gtPlusPlus/core/proxy/ClientProxy.java +++ b/src/Java/gtPlusPlus/core/proxy/ClientProxy.java @@ -17,8 +17,10 @@ import gtPlusPlus.core.client.renderer.*; import gtPlusPlus.core.common.CommonProxy; import gtPlusPlus.core.common.compat.COMPAT_PlayerAPI; import gtPlusPlus.core.entity.EntityPrimedMiningExplosive; +import gtPlusPlus.core.entity.EntityTeslaTowerLightning; import gtPlusPlus.core.entity.monster.EntitySickBlaze; import gtPlusPlus.core.entity.monster.EntityStaballoyConstruct; +import gtPlusPlus.core.entity.projectile.EntityHydrofluoricAcidPotion; import gtPlusPlus.core.entity.projectile.EntitySulfuricAcidPotion; import gtPlusPlus.core.entity.projectile.EntityToxinballSmall; import gtPlusPlus.core.handler.render.FirepitRender; @@ -30,6 +32,7 @@ import gtPlusPlus.core.util.particles.EntityParticleFXMysterious; import gtPlusPlus.xmod.gregtech.common.render.GTPP_CapeRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.entity.RenderLightningBolt; import net.minecraft.client.renderer.entity.RenderSnowball; import net.minecraft.entity.Entity; @@ -96,7 +99,8 @@ public class ClientProxy extends CommonProxy implements Runnable{ RenderingRegistry.registerEntityRenderingHandler(EntityToxinballSmall.class, new RenderToxinball(1F)); Logger.INFO("Registering Custom Renderer for Sulfuric potion."); RenderingRegistry.registerEntityRenderingHandler(EntitySulfuricAcidPotion.class, new RenderSnowball(ModItems.itemSulfuricPotion)); - + RenderingRegistry.registerEntityRenderingHandler(EntityHydrofluoricAcidPotion.class, new RenderSnowball(ModItems.itemHydrofluoricPotion)); + RenderingRegistry.registerEntityRenderingHandler(EntityTeslaTowerLightning.class, new RenderLightningBolt()); //ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBloodSteelChest.class, new BloodSteelChestRenderer()); //MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.tutChest), new ItemRenderBloodSteelChest()); diff --git a/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java b/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java index 60b05a308f..90b4b2b22c 100644 --- a/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java +++ b/src/Java/gtPlusPlus/core/util/entity/EntityUtils.java @@ -1,12 +1,17 @@ package gtPlusPlus.core.util.entity; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import cpw.mods.fml.common.registry.EntityRegistry; import gregtech.api.util.GT_Utility; import gtPlusPlus.core.util.array.BlockPos; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import ic2.core.IC2Potion; import ic2.core.item.armor.ItemArmorHazmat; import net.minecraft.block.Block; import net.minecraft.entity.*; +import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; @@ -36,7 +41,7 @@ public class EntityUtils { final int blockZ = MathHelper.floor_double(parEntity.posZ); return parEntity.worldObj.getBlock(blockX, blockY, blockZ); } - + public static BlockPos findBlockPosUnderEntity(final Entity parEntity){ final int blockX = MathHelper.floor_double(parEntity.posX); final int blockY = MathHelper.floor_double(parEntity.boundingBox.minY)-1; @@ -72,4 +77,34 @@ public class EntityUtils { return false; } + + /** + * Static Version of the method used in {@code doFireDamage(entity, int)} to save memory. + */ + private static volatile Method dealFireDamage; + + /** + * Reflective Call to do Fire Damage to an entity (Does not set entity on fire though) + */ + public static boolean doFireDamage(Entity entity, int amount){ + if (dealFireDamage == null){ + try { + dealFireDamage = Entity.class.getDeclaredMethod("dealFireDamage", int.class); + dealFireDamage.setAccessible(true); + } + catch (NoSuchMethodException | SecurityException e) {} + } + else { + try { + dealFireDamage.invoke(entity, amount); + } + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {} + } + return false; + } + + public static void doDamage(Entity entity, DamageSource dmg, int i) { + entity.attackEntityFrom(dmg, i); + } + } -- cgit