From ddca005edbe955e196ce7de204b60eaff8d9df23 Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 19 Jan 2022 16:41:19 +0100 Subject: [PATCH] siege mode lasers, pew pew --- .../hbm/entity/mob/siege/EntitySiegeUFO.java | 34 +++++ .../entity/mob/siege/EntitySiegeZombie.java | 5 + .../entity/projectile/EntitySiegeLaser.java | 132 ++++++++++++++++ .../com/hbm/handler/SiegeOrchestrator.java | 2 + .../com/hbm/inventory/fluid/FluidType.java | 4 - src/main/java/com/hbm/main/ClientProxy.java | 1 + src/main/java/com/hbm/main/MainRegistry.java | 1 + .../entity/projectile/RenderSiegeLaser.java | 144 ++++++++++++++++++ 8 files changed, 319 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/hbm/entity/projectile/EntitySiegeLaser.java create mode 100644 src/main/java/com/hbm/render/entity/projectile/RenderSiegeLaser.java diff --git a/src/main/java/com/hbm/entity/mob/siege/EntitySiegeUFO.java b/src/main/java/com/hbm/entity/mob/siege/EntitySiegeUFO.java index 9af91fdaa..0aaa315b7 100644 --- a/src/main/java/com/hbm/entity/mob/siege/EntitySiegeUFO.java +++ b/src/main/java/com/hbm/entity/mob/siege/EntitySiegeUFO.java @@ -2,6 +2,8 @@ package com.hbm.entity.mob.siege; import java.util.List; +import com.hbm.handler.SiegeOrchestrator; + import api.hbm.entity.IRadiationImmune; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityFlying; @@ -14,6 +16,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSource; import net.minecraft.util.Vec3; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; @@ -46,6 +50,36 @@ public class EntitySiegeUFO extends EntityFlying implements IMob, IRadiationImmu this.setHealth(this.getMaxHealth()); } + @Override + public boolean attackEntityFrom(DamageSource source, float damage) { + + if(this.isEntityInvulnerable()) + return false; + + if(SiegeOrchestrator.isSiegeMob(source.getEntity())) + return false; + + SiegeTier tier = this.getTier(); + + if(tier.fireProof && source.isFireDamage()) + return false; + + //noFF can't be harmed by other mobs + if(tier.noFriendlyFire && source instanceof EntityDamageSource && !(((EntityDamageSource) source).getEntity() instanceof EntityPlayer)) + return false; + + damage -= tier.dt; + + if(damage < 0) { + worldObj.playSoundAtEntity(this, "random.break", 5F, 1.0F + rand.nextFloat() * 0.5F); + return false; + } + + damage *= (1F - tier.dr); + + return super.attackEntityFrom(source, damage); + } + public SiegeTier getTier() { SiegeTier tier = SiegeTier.tiers[this.getDataWatcher().getWatchableObjectInt(12)]; return tier != null ? tier : SiegeTier.CLAY; diff --git a/src/main/java/com/hbm/entity/mob/siege/EntitySiegeZombie.java b/src/main/java/com/hbm/entity/mob/siege/EntitySiegeZombie.java index 6f5b575fe..b98b78d3b 100644 --- a/src/main/java/com/hbm/entity/mob/siege/EntitySiegeZombie.java +++ b/src/main/java/com/hbm/entity/mob/siege/EntitySiegeZombie.java @@ -1,5 +1,7 @@ package com.hbm.entity.mob.siege; +import com.hbm.handler.SiegeOrchestrator; + import api.hbm.entity.IRadiationImmune; import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.SharedMonsterAttributes; @@ -42,6 +44,9 @@ public class EntitySiegeZombie extends EntityMob implements IRadiationImmune { if(this.isEntityInvulnerable()) return false; + if(SiegeOrchestrator.isSiegeMob(source.getEntity())) + return false; + SiegeTier tier = this.getTier(); if(tier.fireProof && source.isFireDamage()) diff --git a/src/main/java/com/hbm/entity/projectile/EntitySiegeLaser.java b/src/main/java/com/hbm/entity/projectile/EntitySiegeLaser.java new file mode 100644 index 000000000..2af63e100 --- /dev/null +++ b/src/main/java/com/hbm/entity/projectile/EntitySiegeLaser.java @@ -0,0 +1,132 @@ +package com.hbm.entity.projectile; + +import com.hbm.lib.ModDamageSource; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSourceIndirect; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.MovingObjectPosition.MovingObjectType; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class EntitySiegeLaser extends EntityThrowable { + + private float damage = 2; + private float explosive = 0F; + private float breakChance = 0F; + private boolean incendiary = false; + + public EntitySiegeLaser(World world) { + super(world); + } + + public EntitySiegeLaser(World world, EntityLivingBase entity) { + super(world, entity); + } + + public EntitySiegeLaser(World world, double x, double y, double z) { + super(world, x, y, z); + } + + @Override + protected void entityInit() { + this.getDataWatcher().addObject(12, (int) 0xffffff); + } + + public EntitySiegeLaser setDamage(float f) { + this.damage = f; + return this; + } + + public EntitySiegeLaser setExplosive(float f) { + this.explosive = f; + return this; + } + + public EntitySiegeLaser setBreakChance(float f) { + this.breakChance = f; + return this; + } + + public EntitySiegeLaser setIncendiary() { + this.incendiary = true; + return this; + } + + public EntitySiegeLaser setColor(int color) { + this.getDataWatcher().updateObject(12, color); + return this; + } + + public int getColor() { + return this.getDataWatcher().getWatchableObjectInt(12); + } + + @Override + protected void onImpact(MovingObjectPosition mop) { + + if(mop.typeOfHit == MovingObjectType.ENTITY) { + DamageSource dmg; + + if(this.getThrower() != null) + dmg = new EntityDamageSourceIndirect(ModDamageSource.s_laser, this, this.getThrower()); + else + dmg = new DamageSource(ModDamageSource.s_laser); + + mop.entityHit.attackEntityFrom(dmg, this.damage); + + if(this.incendiary) + mop.entityHit.setFire(3); + + if(this.explosive > 0) + this.worldObj.newExplosion(this, mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord, this.explosive, false, this.incendiary); + + } else if(mop.typeOfHit == MovingObjectType.BLOCK) { + + if(this.explosive > 0) { + this.worldObj.newExplosion(this, mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord, this.explosive, false, this.incendiary); + + } else if(this.incendiary) { + ForgeDirection dir = ForgeDirection.getOrientation(mop.sideHit); + int x = mop.blockX + dir.offsetX; + int y = mop.blockY + dir.offsetY; + int z = mop.blockZ + dir.offsetZ; + + if(this.worldObj.getBlock(x, y, z).isReplaceable(this.worldObj, x, y, z)) { + this.worldObj.setBlock(x, y, z, Blocks.fire); + } + } + + if(this.rand.nextFloat() < this.breakChance) { + this.worldObj.func_147480_a(mop.blockX, mop.blockY, mop.blockZ, false); + } + } + } + + @Override + public void writeEntityToNBT(NBTTagCompound nbt) { + super.writeEntityToNBT(nbt); + nbt.setFloat("damage", this.damage); + nbt.setFloat("explosive", this.explosive); + nbt.setFloat("breakChance", this.breakChance); + nbt.setBoolean("incendiary", this.incendiary); + nbt.setInteger("color", this.getColor()); + } + + @Override + public void readEntityFromNBT(NBTTagCompound nbt) { + super.readEntityFromNBT(nbt); + this.damage = nbt.getFloat("damage"); + this.explosive = nbt.getFloat("explosive"); + this.breakChance = nbt.getFloat("breakChance"); + this.incendiary = nbt.getBoolean("incendiary"); + this.setColor(nbt.getInteger("color")); + + } +} diff --git a/src/main/java/com/hbm/handler/SiegeOrchestrator.java b/src/main/java/com/hbm/handler/SiegeOrchestrator.java index b17b03fb6..d0f2f0c1e 100644 --- a/src/main/java/com/hbm/handler/SiegeOrchestrator.java +++ b/src/main/java/com/hbm/handler/SiegeOrchestrator.java @@ -125,6 +125,7 @@ public class SiegeOrchestrator { public static final String KEY_WAVE_DURATION = "siegeWaveDuration"; public static final String KEY_PAUSE_DURATION = "siegePauseDuration"; public static final String KEY_ENABLE_DROPS = "siegeEnableDropships"; + public static final String KEY_ENABLE_SPAWNS = "siegeEnableGroundSpawning"; public static final String KEY_ENABLE_BASES = "siegeEnableBases"; public static final String KEY_ENABLE_MISSILES = "siegeEnableMissiles"; public static final String KEY_SPAWN_DIST = "siegeSpawnDist"; @@ -145,6 +146,7 @@ public class SiegeOrchestrator { rules.setOrCreateGameRule(KEY_WAVE_DURATION, "" + (20 * 60 * 20)); rules.setOrCreateGameRule(KEY_PAUSE_DURATION, "" + (10 * 60 * 20)); rules.setOrCreateGameRule(KEY_ENABLE_DROPS, "true"); + rules.setOrCreateGameRule(KEY_ENABLE_SPAWNS, "false"); rules.setOrCreateGameRule(KEY_ENABLE_BASES, "true"); rules.setOrCreateGameRule(KEY_ENABLE_MISSILES, "true"); rules.setOrCreateGameRule(KEY_SPAWN_DIST, "64"); diff --git a/src/main/java/com/hbm/inventory/fluid/FluidType.java b/src/main/java/com/hbm/inventory/fluid/FluidType.java index 041857213..52d5de9b6 100644 --- a/src/main/java/com/hbm/inventory/fluid/FluidType.java +++ b/src/main/java/com/hbm/inventory/fluid/FluidType.java @@ -152,10 +152,6 @@ public class FluidType { //shitty wrapper delegates, go! //only used for compatibility purposes, these will be removed soon //don't use these, dumbfuck - /*@Deprecated //reason: use the fucking registry you dumbass this isn't a fucking enum anymore, we don't sell lists of all our instances here - public static FluidType[] values() { - return Fluids.metaOrder.toArray(new FluidType[0]); - }*/ @Deprecated //reason: not an enum, asshole, use the registry public static FluidType getEnum(int i) { return Fluids.fromID(i); diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index 1cd4c61fc..a006cf2c3 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -442,6 +442,7 @@ public class ClientProxy extends ServerProxy { RenderingRegistry.registerEntityRenderingHandler(EntitySparkBeam.class, new RenderBeam4()); RenderingRegistry.registerEntityRenderingHandler(EntityExplosiveBeam.class, new RenderBeam5()); RenderingRegistry.registerEntityRenderingHandler(EntityModBeam.class, new RenderBeam6()); + RenderingRegistry.registerEntityRenderingHandler(EntitySiegeLaser.class, new RenderSiegeLaser()); RenderingRegistry.registerEntityRenderingHandler(EntityLN2.class, new RenderLN2(ModItems.energy_ball)); RenderingRegistry.registerEntityRenderingHandler(EntityLaser.class, new RenderLaser()); RenderingRegistry.registerEntityRenderingHandler(EntityBombletTheta.class, new RenderBombletTheta()); diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index 2f8116826..f01ab322f 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -478,6 +478,7 @@ public class MainRegistry { EntityRegistry.registerModEntity(EntityZirnoxDebris.class, "entity_zirnox_debris", 161, this, 1000, 1, true); EntityRegistry.registerModEntity(EntityGhost.class, "entity_ntm_ghost", 162, this, 1000, 1, true); EntityRegistry.registerModEntity(EntityGrenadeDynamite.class, "entity_grenade_dynamite", 163, this, 250, 1, true); + EntityRegistry.registerModEntity(EntitySiegeLaser.class, "entity_ntm_siege_laser", 164, this, 1000, 1, true); EntityRegistry.registerGlobalEntityID(EntityNuclearCreeper.class, "entity_mob_nuclear_creeper", EntityRegistry.findGlobalUniqueEntityId(), 0x204131, 0x75CE00); EntityRegistry.registerGlobalEntityID(EntityTaintedCreeper.class, "entity_mob_tainted_creeper", EntityRegistry.findGlobalUniqueEntityId(), 0x813b9b, 0xd71fdd); diff --git a/src/main/java/com/hbm/render/entity/projectile/RenderSiegeLaser.java b/src/main/java/com/hbm/render/entity/projectile/RenderSiegeLaser.java new file mode 100644 index 000000000..1b9d2a8ac --- /dev/null +++ b/src/main/java/com/hbm/render/entity/projectile/RenderSiegeLaser.java @@ -0,0 +1,144 @@ +package com.hbm.render.entity.projectile; + +import java.util.Random; + +import org.lwjgl.opengl.GL11; + +import com.hbm.entity.projectile.EntitySiegeLaser; +import com.hbm.handler.BulletConfiguration; +import com.hbm.main.ResourceManager; + +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; + +public class RenderSiegeLaser extends Render { + + @Override + public void doRender(Entity laser, double x, double y, double z, float f0, float f1) { + + GL11.glPushMatrix(); + GL11.glTranslatef((float) x, (float) y, (float) z); + GL11.glRotatef(laser.prevRotationYaw + (laser.rotationYaw - laser.prevRotationYaw) * f1 - 90.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(laser.prevRotationPitch + (laser.rotationPitch - laser.prevRotationPitch) * f1 + 180, 0.0F, 0.0F, 1.0F); + + this.renderDart((EntitySiegeLaser) laser); + + GL11.glPopMatrix(); + } + + @Override + protected ResourceLocation getEntityTexture(Entity entity) { + return ResourceManager.universal; + } + + private void renderDart(EntitySiegeLaser laser) { + + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_CULL_FACE); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + GL11.glDepthMask(false); + + GL11.glScalef(1F / 4F, 1F / 8F, 1F / 8F); + GL11.glScalef(-1, 1, 1); + + GL11.glScalef(2, 2, 2); + + int color = laser.getColor(); + + Tessellator tess = Tessellator.instance; + + // front + tess.startDrawing(4); + tess.setColorOpaque_I(color); + tess.addVertex(6, 0, 0); + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, -1, -1); + tess.addVertex(3, 1, -1); + + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, -1, 1); + tess.setColorOpaque_I(color); + tess.addVertex(6, 0, 0); + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, 1, 1); + + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, -1, -1); + tess.setColorOpaque_I(color); + tess.addVertex(6, 0, 0); + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, -1, 1); + + tess.setColorOpaque_I(color); + tess.addVertex(6, 0, 0); + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, 1, -1); + tess.setColorRGBA_I(color, 0); + tess.addVertex(3, 1, 1); + + // mid + tess.setColorOpaque_I(color); + tess.addVertex(6, 0, 0); + tess.addVertex(4, -0.5, -0.5); + tess.addVertex(4, 0.5, -0.5); + + tess.setColorOpaque_I(color); + tess.addVertex(4, -0.5, 0.5); + tess.addVertex(6, 0, 0); + tess.addVertex(4, 0.5, 0.5); + + tess.setColorOpaque_I(color); + tess.addVertex(4, -0.5, -0.5); + tess.addVertex(6, 0, 0); + tess.addVertex(4, -0.5, 0.5); + + tess.setColorOpaque_I(color); + tess.addVertex(6, 0, 0); + tess.addVertex(4, 0.5, -0.5); + tess.addVertex(4, 0.5, 0.5); + + // tail + tess.setColorOpaque_I(color); + tess.addVertex(4, 0.5, -0.5); + tess.addVertex(4, 0.5, 0.5); + tess.setColorRGBA_I(color, 0); + tess.addVertex(0, 0.5, 0.5); + tess.addVertex(0, 0.5, -0.5); + + tess.setColorOpaque_I(color); + tess.addVertex(4, -0.5, -0.5); + tess.addVertex(4, -0.5, 0.5); + tess.setColorRGBA_I(color, 0); + tess.addVertex(0, -0.5, 0.5); + tess.addVertex(0, -0.5, -0.5); + + tess.setColorOpaque_I(color); + tess.addVertex(4, -0.5, 0.5); + tess.addVertex(4, 0.5, 0.5); + tess.setColorRGBA_I(color, 0); + tess.addVertex(0, 0.5, 0.5); + tess.addVertex(0, -0.5, 0.5); + + tess.setColorOpaque_I(color); + tess.addVertex(4, -0.5, -0.5); + tess.addVertex(4, 0.5, -0.5); + tess.setColorRGBA_I(color, 0); + tess.addVertex(0, 0.5, -0.5); + tess.addVertex(0, -0.5, -0.5); + tess.draw(); + + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glDepthMask(true); + + GL11.glPopMatrix(); + } +}