From a4f469fab66c08773e4f6110f226ffc43733d9f5 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 15 Jun 2021 23:59:23 +0200 Subject: [PATCH] microwave johnson --- src/main/java/com/hbm/blocks/ModBlocks.java | 2 +- .../com/hbm/blocks/turret/TurretMaxwell.java | 2 +- src/main/java/com/hbm/handler/GUIHandler.java | 14 ++ .../java/com/hbm/handler/HTTPHandler.java | 86 +++++----- .../hbm/inventory/gui/GUITurretMaxwell.java | 20 +++ src/main/java/com/hbm/main/ClientProxy.java | 26 +++ src/main/java/com/hbm/main/MainRegistry.java | 5 + .../com/hbm/main/ModEventHandlerClient.java | 15 +- src/main/java/com/hbm/main/ServerProxy.java | 5 + .../tileentity/RenderTurretMaxwell.java | 53 ++++++ .../turret/TileEntityTurretHoward.java | 1 - .../turret/TileEntityTurretMaxwell.java | 154 ++++++++++++++++-- .../java/com/hbm/util/EntityDamageUtil.java | 11 ++ 13 files changed, 334 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/hbm/inventory/gui/GUITurretMaxwell.java diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index d31c51869..b3c29b1d4 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -906,7 +906,7 @@ public class ModBlocks { public static Block turret_howard; public static final int guiID_howard = 112; public static Block turret_maxwell; - public static final int guiID_maxwell = 112; + public static final int guiID_maxwell = 120; public static Block rbmk_rod; public static Block rbmk_control; diff --git a/src/main/java/com/hbm/blocks/turret/TurretMaxwell.java b/src/main/java/com/hbm/blocks/turret/TurretMaxwell.java index 23b73ab57..33937ce33 100644 --- a/src/main/java/com/hbm/blocks/turret/TurretMaxwell.java +++ b/src/main/java/com/hbm/blocks/turret/TurretMaxwell.java @@ -29,4 +29,4 @@ public class TurretMaxwell extends TurretBaseNT { public void openGUI(World world, EntityPlayer player, int x, int y, int z) { FMLNetworkHandler.openGui(player, MainRegistry.instance, ModBlocks.guiID_maxwell, world, x, y, z); } -} +} \ No newline at end of file diff --git a/src/main/java/com/hbm/handler/GUIHandler.java b/src/main/java/com/hbm/handler/GUIHandler.java index 763c98472..884079a42 100644 --- a/src/main/java/com/hbm/handler/GUIHandler.java +++ b/src/main/java/com/hbm/handler/GUIHandler.java @@ -834,6 +834,13 @@ public class GUIHandler implements IGuiHandler { } return null; } + + case ModBlocks.guiID_maxwell: { + if(entity instanceof TileEntityTurretMaxwell) { + return new ContainerTurretBase(player.inventory, (TileEntityTurretMaxwell) entity); + } + return null; + } } // NON-TE CONTAINERS @@ -1655,6 +1662,13 @@ public class GUIHandler implements IGuiHandler { } return null; } + + case ModBlocks.guiID_maxwell: { + if(entity instanceof TileEntityTurretMaxwell) { + return new GUITurretMaxwell(player.inventory, (TileEntityTurretMaxwell) entity); + } + return null; + } } // ITEM GUIS diff --git a/src/main/java/com/hbm/handler/HTTPHandler.java b/src/main/java/com/hbm/handler/HTTPHandler.java index b0333763d..d1633e9a5 100644 --- a/src/main/java/com/hbm/handler/HTTPHandler.java +++ b/src/main/java/com/hbm/handler/HTTPHandler.java @@ -5,67 +5,73 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import com.hbm.lib.RefStrings; import com.hbm.main.MainRegistry; public class HTTPHandler { - - public static String capsule = "ERROR "; + + public static List capsule = new ArrayList(); public static boolean newVersion = false; public static String versionNumber = ""; - + public static void loadStats() { - + try { - + loadVersion(); loadSoyuz(); - - } catch (IOException e) { + + } catch(IOException e) { MainRegistry.logger.warn("Version checker failed!"); } } - + private static void loadVersion() throws IOException { - + URL github = new URL("https://raw.githubusercontent.com/HbmMods/Hbm-s-Nuclear-Tech-GIT/master/src/main/java/com/hbm/lib/RefStrings.java"); - BufferedReader in = new BufferedReader(new InputStreamReader(github.openStream())); - - MainRegistry.logger.info("Searching for new versions..."); - String line; - - while ((line = in.readLine()) != null) { - - if(line.contains("String VERSION")) { + BufferedReader in = new BufferedReader(new InputStreamReader(github.openStream())); - int begin = line.indexOf('"'); - int end = line.lastIndexOf('"'); - - String sub = line.substring(begin + 1, end); - - newVersion = !RefStrings.VERSION.equals(sub); - versionNumber = sub; - MainRegistry.logger.info("Found version " + sub); - break; - } - } + MainRegistry.logger.info("Searching for new versions..."); + String line; - MainRegistry.logger.info("Version checker ended."); - in.close(); + while((line = in.readLine()) != null) { + + if(line.contains("String VERSION")) { + + int begin = line.indexOf('"'); + int end = line.lastIndexOf('"'); + + String sub = line.substring(begin + 1, end); + + newVersion = !RefStrings.VERSION.equals(sub); + versionNumber = sub; + MainRegistry.logger.info("Found version " + sub); + break; + } + } + + MainRegistry.logger.info("Version checker ended."); + in.close(); } - + private static void loadSoyuz() throws IOException { - + URL github = new URL("https://gist.githubusercontent.com/HbmMods/a1cad71d00b6915945a43961d0037a43/raw/soyuz_holo"); - BufferedReader in = new BufferedReader(new InputStreamReader(github.openStream())); - - String line = in.readLine(); - - if(line != null) - capsule = line; - - in.close(); + BufferedReader in = new BufferedReader(new InputStreamReader(github.openStream())); + + String line; + + while((line = in.readLine()) != null) { + capsule.add(line); + } + + if(capsule.isEmpty()) + capsule.add("I AM ERROR"); + + in.close(); } } diff --git a/src/main/java/com/hbm/inventory/gui/GUITurretMaxwell.java b/src/main/java/com/hbm/inventory/gui/GUITurretMaxwell.java new file mode 100644 index 000000000..7a8600db4 --- /dev/null +++ b/src/main/java/com/hbm/inventory/gui/GUITurretMaxwell.java @@ -0,0 +1,20 @@ +package com.hbm.inventory.gui; + +import com.hbm.lib.RefStrings; +import com.hbm.tileentity.turret.TileEntityTurretBaseNT; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +public class GUITurretMaxwell extends GUITurretBase { + + private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/weapon/gui_turret_maxwell.png"); + + public GUITurretMaxwell(InventoryPlayer invPlayer, TileEntityTurretBaseNT tedf) { + super(invPlayer, tedf); + } + + protected ResourceLocation getTexture() { + return texture; + } +} diff --git a/src/main/java/com/hbm/main/ClientProxy.java b/src/main/java/com/hbm/main/ClientProxy.java index b38d6b4fd..32c086dd8 100644 --- a/src/main/java/com/hbm/main/ClientProxy.java +++ b/src/main/java/com/hbm/main/ClientProxy.java @@ -28,10 +28,13 @@ import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.common.MinecraftForge; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Random; +import java.util.Set; import com.hbm.blocks.ModBlocks; import com.hbm.entity.effect.*; @@ -1338,6 +1341,29 @@ public class ClientProxy extends ServerProxy { Minecraft.getMinecraft().effectRenderer.addEffect(new ParticleSpark(world, x, y, z, rand.nextGaussian() * 0.05, 0.05, rand.nextGaussian() * 0.05)); Minecraft.getMinecraft().effectRenderer.addEffect(new ParticleHadron(man, world, x, y, z)); } + + if("vanish".equals(type)) { + int ent = data.getInteger("ent"); + this.vanish(ent); + } + } + + private HashMap vanished = new HashMap(); + + public void vanish(int ent) { + vanished.put(ent, System.currentTimeMillis() + 2000); + } + + @Override + public boolean isVanished(Entity e) { + + if(e == null) + return false; + + if(!this.vanished.containsKey(e.getEntityId())) + return false; + + return this.vanished.get(e.getEntityId()) > System.currentTimeMillis(); } @Override diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index e9c9b7e91..d5a185465 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -208,11 +208,16 @@ public class MainRegistry { public static int y; public static int z; public static long time; + + public static long startupTime = 0; Random rand = new Random(); @EventHandler public void PreLoad(FMLPreInitializationEvent PreEvent) { + + startupTime = System.currentTimeMillis(); + if(logger == null) logger = PreEvent.getModLog(); diff --git a/src/main/java/com/hbm/main/ModEventHandlerClient.java b/src/main/java/com/hbm/main/ModEventHandlerClient.java index 52d92b5f2..9362f216c 100644 --- a/src/main/java/com/hbm/main/ModEventHandlerClient.java +++ b/src/main/java/com/hbm/main/ModEventHandlerClient.java @@ -1,6 +1,7 @@ package com.hbm.main; import java.util.List; +import java.util.Random; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -8,11 +9,9 @@ import org.lwjgl.opengl.GL11; import com.hbm.entity.mob.EntityHunterChopper; import com.hbm.entity.projectile.EntityChopperMine; import com.hbm.extprop.HbmLivingProps; -import com.hbm.extprop.HbmPlayerProps; import com.hbm.handler.ArmorModHandler; import com.hbm.handler.HTTPHandler; import com.hbm.handler.HazmatRegistry; -import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.interfaces.IHoldableWeapon; import com.hbm.interfaces.IItemHUD; import com.hbm.interfaces.Spaghetti; @@ -28,7 +27,6 @@ import com.hbm.lib.Library; import com.hbm.lib.RefStrings; import com.hbm.packet.AuxButtonPacket; import com.hbm.packet.GunButtonPacket; -import com.hbm.packet.KeybindPacket; import com.hbm.packet.PacketDispatcher; import com.hbm.render.anim.HbmAnimations; import com.hbm.render.anim.HbmAnimations.Animation; @@ -49,6 +47,7 @@ import com.hbm.util.I18nUtil; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.hbm.sound.MovingSoundPlayerLoop.EnumHbmSound; +import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -500,7 +499,8 @@ public class ModEventHandlerClient { GL11.glRotated(System.currentTimeMillis() * 0.025 % 360, 0, -1, 0); - String msg = HTTPHandler.capsule; + int rand = new Random(MainRegistry.startupTime).nextInt(HTTPHandler.capsule.size()); + String msg = HTTPHandler.capsule.get(rand); GL11.glTranslated(0, 3.75, 0); GL11.glRotated(180, 1, 0, 0); @@ -545,6 +545,13 @@ public class ModEventHandlerClient { } } + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void preRenderEventFirst(RenderLivingEvent.Pre event) { + + if(MainRegistry.proxy.isVanished(event.entity)) + event.setCanceled(true); + } + @SubscribeEvent public void preRenderEvent(RenderLivingEvent.Pre event) { diff --git a/src/main/java/com/hbm/main/ServerProxy.java b/src/main/java/com/hbm/main/ServerProxy.java index c2d5c868c..46d9cc185 100644 --- a/src/main/java/com/hbm/main/ServerProxy.java +++ b/src/main/java/com/hbm/main/ServerProxy.java @@ -3,6 +3,7 @@ package com.hbm.main; import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.sound.AudioWrapper; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -34,4 +35,8 @@ public class ServerProxy { public EntityPlayer me() { return null; } + + public boolean isVanished(Entity e) { + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/hbm/render/tileentity/RenderTurretMaxwell.java b/src/main/java/com/hbm/render/tileentity/RenderTurretMaxwell.java index 4b2e714ce..a2b539142 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderTurretMaxwell.java +++ b/src/main/java/com/hbm/render/tileentity/RenderTurretMaxwell.java @@ -4,8 +4,13 @@ import org.lwjgl.opengl.GL11; import com.hbm.handler.FluidTypeHandler.FluidType; import com.hbm.main.ResourceManager; +import com.hbm.render.util.BeamPronter; +import com.hbm.render.util.BeamPronter.EnumBeamType; +import com.hbm.render.util.BeamPronter.EnumWaveType; import com.hbm.tileentity.turret.TileEntityTurretMaxwell; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Vec3; @@ -40,6 +45,54 @@ public class RenderTurretMaxwell extends RenderTurretBase { bindTexture(ResourceManager.turret_maxwell_tex); ResourceManager.turret_maxwell.renderPart("Microwave"); + if(turret.beam > 0) { + + double length = turret.lastDist - turret.getBarrelLength(); + + GL11.glPushMatrix(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPushAttrib(GL11.GL_LIGHTING_BIT); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F); + GL11.glTranslated(turret.getBarrelLength(), 2D, 0); + + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.0F); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDepthMask(false); + + Tessellator tess = Tessellator.instance; + tess.startDrawingQuads(); + Vec3 v = Vec3.createVectorHelper(0, 0.375, 0); + for(int i = 0; i < 16; i++) { + + tess.setColorRGBA_F(1.0F, 1.0F, 1.0F, 0.35F); + tess.addVertex(0, v.yCoord, v.zCoord); + tess.setColorRGBA_F(1.0F, 1.0F, 1.0F, 0F); + tess.addVertex(length, v.yCoord, v.zCoord); + v.rotateAroundX((float)Math.PI * 0.25F); + tess.setColorRGBA_F(1.0F, 1.0F, 1.0F, 0F); + tess.addVertex(length, v.yCoord, v.zCoord); + tess.setColorRGBA_F(1.0F, 1.0F, 1.0F, 0.35F); + tess.addVertex(0, v.yCoord, v.zCoord); + } + + tess.draw(); + + GL11.glDepthMask(true); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + GL11.glDisable(GL11.GL_BLEND); + GL11.glShadeModel(GL11.GL_FLAT); + + BeamPronter.prontBeam(Vec3.createVectorHelper(length, 0, 0), EnumWaveType.SPIRAL, EnumBeamType.LINE, 0x0000ff, 0x8080ff, (int)((te.getWorldObj().getTotalWorldTime() + interp) * -50) % 360, (int)((turret.lastDist + 1) * 10), 0.4325F, 0, 0); + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } + GL11.glShadeModel(GL11.GL_FLAT); GL11.glPopMatrix(); } diff --git a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHoward.java b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHoward.java index b1c277d72..94df68742 100644 --- a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHoward.java +++ b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretHoward.java @@ -13,7 +13,6 @@ import com.hbm.util.EntityDamageUtil; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.DamageSource; import net.minecraft.util.Vec3; public class TileEntityTurretHoward extends TileEntityTurretBaseNT { diff --git a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretMaxwell.java b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretMaxwell.java index a5efbe950..e0aacad62 100644 --- a/src/main/java/com/hbm/tileentity/turret/TileEntityTurretMaxwell.java +++ b/src/main/java/com/hbm/tileentity/turret/TileEntityTurretMaxwell.java @@ -2,29 +2,157 @@ package com.hbm.tileentity.turret; import java.util.List; +import com.hbm.lib.ModDamageSource; +import com.hbm.packet.AuxParticlePacketNT; +import com.hbm.packet.PacketDispatcher; +import com.hbm.util.EntityDamageUtil; + +import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.Vec3; + public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT { @Override - public long getMaxPower() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void updateFiringTick() { - // TODO Auto-generated method stub - + public String getName() { + return "container.turretMaxwell"; } @Override protected List getAmmoList() { - // TODO Auto-generated method stub return null; } + + @Override + public double getAcceptableInaccuracy() { + return 2; + } @Override - public String getName() { - // TODO Auto-generated method stub - return "container.turretMaxwell"; + public double getDecetorGrace() { + return 5D; + } + + @Override + public double getTurretYawSpeed() { + return 9D; + } + + @Override + public double getTurretPitchSpeed() { + return 6D; + } + + @Override + public double getTurretElevation() { + return 40D; + } + + @Override + public double getTurretDepression() { + return 35D; + } + + @Override + public double getDecetorRange() { + return 128D; + } + + @Override + public long getMaxPower() { + return 10000000; + } + + @Override + public long getConsumption() { + return 5000; + } + + @Override + public double getBarrelLength() { + return 2.125D; + } + + @Override + public double getHeightOffset() { + return 2D; + } + + public int beam; + public double lastDist; + + @Override + public void updateEntity() { + + if(worldObj.isRemote) { + + if(this.tPos != null) { + Vec3 pos = this.getTurretPos(); + double length = Vec3.createVectorHelper(tPos.xCoord - pos.xCoord, tPos.yCoord - pos.yCoord, tPos.zCoord - pos.zCoord).lengthVector(); + this.lastDist = length; + } + + if(beam > 0) + beam--; + } + + super.updateEntity(); + } + + @Override + public void updateFiringTick() { + + long demand = this.getConsumption() * 10; + + if(this.target != null && this.getPower() >= demand) { + + EntityDamageUtil.attackEntityFromIgnoreIFrame(this.target, ModDamageSource.shrapnel, 1F); + + for(int i = 1; i <= 10; i *= 10) { + + if(EntityDamageUtil.getLastDamage(this.target) < i * 0.5F) + EntityDamageUtil.attackEntityFromIgnoreIFrame(this.target, ModDamageSource.shrapnel, i * 10F); + else + break; + } + + if(!this.target.isEntityAlive()) { + float health = this.target instanceof EntityLivingBase ? ((EntityLivingBase)this.target).getMaxHealth() : 20F; + int count = Math.min((int)Math.ceil(health / 3D), 250); + + NBTTagCompound data = new NBTTagCompound(); + data.setString("type", "vanillaburst"); + data.setInteger("count", count * 4); + data.setDouble("motion", 0.1D); + data.setString("mode", "blockdust"); + data.setInteger("block", Block.getIdFromBlock(Blocks.redstone_block)); + PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ), new TargetPoint(this.target.dimension, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ, 50)); + + NBTTagCompound vdat = new NBTTagCompound(); + vdat.setString("type", "vanish"); + vdat.setInteger("ent", this.target.getEntityId()); + PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ), new TargetPoint(this.target.dimension, this.target.posX, this.target.posY + this.target.height * 0.5, this.target.posZ, 50)); + + worldObj.playSoundEffect(this.target.posX, this.target.posY, this.target.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F); + } + + this.power -= demand; + + NBTTagCompound data = new NBTTagCompound(); + data.setBoolean("shot", true); + this.networkPack(data, 250); + } + } + + @Override + public void networkUnpack(NBTTagCompound nbt) { + + if(nbt.hasKey("shot")) + beam = 5; + else + super.networkUnpack(nbt); } } diff --git a/src/main/java/com/hbm/util/EntityDamageUtil.java b/src/main/java/com/hbm/util/EntityDamageUtil.java index faf988a9c..9894191c5 100644 --- a/src/main/java/com/hbm/util/EntityDamageUtil.java +++ b/src/main/java/com/hbm/util/EntityDamageUtil.java @@ -25,4 +25,15 @@ public class EntityDamageUtil { return true; } } + + public static float getLastDamage(Entity victim) { + + try { + Field lastDamage = ReflectionHelper.findField(EntityLivingBase.class, "lastDamage", "field_110153_bc"); + + return lastDamage.getFloat(victim); + } catch(Exception x) { + return 0F; + } + } }