diff --git a/README.md b/README.md index f75b1f10b..48c46e364 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ https://minecraft.curseforge.com/projects/hbms-nuclear-tech-mod?gameCategorySlug=mc-mods&projectID=235439 +For a 1.12 fork, check this link: https://github.com/Drillgon200/Hbm-s-Nuclear-Tech-GIT/releases + ## Installation Instructions ### Important note: Forge has since dropped support for 1.7.10, quite a few things are not going to work from the getgo. THIS IS NOT MY FAULT, so please, instead of opening an issue on this repository and making it my problem too, use this handy thing called "google" for instructions on how to fix 1.7.10 workspaces. The dependencies are also no longer available on the official forge site, you might have to resort to different versions of the CodeChicken mods, simply change the build.gradle file accordingly and check the code for any errors. diff --git a/com/hbm/handler/GunConfiguration.java b/com/hbm/handler/GunConfiguration.java index 8688e0a66..1737eb053 100644 --- a/com/hbm/handler/GunConfiguration.java +++ b/com/hbm/handler/GunConfiguration.java @@ -1,8 +1,11 @@ package com.hbm.handler; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import com.hbm.render.anim.BusAnimation; +import com.hbm.render.anim.HbmAnimations.AnimType; import com.hbm.render.util.RenderScreenOverlay.Crosshair; public class GunConfiguration { @@ -26,14 +29,8 @@ public class GunConfiguration { //weapon won't fire after weapon breaks (main only) public int durability; - //whether or not there is a reload delay animation - public boolean hasReloadAnim; - //whether or not there is a firing delay with animation - public boolean hasFiringAnim; - //whether there is a warmup duration for spinup - public boolean hasSpinup; - //whether there is a cooldown duration for spindown - public boolean hasSpindown; + //animations! + public HashMap animations = new HashMap(); //whether ot not to disable crosshais when sneaking public boolean hasSights; diff --git a/com/hbm/handler/guncfg/Gun12GaugeFactory.java b/com/hbm/handler/guncfg/Gun12GaugeFactory.java index f63db0489..31cffe9d3 100644 --- a/com/hbm/handler/guncfg/Gun12GaugeFactory.java +++ b/com/hbm/handler/guncfg/Gun12GaugeFactory.java @@ -25,10 +25,6 @@ public class Gun12GaugeFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 6; @@ -60,10 +56,6 @@ public class Gun12GaugeFactory { config.roundsPerCycle = 2; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 0; diff --git a/com/hbm/handler/guncfg/Gun20GaugeFactory.java b/com/hbm/handler/guncfg/Gun20GaugeFactory.java index a96abfbf4..c1e974f2d 100644 --- a/com/hbm/handler/guncfg/Gun20GaugeFactory.java +++ b/com/hbm/handler/guncfg/Gun20GaugeFactory.java @@ -6,6 +6,10 @@ import com.hbm.handler.BulletConfigSyncingUtil; import com.hbm.handler.BulletConfiguration; import com.hbm.handler.GunConfiguration; import com.hbm.items.ModItems; +import com.hbm.render.anim.BusAnimation; +import com.hbm.render.anim.BusAnimationKeyframe; +import com.hbm.render.anim.BusAnimationSequence; +import com.hbm.render.anim.HbmAnimations.AnimType; import com.hbm.render.util.RenderScreenOverlay.Crosshair; import net.minecraft.potion.Potion; @@ -17,14 +21,10 @@ public class Gun20GaugeFactory { GunConfiguration config = new GunConfiguration(); - config.rateOfFire = 10; + config.rateOfFire = 20; config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 6; @@ -33,6 +33,18 @@ public class Gun20GaugeFactory { config.crosshair = Crosshair.L_CIRCLE; config.reloadSound = GunConfiguration.RSOUND_SHOTGUN; + config.animations.put(AnimType.CYCLE, new BusAnimation() + .addBus("LEVER_ROTATE", new BusAnimationSequence() + .addKeyframe(new BusAnimationKeyframe(0, 0, 0, 500)) + .addKeyframe(new BusAnimationKeyframe(0, 0, 45, 250)) + .addKeyframe(new BusAnimationKeyframe(0, 0, 0, 250)) + ) + .addBus("LEVER_RECOIL", new BusAnimationSequence() + .addKeyframe(new BusAnimationKeyframe(0.5, 0, 0, 50)) + .addKeyframe(new BusAnimationKeyframe(0, 0, 90, 50)) + ) + ); + config.config = new ArrayList(); config.config.add(BulletConfigSyncingUtil.G20_NORMAL); config.config.add(BulletConfigSyncingUtil.G20_SLUG); diff --git a/com/hbm/handler/guncfg/Gun22LRFactory.java b/com/hbm/handler/guncfg/Gun22LRFactory.java index f7ec6608a..5cb18ba6e 100644 --- a/com/hbm/handler/guncfg/Gun22LRFactory.java +++ b/com/hbm/handler/guncfg/Gun22LRFactory.java @@ -18,10 +18,6 @@ public class Gun22LRFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 32; diff --git a/com/hbm/handler/guncfg/Gun357MagnumFactory.java b/com/hbm/handler/guncfg/Gun357MagnumFactory.java index af5654aa8..16f89d24c 100644 --- a/com/hbm/handler/guncfg/Gun357MagnumFactory.java +++ b/com/hbm/handler/guncfg/Gun357MagnumFactory.java @@ -21,10 +21,6 @@ public class Gun357MagnumFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 6; diff --git a/com/hbm/handler/guncfg/Gun44MagnumFactory.java b/com/hbm/handler/guncfg/Gun44MagnumFactory.java index 4c2a97b7c..a0549cc53 100644 --- a/com/hbm/handler/guncfg/Gun44MagnumFactory.java +++ b/com/hbm/handler/guncfg/Gun44MagnumFactory.java @@ -33,10 +33,6 @@ public class Gun44MagnumFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 6; diff --git a/com/hbm/handler/guncfg/Gun4GaugeFactory.java b/com/hbm/handler/guncfg/Gun4GaugeFactory.java index e99acf9bd..e7403b016 100644 --- a/com/hbm/handler/guncfg/Gun4GaugeFactory.java +++ b/com/hbm/handler/guncfg/Gun4GaugeFactory.java @@ -18,10 +18,6 @@ public class Gun4GaugeFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 4; diff --git a/com/hbm/handler/guncfg/Gun50AEFactory.java b/com/hbm/handler/guncfg/Gun50AEFactory.java index 4963f5de0..ca7aa864c 100644 --- a/com/hbm/handler/guncfg/Gun50AEFactory.java +++ b/com/hbm/handler/guncfg/Gun50AEFactory.java @@ -18,10 +18,6 @@ public class Gun50AEFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 7; diff --git a/com/hbm/handler/guncfg/Gun50BMGFactory.java b/com/hbm/handler/guncfg/Gun50BMGFactory.java index fc961c735..56a8dcb01 100644 --- a/com/hbm/handler/guncfg/Gun50BMGFactory.java +++ b/com/hbm/handler/guncfg/Gun50BMGFactory.java @@ -27,10 +27,6 @@ public class Gun50BMGFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 50; @@ -65,10 +61,6 @@ public class Gun50BMGFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 30; config.firingDuration = 0; config.ammoCap = 100; diff --git a/com/hbm/handler/guncfg/Gun556mmFactory.java b/com/hbm/handler/guncfg/Gun556mmFactory.java index 984746cca..f88a56892 100644 --- a/com/hbm/handler/guncfg/Gun556mmFactory.java +++ b/com/hbm/handler/guncfg/Gun556mmFactory.java @@ -27,10 +27,6 @@ public class Gun556mmFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.hasSights = false; config.reloadDuration = 20; config.firingDuration = 0; @@ -69,10 +65,6 @@ public class Gun556mmFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.hasSights = true; config.reloadDuration = 25; config.firingDuration = 0; @@ -110,10 +102,6 @@ public class Gun556mmFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.hasSights = true; config.reloadDuration = 40; config.firingDuration = 0; diff --git a/com/hbm/handler/guncfg/Gun5mmFactory.java b/com/hbm/handler/guncfg/Gun5mmFactory.java index 0e5167d31..6ab2807e9 100644 --- a/com/hbm/handler/guncfg/Gun5mmFactory.java +++ b/com/hbm/handler/guncfg/Gun5mmFactory.java @@ -18,10 +18,6 @@ public class Gun5mmFactory { config.roundsPerCycle = 5; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 0; diff --git a/com/hbm/handler/guncfg/Gun9mmFactory.java b/com/hbm/handler/guncfg/Gun9mmFactory.java index c3492a749..5f9b9e29b 100644 --- a/com/hbm/handler/guncfg/Gun9mmFactory.java +++ b/com/hbm/handler/guncfg/Gun9mmFactory.java @@ -18,10 +18,6 @@ public class Gun9mmFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 32; diff --git a/com/hbm/handler/guncfg/GunEnergyFactory.java b/com/hbm/handler/guncfg/GunEnergyFactory.java index c1bbca871..65305aa01 100644 --- a/com/hbm/handler/guncfg/GunEnergyFactory.java +++ b/com/hbm/handler/guncfg/GunEnergyFactory.java @@ -27,10 +27,6 @@ public class GunEnergyFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 10; config.firingDuration = 0; config.ammoCap = 0; @@ -57,10 +53,6 @@ public class GunEnergyFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.reloadSoundEnd = false; config.firingDuration = 0; diff --git a/com/hbm/handler/guncfg/GunFatmanFactory.java b/com/hbm/handler/guncfg/GunFatmanFactory.java index f098b497c..8815ba808 100644 --- a/com/hbm/handler/guncfg/GunFatmanFactory.java +++ b/com/hbm/handler/guncfg/GunFatmanFactory.java @@ -23,10 +23,6 @@ public class GunFatmanFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 120; config.firingDuration = 0; config.ammoCap = 1; @@ -68,10 +64,6 @@ public class GunFatmanFactory { config.roundsPerCycle = 8; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 120; config.firingDuration = 0; config.ammoCap = 8; diff --git a/com/hbm/handler/guncfg/GunGaussFactory.java b/com/hbm/handler/guncfg/GunGaussFactory.java index d71a120e2..ce49391a9 100644 --- a/com/hbm/handler/guncfg/GunGaussFactory.java +++ b/com/hbm/handler/guncfg/GunGaussFactory.java @@ -18,10 +18,6 @@ public class GunGaussFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 0; diff --git a/com/hbm/handler/guncfg/GunGrenadeFactory.java b/com/hbm/handler/guncfg/GunGrenadeFactory.java index b1b1a3884..5da02c6eb 100644 --- a/com/hbm/handler/guncfg/GunGrenadeFactory.java +++ b/com/hbm/handler/guncfg/GunGrenadeFactory.java @@ -18,10 +18,6 @@ public class GunGrenadeFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.hasSights = true; config.reloadDuration = 40; config.firingDuration = 0; diff --git a/com/hbm/handler/guncfg/GunOSIPRFactory.java b/com/hbm/handler/guncfg/GunOSIPRFactory.java index 9c712f190..4d2a0a50e 100644 --- a/com/hbm/handler/guncfg/GunOSIPRFactory.java +++ b/com/hbm/handler/guncfg/GunOSIPRFactory.java @@ -18,10 +18,6 @@ public class GunOSIPRFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_AUTO; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 30; @@ -50,10 +46,6 @@ public class GunOSIPRFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 20; config.firingDuration = 0; config.ammoCap = 0; diff --git a/com/hbm/handler/guncfg/GunRocketFactory.java b/com/hbm/handler/guncfg/GunRocketFactory.java index 3f166b430..44c1b404f 100644 --- a/com/hbm/handler/guncfg/GunRocketFactory.java +++ b/com/hbm/handler/guncfg/GunRocketFactory.java @@ -23,10 +23,6 @@ public class GunRocketFactory { config.roundsPerCycle = 1; config.gunMode = GunConfiguration.MODE_NORMAL; config.firingMode = GunConfiguration.FIRE_MANUAL; - config.hasReloadAnim = false; - config.hasFiringAnim = false; - config.hasSpinup = false; - config.hasSpindown = false; config.reloadDuration = 30; config.firingDuration = 0; config.ammoCap = 1; diff --git a/com/hbm/items/weapon/ItemGunBase.java b/com/hbm/items/weapon/ItemGunBase.java index ff69c7b6f..748bd5253 100644 --- a/com/hbm/items/weapon/ItemGunBase.java +++ b/com/hbm/items/weapon/ItemGunBase.java @@ -11,8 +11,10 @@ import com.hbm.handler.BulletConfiguration; import com.hbm.handler.GunConfiguration; import com.hbm.interfaces.IHoldableWeapon; import com.hbm.main.MainRegistry; +import com.hbm.packet.GunAnimationPacket; import com.hbm.packet.GunButtonPacket; import com.hbm.packet.PacketDispatcher; +import com.hbm.render.anim.HbmAnimations.AnimType; import com.hbm.render.util.RenderScreenOverlay.Crosshair; import cpw.mods.fml.common.FMLCommonHandler; @@ -23,6 +25,7 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -211,6 +214,10 @@ public class ItemGunBase extends Item implements IHoldableWeapon { EntityBulletBase bullet = new EntityBulletBase(world, config, player); world.spawnEntityInWorld(bullet); + + if(this.mainConfig.animations.containsKey(AnimType.CYCLE) && player instanceof EntityPlayerMP) + PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player); + } //called on click (server side, called by mouse packet) for semi-automatics and specific events diff --git a/com/hbm/main/ModEventHandlerClient.java b/com/hbm/main/ModEventHandlerClient.java index 06da88df4..80610c70b 100644 --- a/com/hbm/main/ModEventHandlerClient.java +++ b/com/hbm/main/ModEventHandlerClient.java @@ -16,6 +16,8 @@ import com.hbm.lib.Library; import com.hbm.lib.RefStrings; import com.hbm.packet.GunButtonPacket; import com.hbm.packet.PacketDispatcher; +import com.hbm.render.anim.HbmAnimations; +import com.hbm.render.anim.HbmAnimations.Animation; import com.hbm.render.util.RenderAccessoryUtility; import com.hbm.render.util.RenderScreenOverlay; import com.hbm.sound.MovingSoundChopper; @@ -52,6 +54,7 @@ public class ModEventHandlerClient { EntityPlayer player = Minecraft.getMinecraft().thePlayer; + /// HANDLE GUN AND AMMO OVERLAYS /// if(event.type == ElementType.HOTBAR && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemGunBase) { ItemGunBase gun = ((ItemGunBase)player.getHeldItem().getItem()); @@ -83,6 +86,7 @@ public class ModEventHandlerClient { } } + /// HANDLE GEIGER COUNTER HUD /// if(event.type == ElementType.HOTBAR) { if(player.inventory.hasItem(ModItems.geiger_counter)) { @@ -95,6 +99,7 @@ public class ModEventHandlerClient { } } + /// HANDLE CUSTOM CROSSHAIRS /// if(event.type == ElementType.CROSSHAIRS && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IHoldableWeapon && MainRegistry.enableCrosshairs) { event.setCanceled(true); @@ -102,6 +107,21 @@ public class ModEventHandlerClient { RenderScreenOverlay.renderCustomCrosshairs(event.resolution, Minecraft.getMinecraft().ingameGUI, ((IHoldableWeapon)player.getHeldItem().getItem()).getCrosshair()); } + + /// HANLDE ANIMATION BUSES /// + + for(int i = 0; i < HbmAnimations.hotbar.length; i++) { + + Animation animation = HbmAnimations.hotbar[i]; + + if(animation == null) + continue; + + long time = System.currentTimeMillis() - animation.startMillis; + + if(time > animation.animation.getDuration()) + HbmAnimations.hotbar[i] = null; + } } @SubscribeEvent diff --git a/com/hbm/packet/GunAnimationPacket.java b/com/hbm/packet/GunAnimationPacket.java new file mode 100644 index 000000000..525c0f6d6 --- /dev/null +++ b/com/hbm/packet/GunAnimationPacket.java @@ -0,0 +1,72 @@ +package com.hbm.packet; + +import com.hbm.handler.GunConfiguration; +import com.hbm.items.weapon.ItemGunBase; +import com.hbm.render.anim.BusAnimation; +import com.hbm.render.anim.HbmAnimations; +import com.hbm.render.anim.HbmAnimations.AnimType; +import com.hbm.render.anim.HbmAnimations.Animation; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public class GunAnimationPacket implements IMessage { + + int type; + + public GunAnimationPacket() { } + + public GunAnimationPacket(int type) { + this.type = type; + } + + @Override + public void fromBytes(ByteBuf buf) { + type = buf.readInt(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(type); + } + + public static class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(GunAnimationPacket m, MessageContext ctx) { + + try { + + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + ItemStack stack = player.getHeldItem(); + int slot = player.inventory.currentItem; + + if(stack == null) + return null; + + if(!(stack.getItem() instanceof ItemGunBase)) + return null; + + if(m.type < 0 || m.type >= AnimType.values().length) + return null; + + GunConfiguration config = ((ItemGunBase) stack.getItem()).mainConfig; + AnimType type = AnimType.values()[m.type]; + + BusAnimation animation = config.animations.get(type); + + if(animation != null) { + HbmAnimations.hotbar[slot] = new Animation(stack.getItem().getUnlocalizedName(), System.currentTimeMillis(), animation); + } + + } catch(Exception x) { } + + return null; + } + } +} diff --git a/com/hbm/packet/PacketDispatcher.java b/com/hbm/packet/PacketDispatcher.java index 48f6306a0..552dd52fb 100644 --- a/com/hbm/packet/PacketDispatcher.java +++ b/com/hbm/packet/PacketDispatcher.java @@ -93,6 +93,8 @@ public class PacketDispatcher { wrapper.registerMessage(AuxParticlePacketNT.Handler.class, AuxParticlePacketNT.class, i++, Side.CLIENT); //Signals server to do coord based satellite stuff wrapper.registerMessage(SatCoordPacket.Handler.class, SatCoordPacket.class, i++, Side.SERVER); + //Triggers gun animations of the client + wrapper.registerMessage(GunAnimationPacket.Handler.class, GunAnimationPacket.class, i++, Side.CLIENT); } } diff --git a/com/hbm/render/block/BusAnimation.java b/com/hbm/render/anim/BusAnimation.java similarity index 76% rename from com/hbm/render/block/BusAnimation.java rename to com/hbm/render/anim/BusAnimation.java index c7ad3707f..cef75c8a9 100644 --- a/com/hbm/render/block/BusAnimation.java +++ b/com/hbm/render/anim/BusAnimation.java @@ -1,6 +1,7 @@ -package com.hbm.render.block; +package com.hbm.render.anim; import java.util.HashMap; +import java.util.Map.Entry; //a """simple""" implementation of an animation system //it's the first thing i came up with and i suppose it's relatively simple but @@ -15,6 +16,9 @@ public class BusAnimation { //imagine the busses being film strips that hang from the ceiling, with the tape player //rolling down, picking up images from all tapes and combining them into a movie. + //0 by default, will always equal the duration of the longest BusAnimationSequence + private int totalTime = 0; + /** * Adds a bus to the animation * If an object has several moving parts, each transformation type of each seperat bus should have its own bus @@ -26,9 +30,30 @@ public class BusAnimation { public BusAnimation addBus(String name, BusAnimationSequence bus) { animationBuses.put(name, bus); + + int duration = bus.getTotalTime(); + + if(duration > totalTime) + totalTime = duration; + return this; } + /** + * In case there is keyframes being added to sequences in post, this method allows the totalTime + * to be updated. + */ + public void updateTime() { + + for(Entry sequence : animationBuses.entrySet()) { + + int time = sequence.getValue().getTotalTime(); + + if(time > totalTime) + totalTime = time; + } + } + /** * Gets a bus from the specified name. Usually not something you want to do * @param name @@ -61,5 +86,9 @@ public class BusAnimation { public void playPendingSounds(int lastMillis, int millis) { //TODO: pending } + + public int getDuration() { + return totalTime; + } } diff --git a/com/hbm/render/block/BusAnimationKeyframe.java b/com/hbm/render/anim/BusAnimationKeyframe.java similarity index 73% rename from com/hbm/render/block/BusAnimationKeyframe.java rename to com/hbm/render/anim/BusAnimationKeyframe.java index 5b523cd8e..db0e18261 100644 --- a/com/hbm/render/block/BusAnimationKeyframe.java +++ b/com/hbm/render/anim/BusAnimationKeyframe.java @@ -1,4 +1,4 @@ -package com.hbm.render.block; +package com.hbm.render.anim; //"pieces" that make up a bus public class BusAnimationKeyframe { @@ -25,23 +25,29 @@ public class BusAnimationKeyframe { public InterpolationType interpolationType; public int duration; + public double[] toArray() { + return new double[] {x, y, z}; + } + //this one can be used for "reset" type keyframes public BusAnimationKeyframe() { this.x = 0; this.y = 0; this.z = 0; + this.duration = 1; this.interpolationType = InterpolationType.SMOOTH; } - public BusAnimationKeyframe(double x, double y, double z) { + public BusAnimationKeyframe(double x, double y, double z, int duration) { this(); this.x = x; this.y = y; this.z = z; + this.duration = duration; } - public BusAnimationKeyframe(double x, double y, double z, InterpolationType interpolation) { - this(x, y, z); + public BusAnimationKeyframe(double x, double y, double z, int duration, InterpolationType interpolation) { + this(x, y, z, duration); this.interpolationType = interpolation; } } diff --git a/com/hbm/render/anim/BusAnimationSequence.java b/com/hbm/render/anim/BusAnimationSequence.java new file mode 100644 index 000000000..f9de9f4ba --- /dev/null +++ b/com/hbm/render/anim/BusAnimationSequence.java @@ -0,0 +1,111 @@ +package com.hbm.render.anim; + +import java.util.ArrayList; +import java.util.List; + +import com.hbm.render.anim.BusAnimationKeyframe.InterpolationType; + +//the actual bus, a sequence of keyframes with their own behavior and such +public class BusAnimationSequence { + + //not actually useful for anything since the renderer usually handles + //this part, but it's nice to have for distinction just in case + public static enum EnumTransformation { + UNDEFINED, + ROTATION, + TRANSLATION, + SCALE + } + + private List keyframes = new ArrayList(); + public EnumTransformation transformationType; + + //appends a keyframe at the end of the sequence + public BusAnimationSequence addKeyframe(BusAnimationKeyframe keyframe) { + + keyframes.add(keyframe); + + return this; + } + + //all transformation data is absolute, additive transformations have not yet been implemented + public double[] getTransformation(int millis) { + + BusAnimationKeyframe frame = getFrameAtTime(millis); + + if(frame == null) + return null; + + //if no interpolation type is set, just return the new coords + if(frame.interpolationType == InterpolationType.NONE) + return frame.toArray(); + + //if this is the first frame, the "previous" values are 0 + double[] previous = new double[] {0, 0, 0}; + + BusAnimationKeyframe lastFrame = getPreviousFrame(frame); + + if(lastFrame != null) + previous = lastFrame.toArray(); + + //the time elapsed during the frame is the total current time minus the starting timie of the current frame + int frameTime = millis - getStartingTime(frame); + double interpolation = (double)frameTime / (double)frame.duration; + + double interX = (frame.x - previous[0]) * interpolation + previous[0]; + double interY = (frame.y - previous[1]) * interpolation + previous[1]; + double interZ = (frame.z - previous[2]) * interpolation + previous[2]; + + return new double[] {interX, interY, interZ}; + } + + public BusAnimationKeyframe getFrameAtTime(int millis) { + + int time = 0; + + for(BusAnimationKeyframe frame : keyframes) { + time += frame.duration; + + if(millis < time) + return frame; + } + + return null; + } + + public BusAnimationKeyframe getPreviousFrame(BusAnimationKeyframe frame) { + + int index = keyframes.indexOf(frame); + + if(index == 0) + return null; + + return keyframes.get(index - 1); + } + + public int getStartingTime(BusAnimationKeyframe start) { + + int time = 0; + + for(BusAnimationKeyframe frame : keyframes) { + + if(frame == start) + break; + + time += frame.duration; + } + + return time; + } + + public int getTotalTime() { + + int time = 0; + + for(BusAnimationKeyframe frame : keyframes) { + time += frame.duration; + } + + return time; + } +} diff --git a/com/hbm/render/anim/HbmAnimations.java b/com/hbm/render/anim/HbmAnimations.java new file mode 100644 index 000000000..e3de08a32 --- /dev/null +++ b/com/hbm/render/anim/HbmAnimations.java @@ -0,0 +1,62 @@ +package com.hbm.render.anim; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +public class HbmAnimations { + + //in flans mod and afaik also MW, there's an issue that there is only one + //single animation timer for each client. this is fine for the most part, + //but once you reload and switch weapons while the animation plays, the + //other weapon will too play the animation, even though it is not reloading. + //my approach adds 9 timers, one for every inventory slot. you can still + //"trick" the system by putting a weapon into a different slot while an + //animation is playing, though this will cancel the animation entirely. + public static final Animation[] hotbar = new Animation[9]; + + public static enum AnimType { + RELOAD, //animation for every reload cycle + CYCLE, //animation for every firing cycle + ALT_CYCLE, //animation for alt fire cycles + SPINUP, //animation for actionstart + SPINDOWN //animation for actionend + } + + public static class Animation { + + //the "name" of the animation slot. if the item has a different key than + //the animation, the animation will be canceled. + public String key; + //the starting time of the animation + public long startMillis; + //the animation bus + public BusAnimation animation; + + public Animation(String key, long startMillis, BusAnimation animation) { + this.key = key; + this.startMillis = startMillis; + this.animation = animation; + } + } + + public static Animation getRelevantAnim() { + + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + int slot = player.inventory.currentItem; + ItemStack stack = player.getHeldItem(); + + if(stack == null) + return null; + + if(hotbar[slot] == null) + return null; + + if(hotbar[slot].key.equals(stack.getItem().getUnlocalizedName())) { + return hotbar[slot]; + } + + return null; + } + +} diff --git a/com/hbm/render/block/BusAnimationSequence.java b/com/hbm/render/block/BusAnimationSequence.java deleted file mode 100644 index 5170ebea0..000000000 --- a/com/hbm/render/block/BusAnimationSequence.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.hbm.render.block; - -import java.util.ArrayList; -import java.util.List; - -//the actual bus, a sequence of keyframes with their own behavior and such -public class BusAnimationSequence { - - //not actually useful for anything since the renderer usually handles - //this part, but it's nice to have for distinction just in case - public static enum EnumTransformation { - UNDEFINED, - ROTATION, - TRANSLATION, - SCALE - } - - private List keyframes = new ArrayList(); - public EnumTransformation transformationType; - - public double[] getTransformation(int millis) { - return null; - } -} diff --git a/com/hbm/render/block/RenderAntennaTop.java b/com/hbm/render/block/RenderAntennaTop.java index 2f7322e8e..0368c5f1f 100644 --- a/com/hbm/render/block/RenderAntennaTop.java +++ b/com/hbm/render/block/RenderAntennaTop.java @@ -3,6 +3,7 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/block/RenderBarbedWire.java b/com/hbm/render/block/RenderBarbedWire.java index e1f490cfb..62ebf7e67 100644 --- a/com/hbm/render/block/RenderBarbedWire.java +++ b/com/hbm/render/block/RenderBarbedWire.java @@ -3,6 +3,7 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/block/RenderBarrel.java b/com/hbm/render/block/RenderBarrel.java index 422348b8f..f76648f8f 100644 --- a/com/hbm/render/block/RenderBarrel.java +++ b/com/hbm/render/block/RenderBarrel.java @@ -3,6 +3,7 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/block/RenderConserve.java b/com/hbm/render/block/RenderConserve.java index 37baae718..7aa3763a8 100644 --- a/com/hbm/render/block/RenderConserve.java +++ b/com/hbm/render/block/RenderConserve.java @@ -3,6 +3,7 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/block/RenderConveyor.java b/com/hbm/render/block/RenderConveyor.java index 891852856..284a93154 100644 --- a/com/hbm/render/block/RenderConveyor.java +++ b/com/hbm/render/block/RenderConveyor.java @@ -3,6 +3,7 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/block/RenderScaffoldBlock.java b/com/hbm/render/block/RenderScaffoldBlock.java index 135d56284..bb194b105 100644 --- a/com/hbm/render/block/RenderScaffoldBlock.java +++ b/com/hbm/render/block/RenderScaffoldBlock.java @@ -3,6 +3,8 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; + import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; diff --git a/com/hbm/render/block/RenderSteelBeam.java b/com/hbm/render/block/RenderSteelBeam.java index e528cf014..7b5e0219d 100644 --- a/com/hbm/render/block/RenderSteelBeam.java +++ b/com/hbm/render/block/RenderSteelBeam.java @@ -3,6 +3,7 @@ package com.hbm.render.block; import org.lwjgl.opengl.GL11; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/block/RenderTapeBlock.java b/com/hbm/render/block/RenderTapeBlock.java index f00576c58..dad6d7415 100644 --- a/com/hbm/render/block/RenderTapeBlock.java +++ b/com/hbm/render/block/RenderTapeBlock.java @@ -4,6 +4,7 @@ import org.lwjgl.opengl.GL11; import com.hbm.blocks.ModBlocks; import com.hbm.main.ResourceManager; +import com.hbm.render.util.ObjUtil; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; diff --git a/com/hbm/render/item/ItemRenderGunAnim.java b/com/hbm/render/item/ItemRenderGunAnim.java index 79de56b20..e258fc61e 100644 --- a/com/hbm/render/item/ItemRenderGunAnim.java +++ b/com/hbm/render/item/ItemRenderGunAnim.java @@ -8,6 +8,10 @@ import com.hbm.items.weapon.GunBoltAction; import com.hbm.items.weapon.GunLeverAction; import com.hbm.items.weapon.GunLeverActionS; import com.hbm.lib.RefStrings; +import com.hbm.render.anim.BusAnimation; +import com.hbm.render.anim.BusAnimationSequence; +import com.hbm.render.anim.HbmAnimations; +import com.hbm.render.anim.HbmAnimations.Animation; import com.hbm.render.model.ModelB92; import com.hbm.render.model.ModelB93; import com.hbm.render.model.ModelBoltAction; @@ -50,6 +54,9 @@ public class ItemRenderGunAnim implements IItemRenderer { @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + + float lever = 0; + switch(type) { case EQUIPPED_FIRST_PERSON: GL11.glPushMatrix(); @@ -83,9 +90,34 @@ public class ItemRenderGunAnim implements IItemRenderer { GL11.glTranslatef(2.3F, 0.2F, 0.8F); } - if((item.getItem() == ModItems.gun_lever_action || item.getItem() == ModItems.gun_lever_action_dark) && GunLeverAction.getRotationFromAnim(item) > 0) { - GL11.glRotatef(GunLeverAction.getRotationFromAnim(item) * 25, 0.0F, 0.0F, 1.0F); - GL11.glTranslatef(GunLeverAction.getOffsetFromAnim(item) * -1.5F, 0.0F, 0.0F); + if(item.getItem() == ModItems.gun_lever_action || item.getItem() == ModItems.gun_lever_action_dark) { + + Animation anim = HbmAnimations.getRelevantAnim(); + + if(anim != null) { + + BusAnimation buses = anim.animation; + int millis = (int)(System.currentTimeMillis() - anim.startMillis); + + BusAnimationSequence rotate = buses.getBus("LEVER_ROTATE"); + + if(rotate != null) { + double[] trans = rotate.getTransformation(millis); + + if(trans != null) { + GL11.glRotated(trans[2], 0.0, 0.0, 1.0); + lever = (float) Math.toRadians(trans[2]); + } + } + + BusAnimationSequence recoil = buses.getBus("LEVER_RECOIL"); + if(recoil != null) { + double[] trans = recoil.getTransformation(millis); + + if(trans != null) + GL11.glTranslated(trans[0], 0.0, 0.0); + } + } } if((item.getItem() == ModItems.gun_lever_action_sonata) && GunLeverActionS.getRotationFromAnim(item) > 0) { @@ -121,7 +153,7 @@ public class ItemRenderGunAnim implements IItemRenderer { } if(item.getItem() == ModItems.gun_lever_action || item.getItem() == ModItems.gun_lever_action_dark) - leveraction.renderAnim((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, GunLeverAction.getRotationFromAnim(item)); + leveraction.renderAnim((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, lever); if(item.getItem() == ModItems.gun_lever_action_sonata) leveraction.renderAnim((Entity)data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, GunLeverActionS.getRotationFromAnim(item)); if(item.getItem() == ModItems.gun_bolt_action || item.getItem() == ModItems.gun_bolt_action_green || item.getItem() == ModItems.gun_bolt_action_saturnite) diff --git a/com/hbm/render/block/ObjUtil.java b/com/hbm/render/util/ObjUtil.java similarity index 98% rename from com/hbm/render/block/ObjUtil.java rename to com/hbm/render/util/ObjUtil.java index 8b6dac094..4175203f8 100644 --- a/com/hbm/render/block/ObjUtil.java +++ b/com/hbm/render/util/ObjUtil.java @@ -1,4 +1,4 @@ -package com.hbm.render.block; +package com.hbm.render.util; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon;