Fix reload animation getting stuck if you run out of ammo before filling the weapon

Fix ALT_CYCLE support, will fall back to CYCLE if no ALT_CYCLE animation is defined
This commit is contained in:
George Paton 2024-02-01 21:56:04 +11:00
parent 273018a5c7
commit 3d6c2aa67e
8 changed files with 34 additions and 262 deletions

View File

@ -16,7 +16,6 @@ import com.hbm.particle.SpentCasing;
import com.hbm.particle.SpentCasing.CasingType;
import com.hbm.potion.HbmPotion;
import com.hbm.render.anim.BusAnimation;
import com.hbm.render.anim.BusAnimationKeyframe;
import com.hbm.render.anim.BusAnimationSequence;
import com.hbm.render.anim.BusAnimationSequence.Dimension;
import com.hbm.render.anim.HbmAnimations.AnimType;

View File

@ -4257,7 +4257,7 @@ public class ModItems {
gun_twigun = new GunEuthanasia().setUnlocalizedName("gun_twigun").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_twigun");
gun_defabricator_ammo = new Item().setUnlocalizedName("gun_defabricator_ammo").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_defabricator_ammo");
gun_defabricator = new GunDefabricator().setUnlocalizedName("gun_defabricator").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_defabricator");
gun_vortex = new ItemGunVortex(Gun556mmFactory.getEuphieConfig()).setUnlocalizedName("gun_vortex").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_vortex");
gun_vortex = new ItemGunBase(Gun556mmFactory.getEuphieConfig()).setUnlocalizedName("gun_vortex").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_vortex");
gun_super_shotgun = new ItemCustomLore().setUnlocalizedName("gun_super_shotgun").setMaxStackSize(1).setFull3D().setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_super_shotgun");
gun_moist_nugget = new ItemNugget(3, false).setUnlocalizedName("gun_moist_nugget").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_moist_nugget");
gun_dampfmaschine = new GunDampfmaschine().setUnlocalizedName("gun_dampfmaschine").setCreativeTab(MainRegistry.weaponTab).setTextureName(RefStrings.MODID + ":gun_dampfmaschine");

View File

@ -26,12 +26,12 @@ public class ItemCryoCannon extends ItemGunBase {
@Override
protected void fire(ItemStack stack, World world, EntityPlayer player) {
if(this.getPressure(stack) >= 1000) return;
if(this.getTurbine(stack) < 100) return;
if(getPressure(stack) >= 1000) return;
if(getTurbine(stack) < 100) return;
BulletConfiguration config = null;
if(mainConfig.reloadType == mainConfig.RELOAD_NONE) {
if(mainConfig.reloadType == GunConfiguration.RELOAD_NONE) {
config = getBeltCfg(player, stack, true);
} else {
config = BulletConfigSyncingUtil.pullConfig(mainConfig.config.get(getMagType(stack)));
@ -50,6 +50,9 @@ public class ItemCryoCannon extends ItemGunBase {
for(int i = 0; i < bullets; i++) {
spawnProjectile(world, player, stack, BulletConfigSyncingUtil.getKey(config));
}
if(player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
useUpAmmo(player, stack, true);
player.inventoryContainer.detectAndSendChanges();
@ -66,26 +69,23 @@ public class ItemCryoCannon extends ItemGunBase {
@Override
protected void spawnProjectile(World world, EntityPlayer player, ItemStack stack, int config) {
EntityChemical chem = new EntityChemical(world, player);
chem.setFluid(Fluids.OXYGEN);
world.spawnEntityInWorld(chem);
int pressure = this.getPressure(stack);
int pressure = getPressure(stack);
pressure += 5;
pressure = MathHelper.clamp_int(pressure, 0, 1000);
this.setPressure(stack, pressure);
if(player instanceof EntityPlayerMP) PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
setPressure(stack, pressure);
}
@Override
protected void updateServer(ItemStack stack, World world, EntityPlayer player, int slot, boolean isCurrentItem) {
int turbine = this.getTurbine(stack);
int pressure = this.getPressure(stack);
int turbine = getTurbine(stack);
int pressure = getPressure(stack);
if(this.getIsMouseDown(stack)) {
if(getIsMouseDown(stack)) {
turbine += 10;
} else {
turbine -= 5;
@ -94,8 +94,8 @@ public class ItemCryoCannon extends ItemGunBase {
turbine = MathHelper.clamp_int(turbine, 0, 100);
pressure = MathHelper.clamp_int(pressure, 0, 1000);
this.setTurbine(stack, turbine);
this.setPressure(stack, pressure);
setTurbine(stack, turbine);
setPressure(stack, pressure);
super.updateServer(stack, world, player, slot, isCurrentItem);
}

View File

@ -241,6 +241,9 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
for(int i = 0; i < bullets; i++) {
spawnProjectile(world, player, stack, BulletConfigSyncingUtil.getKey(config));
}
if(player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
useUpAmmo(player, stack, true);
player.inventoryContainer.detectAndSendChanges();
@ -276,6 +279,9 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
for(int i = 0; i < bullets; i++) {
spawnProjectile(world, player, stack, BulletConfigSyncingUtil.getKey(config));
}
if(player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.ALT_CYCLE.ordinal()), (EntityPlayerMP) player);
useUpAmmo(player, stack, false);
player.inventoryContainer.detectAndSendChanges();
@ -291,13 +297,8 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
//spawns the actual projectile, can be overridden to change projectile entity
protected void spawnProjectile(World world, EntityPlayer player, ItemStack stack, int config) {
EntityBulletBaseNT bullet = new EntityBulletBaseNT(world, config, player);
world.spawnEntityInWorld(bullet);
if(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
@ -314,10 +315,6 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire);
}
//setMag(stack, getMag(stack) - 1);
//useUpAmmo(player, stack, main);
//player.inventoryContainer.detectAndSendChanges();
}
if(!main && altConfig != null && tryShoot(stack, world, player, main)) {
@ -328,9 +325,6 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
altFire(stack, world, player);
setDelay(stack, altConfig.rateOfFire);
}
//useUpAmmo(player, stack, main);
//player.inventoryContainer.detectAndSendChanges();
}
}
@ -378,7 +372,8 @@ public class ItemGunBase extends Item implements IHoldableWeapon, IItemHUD, IEqu
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.RELOAD_END.ordinal()), (EntityPlayerMP) player);
} else {
resetReloadCycle(player, stack);
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.RELOAD_CYCLE.ordinal()), (EntityPlayerMP) player);
AnimType animType = availableFills <= 1 ? AnimType.RELOAD_END : AnimType.RELOAD_CYCLE;
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(animType.ordinal()), (EntityPlayerMP) player);
}
if(hasLoaded && mainConfig.reloadSoundEnd)

View File

@ -48,13 +48,14 @@ public class ItemGunChemthrower extends ItemGunBase implements IFillableItem {
spawnProjectile(world, player, stack, 0);
}
if(player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
useUpAmmo(player, stack, true);
player.inventoryContainer.detectAndSendChanges();
int wear = (int) Math.ceil(10 / (1F + EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)));
setItemWear(stack, getItemWear(stack) + wear);
//world.playSoundAtEntity(player, mainConfig.firingSound, 1.0F, mainConfig.firingPitch);
}
@Override
@ -86,15 +87,10 @@ public class ItemGunChemthrower extends ItemGunBase implements IFillableItem {
@Override
protected void spawnProjectile(World world, EntityPlayer player, ItemStack stack, int config) {
//spawn fluid projectile
EntityChemical chem = new EntityChemical(world, player);
chem.setFluid(this.getFluidType(stack));
world.spawnEntityInWorld(chem);
if(player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
}
@Override

View File

@ -1,215 +0,0 @@
package com.hbm.items.weapon;
import com.hbm.handler.GunConfiguration;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemGunVortex extends ItemGunBase {
@SideOnly(Side.CLIENT)
private long lastFireTime;
public ItemGunVortex(GunConfiguration config) {
super(config);
}
/*@Override
protected void spawnProjectile(World world, EntityPlayer player, ItemStack stack, int config) {
//EntityBeamVortex beam = new EntityBeamVortex(world, player);
//world.spawnEntity(beam);
//100 blocks is its current max range, but I'm sure that could be increased if necessary.
List<Entity> entsOnBeam = Library.rayTraceEntitiesOnLine(player, 100, 1).getRight();
for(Entity e : entsOnBeam){
if(!(e instanceof EntityLivingBase))
continue;
float dmg = 30;
EntityDamageUtil.attackEntityFromIgnoreIFrame(e, ModDamageSource.radiation, dmg);
}
if(this.mainConfig.animations.containsKey(AnimType.CYCLE) && player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
PacketDispatcher.wrapper.sendToAllAround(new GunFXPacket(player, FXType.FIRE), new TargetPoint(world.provider.dimensionId, player.posX, player.posY, player.posZ, 1));
}
//This method should also solve the supershotgun issue where it doesn't fire some of the time (maybe?)
@Override
@SideOnly(Side.CLIENT)
public void onFireClient(ItemStack stack, EntityPlayer player, boolean shouldDoThirdPerson) {
//If I'm going to do more particle systems like this maybe I should write some kind of abstraction around it to make it less messy.
NBTTagCompound tag = new NBTTagCompound();
Vec3d pos = null;
if(stack == player.getHeldItemMainhand()){
pos = new Vec3d(-0.16, -0.20, 1).rotatePitch(-(float) Math.toRadians(player.rotationPitch)).rotateYaw(-(float) Math.toRadians(player.rotationYawHead));
} else {
pos = new Vec3d(0.16, -0.20, 1).rotatePitch(-(float) Math.toRadians(player.rotationPitch)).rotateYaw(-(float) Math.toRadians(player.rotationYawHead));
}
pos = pos.add(player.getPositionEyes(1F));
Vec3d view = BobMathUtil.getVectorFromAngle(BobMathUtil.getEulerAngles(player.getLookVec()).addVector(0, 3, 0));
Vec3d hitPos = null;
Vec3d hitNormal = null;
RayTraceResult r = Library.rayTraceIncludeEntities(player, 100, MainRegistry.proxy.partialTicks());
if(r == null || r.typeOfHit == Type.MISS){
hitPos = player.getLook(MainRegistry.proxy.partialTicks()).scale(100).add(pos);
} else {
hitPos = r.hitVec;
hitNormal = new Vec3d(r.sideHit.getFrontOffsetX(), r.sideHit.getFrontOffsetY(), r.sideHit.getFrontOffsetZ());
}
tag.setString("type", "spark");
tag.setString("mode", "coneBurst");
tag.setDouble("posX", pos.x-player.motionX);
tag.setDouble("posY", pos.y-player.motionY);
tag.setDouble("posZ", pos.z-player.motionZ);
tag.setDouble("dirX", view.x);
tag.setDouble("dirY", view.y);
tag.setDouble("dirZ", view.z);
tag.setFloat("r", 0.2F);
tag.setFloat("g", 0.8F);
tag.setFloat("b", 0.9F);
tag.setFloat("a", 1.5F);
tag.setInteger("lifetime", 1);
tag.setFloat("width", 0.01F);
tag.setFloat("length", 2F);
tag.setFloat("gravity", 0);
tag.setFloat("angle", 15F);
tag.setInteger("count", 12);
MainRegistry.proxy.effectNT(tag);
ParticleVortexBeam beam = new ParticleVortexBeam(player.world, pos.x, pos.y, pos.z, hitPos.x, hitPos.y, hitPos.z, shouldDoThirdPerson);
beam.color(0.5F, 0.8F, 0.9F, 2.0F);
beam.width(0.125F);
Minecraft.getMinecraft().effectRenderer.addEffect(beam);
ParticleVortexFireFlash flash = new ParticleVortexFireFlash(player.world, pos.x, pos.y, pos.z, hitPos.x, hitPos.y, hitPos.z);
flash.color(0.5F, 0.8F, 0.9F, 1F);
flash.width(0.5F);
Minecraft.getMinecraft().effectRenderer.addEffect(flash);
Vec3 line = hitPos.subtract(pos);
int circleParticles = (int) line.lengthVector();
for(int i = 0; i < circleParticles; i ++){
Vec3 circlePos = line.scale(i/(float)circleParticles).add(pos);
ParticleVortexCircle c = new ParticleVortexCircle(player.worldObj, circlePos.x, circlePos.y, circlePos.z, 0.5F+player.worldObj.rand.nextFloat()*0.3F);
c.color(0.5F, 0.8F, 0.9F, 0.15F);
c.lifetime((int) (15+(i/(float)circleParticles)*10));
Minecraft.getMinecraft().effectRenderer.addEffect(c);
}
int extraParticles = (int) line.lengthVector();
for(int i = 0; i < extraParticles; i ++){
Vec3d circlePos = line.scale((i/(float)circleParticles)*0.25).add(pos);
float randX = (float) (player.worldObj.rand.nextGaussian()-0.5) * 0.01F;
float randY = (float) (player.worldObj.rand.nextGaussian()-0.5) * 0.01F;
float randZ = (float) (player.worldObj.rand.nextGaussian()-0.5) * 0.01F;
ParticleVortexParticle c = new ParticleVortexParticle(player.worldObj, circlePos.x+randX, circlePos.y+randY, circlePos.z+randZ, 0.5F);
c.color(0.5F, 0.8F, 0.9F, 0.15F);
c.lifetime(30);
Minecraft.getMinecraft().effectRenderer.addEffect(c);
}
ParticleVortexGlow glow = new ParticleVortexGlow(player.worldObj, pos.x, pos.y, pos.z, 2F);
glow.color(0.3F, 0.7F, 1F, 0.5F);
glow.lifetime(15);
Minecraft.getMinecraft().effectRenderer.addEffect(glow);
if(hitNormal != null){
Vec3d sparkAxis = line.normalize().scale(0.25);
switch(r.sideHit.getAxis()){
case X:
sparkAxis = new Vec3d(-sparkAxis.x, sparkAxis.y, sparkAxis.z);
break;
case Y:
sparkAxis = new Vec3d(sparkAxis.x, -sparkAxis.y, sparkAxis.z);
break;
case Z:
sparkAxis = new Vec3d(sparkAxis.x, sparkAxis.y, -sparkAxis.z);
break;
}
tag = new NBTTagCompound();
tag.setString("type", "spark");
tag.setString("mode", "coneBurst");
tag.setDouble("posX", hitPos.x);
tag.setDouble("posY", hitPos.y);
tag.setDouble("posZ", hitPos.z);
tag.setDouble("dirX", sparkAxis.x);
tag.setDouble("dirY", sparkAxis.y+0.1);
tag.setDouble("dirZ", sparkAxis.z);
tag.setFloat("r", 0.2F);
tag.setFloat("g", 0.8F);
tag.setFloat("b", 0.9F);
tag.setFloat("a", 1.5F);
tag.setInteger("lifetime", 20);
tag.setInteger("randLifetime", 30);
tag.setFloat("width", 0.015F);
tag.setFloat("length", 0.5F);
tag.setFloat("gravity", 0.05F);
tag.setFloat("angle", 70F);
tag.setInteger("count", 15);
tag.setFloat("randomVelocity", 0.1F);
MainRegistry.proxy.effectNT(tag);
ParticleVortexHit hit = new ParticleVortexHit(player.world, hitPos.x, hitPos.y, hitPos.z, 2.5F+player.world.rand.nextFloat()*0.5F, 90);
hit.color(0.4F, 0.8F, 1F, 0.25F);
hit.lifetime(20);
ParticleVortexHit hit2 = new ParticleVortexHit(player.world, hitPos.x, hitPos.y, hitPos.z, 2.5F+player.world.rand.nextFloat()*0.5F, -90);
hit2.color(0.4F, 0.8F, 1F, 0.25F);
hit2.lifetime(20);
Minecraft.getMinecraft().effectRenderer.addEffect(hit);
Minecraft.getMinecraft().effectRenderer.addEffect(hit2);
}
MainRegistry.proxy.setRecoil(3);
lastFireTime = System.currentTimeMillis();
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasCustomHudElement() {
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void renderHud(ScaledResolution res, GuiIngame gui, ItemStack stack, float partialTicks) {
float x = res.getScaledWidth()/2;
float y = res.getScaledHeight()/2;
Minecraft.getMinecraft().getTextureManager().bindTexture(ResourceManager.vortex_hud_reticle);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glColor4f(0.4F, 0.9F, 0.9F, 1.0F);
GL11.glEnable(GL11.GL_BLEND);
GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO);
RenderHelper.drawGuiRect(x - 11F, y - 11F, 0, 0, 22, 22, 1, 1);
Minecraft.getMinecraft().getTextureManager().bindTexture(ResourceManager.vortex_hud_circle);
//Running off of system time gives less wonky results than relying on server updating the nbt tag.
long time = System.currentTimeMillis();
//float cooldown = (this.mainConfig.rateOfFire-getDelay(stack)+partialTicks)/(float)this.mainConfig.rateOfFire;
//Adding 0.05 so it doesn't start at nothing makes it look better in my opinion.
//It's 55 instead of 50 (50 ms in one tick) because xon lets you fire slightly before the cooldown is over. This extends the cooldown slightly beyond the real one.
float cooldown = MathHelper.clamp((time-lastFireTime)/(float)(mainConfig.rateOfFire*55), 0, 1)+0.05F;
final int SUBDIVISIONS = 64;
Tessellator tes = Tessellator.instance;
tes.startDrawing(GL11.GL_TRIANGLE_FAN);
tes.setColorRGBA_F(0.4F, 0.9F, 0.9F, 0.4F);
tes.addVertexWithUV(x, y, 0, 0.5, 0.5);
for(int i = 0; i < SUBDIVISIONS+1; i ++){
//Should be quite fast because MathHelper uses a sin table... right?
float ratio = i/(float)SUBDIVISIONS;
float x2 = MathHelper.sin((float) (ratio*Math.PI*2+0.5*Math.PI));
float y2 = MathHelper.cos((float) (ratio*Math.PI*2+0.5*Math.PI));
float alphaMult = 1-ratio < cooldown ? 1 : 0;
buf.pos(x+x2*11, y+y2*11, 0).tex(BobMathUtil.remap01(x2, -1, 1), BobMathUtil.remap01(y2, -1, 1)).color(0.4F, 0.9F, 0.9F, 0.4F*alphaMult).endVertex();
}
tes.draw();
GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);
GlStateManager.disableBlend();
}*/
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.lwjgl.input.Mouse;
import com.hbm.config.GeneralConfig;
import com.hbm.entity.projectile.EntityBulletBaseNT;
import com.hbm.handler.BulletConfigSyncingUtil;
import com.hbm.handler.BulletConfiguration;
import com.hbm.handler.GunConfiguration;
@ -131,6 +130,9 @@ public class ItemEnergyGunBase extends ItemGunBase implements IBatteryItem {
for(int i = 0; i < bullets; i++) {
spawnProjectile(world, player, stack, BulletConfigSyncingUtil.getKey(config));
}
if(player instanceof EntityPlayerMP)
PacketDispatcher.wrapper.sendTo(new GunAnimationPacket(AnimType.CYCLE.ordinal()), (EntityPlayerMP) player);
setCharge(stack, getCharge(stack) - config.dischargePerShot);;
}
@ -138,19 +140,9 @@ public class ItemEnergyGunBase extends ItemGunBase implements IBatteryItem {
world.playSoundAtEntity(player, mainConfig.firingSound, 1.0F, mainConfig.firingPitch);
}
protected void spawnProjectile(World world, EntityPlayer player, ItemStack stack, int config) {
EntityBulletBaseNT bullet = new EntityBulletBaseNT(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);
}
public void startAction(ItemStack stack, World world, EntityPlayer player, boolean main) {
if(mainConfig.firingMode == mainConfig.FIRE_MANUAL && main && tryShoot(stack, world, player, main)) {
if(mainConfig.firingMode == GunConfiguration.FIRE_MANUAL && main && tryShoot(stack, world, player, main)) {
fire(stack, world, player);
setDelay(stack, mainConfig.rateOfFire);

View File

@ -66,6 +66,11 @@ public class GunAnimationPacket implements IMessage {
if(animation == null && type == AnimType.RELOAD_EMPTY) {
animation = base.getAnimation(stack, AnimType.RELOAD);
}
// Fallback to regular CYCLE if no ALT_CYCLE exists
if(animation == null && type == AnimType.ALT_CYCLE) {
animation = base.getAnimation(stack, AnimType.CYCLE);
}
if(animation != null) {
boolean isReloadAnimation = type == AnimType.RELOAD || type == AnimType.RELOAD_CYCLE || type == AnimType.RELOAD_EMPTY;