mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
it's an animation API!
This commit is contained in:
parent
ad0954a145
commit
a21b693441
@ -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.
|
||||
|
||||
@ -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<AnimType, BusAnimation> animations = new HashMap();
|
||||
//whether ot not to disable crosshais when sneaking
|
||||
public boolean hasSights;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<Integer>();
|
||||
config.config.add(BulletConfigSyncingUtil.G20_NORMAL);
|
||||
config.config.add(BulletConfigSyncingUtil.G20_SLUG);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
72
com/hbm/packet/GunAnimationPacket.java
Normal file
72
com/hbm/packet/GunAnimationPacket.java
Normal file
@ -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<GunAnimationPacket, IMessage> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<String, BusAnimationSequence> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
111
com/hbm/render/anim/BusAnimationSequence.java
Normal file
111
com/hbm/render/anim/BusAnimationSequence.java
Normal file
@ -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<BusAnimationKeyframe> 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;
|
||||
}
|
||||
}
|
||||
62
com/hbm/render/anim/HbmAnimations.java
Normal file
62
com/hbm/render/anim/HbmAnimations.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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<BusAnimationKeyframe> keyframes = new ArrayList();
|
||||
public EnumTransformation transformationType;
|
||||
|
||||
public double[] getTransformation(int millis) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user