Removed ModelWings Allocations (#77)

* Removed ModelWings Allocations

* init on first call

* Fix wings and speical armor

* spotless
This commit is contained in:
Caedis authored and GitHub committed 2024-05-19 00:17:44 -05:00
1 parent 5074d8ba1d
commit 6fea13084d
4 files changed
+95 -64

No files matched your search

@@ -12,6 +12,8 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelSpecialArmor extends ModelBiped {
private static ModelSpecialArmor instance;
public ModelRenderer rightWing;
public ModelRenderer leftWing;
public ModelRenderer center;
@@ -30,41 +32,43 @@ public class ModelSpecialArmor extends ModelBiped {
public ModelSpecialArmor(float scale, float offset, int type) {
super(scale, offset, type == 1 ? 128 : 64, type == 0 ? 32 : type == 1 ? 96 : 64);
this.type = type;
switch (this.type) {
case 1:
this.textureWidth = 128;
this.textureHeight = 96;
this.jetpack = new ModelRenderer(this, 16, 69);
this.jetpack.setTextureSize(64, 48);
this.jetpack.addBox(-4.0F, -12.0F, -2.0F, 8, 12 * 2, 4, scale * 2);
this.jetpack.setRotationPoint(0.0F, 0.0F + offset, 0.0F);
break;
case 2:
this.textureWidth = 64;
this.textureHeight = 64;
rightWing = new ModelRenderer(this, 24, 0 + 32);
rightWing.addBox(-11F, -1F, 0F, 11, 13, 1);
rightWing.setRotationPoint(-2F, 0F, 3F);
rightWing.setTextureSize(64, 32);
rightWing.mirror = false;
setRotation(rightWing, 0F, 0.1570796F, 0F);
this.textureWidth = 128;
this.textureHeight = 96;
this.jetpack = new ModelRenderer(this, 16, 69);
this.jetpack.setTextureSize(64, 48);
this.jetpack.addBox(-4.0F, -12.0F, -2.0F, 8, 12 * 2, 4, scale * 2);
this.jetpack.setRotationPoint(0.0F, 0.0F + offset, 0.0F);
leftWing = new ModelRenderer(this, 0, 0 + 32);
leftWing.addBox(0F, -1F, 0F, 11, 13, 1);
leftWing.setRotationPoint(2F, 0F, 3F);
leftWing.setTextureSize(64, 32);
leftWing.mirror = true;
setRotation(leftWing, 0F, -0.1570796F, 0F);
this.textureWidth = 64;
this.textureHeight = 64;
rightWing = new ModelRenderer(this, 24, 0 + 32);
rightWing.addBox(-11F, -1F, 0F, 11, 13, 1);
rightWing.setRotationPoint(-2F, 0F, 3F);
rightWing.setTextureSize(64, 32);
rightWing.mirror = false;
setRotation(rightWing, 0F, 0.1570796F, 0F);
center = new ModelRenderer(this, 0, 14 + 32);
center.addBox(0F, 0F, 1F, 8, 14, 1);
center.setRotationPoint(-4F, 0F, 3F);
center.setTextureSize(64, 32);
center.mirror = true;
setRotation(center, 0F, 0F, 0F);
break;
}
leftWing = new ModelRenderer(this, 0, 0 + 32);
leftWing.addBox(0F, -1F, 0F, 11, 13, 1);
leftWing.setRotationPoint(2F, 0F, 3F);
leftWing.setTextureSize(64, 32);
leftWing.mirror = true;
setRotation(leftWing, 0F, -0.1570796F, 0F);
center = new ModelRenderer(this, 0, 14 + 32);
center.addBox(0F, 0F, 1F, 8, 14, 1);
center.setRotationPoint(-4F, 0F, 3F);
center.setTextureSize(64, 32);
center.mirror = true;
setRotation(center, 0F, 0F, 0F);
}
public static ModelSpecialArmor getInstance() {
if (instance == null) instance = new ModelSpecialArmor();
return instance;
}
private void setRotation(ModelRenderer model, float x, float y, float z) {
@@ -96,6 +100,7 @@ public class ModelSpecialArmor extends ModelBiped {
this.center.render(scale);
this.leftWing.render(scale);
this.rightWing.render(scale);
break;
}
}
@@ -105,6 +110,9 @@ public class ModelSpecialArmor extends ModelBiped {
if (this.isJumping) {
this.rightWing.rotateAngleY = 0.5f;
this.leftWing.rotateAngleY = -0.5f;
} else {
this.rightWing.rotateAngleY = 0.1570796F;
this.leftWing.rotateAngleY = -0.1570796F;
}
if (this.isSneak) {
@@ -113,14 +121,22 @@ public class ModelSpecialArmor extends ModelBiped {
this.jetpack.rotateAngleX = 0.5F;
break;
case 2:
this.center.offsetY -= 0.1;
this.rightWing.offsetY -= 0.1;
this.leftWing.offsetY -= 0.1;
this.center.rotateAngleX = 0.5F;
this.rightWing.rotateAngleX = 0.5F;
this.leftWing.rotateAngleX = 0.5F;
break;
}
} else {
switch (this.type) {
case 1:
this.jetpack.rotateAngleX = 0F;
break;
case 2:
this.center.rotateAngleX = 0F;
this.rightWing.rotateAngleX = 0F;
this.leftWing.rotateAngleX = 0F;
break;
}
}
}
}
+21 -4
View File
@@ -4,8 +4,14 @@ import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ModelWings extends ModelBiped {
@SideOnly(Side.CLIENT)
private static ModelWings instance = null;
public boolean isJumping = false;
ModelRenderer rightWing;
ModelRenderer leftWing;
@@ -41,6 +47,12 @@ public class ModelWings extends ModelBiped {
this.bipedBody.addChild(center);
}
public static ModelWings getInstance() {
if (instance == null) instance = new ModelWings();
return instance;
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
this.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
@@ -55,20 +67,25 @@ public class ModelWings extends ModelBiped {
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float pt, float f3, float f4, float f5, Entity entity) {
public void setRotationAngles(float limbSwing, float limbSwingAmount, float playerTicksExisted,
float playerRotationYawHead, float playerRotationPitch, float f5, Entity entity) {
if (isJumping) {
this.rightWing.rotateAngleY = 0.5f;
this.leftWing.rotateAngleY = -0.5f;
} else {
this.rightWing.rotateAngleY = 0.1570796F;
this.leftWing.rotateAngleY = -0.1570796F;
}
if (entity.isSneaking()) {
this.center.offsetY -= 0.1;
this.rightWing.offsetY -= 0.1;
this.leftWing.offsetY -= 0.1;
this.center.rotateAngleX = 0.5F;
this.rightWing.rotateAngleX = 0.5F;
this.leftWing.rotateAngleX = 0.5F;
} else {
this.center.rotateAngleX = 0.0F;
this.rightWing.rotateAngleX = 0;
this.leftWing.rotateAngleX = 0;
}
}
}
@@ -390,22 +390,23 @@ public class ItemInfusedQuantumChestplate extends ItemArmorElectric implements I
@Override
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack stack, int armorSlot) {
try {
if (entity instanceof EntityPlayer) {
byte wing = stack.stackTagCompound.getByte("wing");
if (wing == JETPACK) {
ModelSpecialArmor mbm = new ModelSpecialArmor(1, 1);
return mbm;
} else if (wing != 0) {
ModelSpecialArmor mbm = new ModelSpecialArmor(1, 2);
mbm.isJumping = stack.stackTagCompound.getBoolean("isJumping");
return mbm;
if (entity instanceof EntityPlayer && stack != null && stack.stackTagCompound != null) {
byte wing = stack.stackTagCompound.getByte("wing");
if (wing == JETPACK) {
ModelSpecialArmor.getInstance().type = 1;
} else if (wing != 0) {
ModelSpecialArmor.getInstance().type = 2;
if (stack.stackTagCompound.hasKey("isJumping")) {
ModelSpecialArmor.getInstance().isJumping = stack.stackTagCompound.getBoolean("isJumping");
}
} else {
ModelSpecialArmor.getInstance().type = 0;
}
} catch (NullPointerException e) {
new ModelSpecialArmor(1, 0);
} else {
ModelSpecialArmor.getInstance().type = 0;
}
return new ModelSpecialArmor(1, 0);
return ModelSpecialArmor.getInstance();
}
@SuppressWarnings("unchecked")
@@ -51,16 +51,13 @@ public class ItemFeatherWing extends ItemArmor implements IRunicArmor {
@Override
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack stack, int armorSlot) {
try {
if (entity instanceof EntityPlayer) {
ModelWings mw = new ModelWings();
mw.isJumping = stack.stackTagCompound.getBoolean("isJumping");
return mw;
}
} catch (NullPointerException e) {
return new ModelWings();
if (entity instanceof EntityPlayer && stack != null
&& stack.stackTagCompound != null
&& stack.stackTagCompound.hasKey("isJumping")) {
ModelWings.getInstance().isJumping = stack.stackTagCompound.getBoolean("isJumping");
}
return new ModelWings();
return ModelWings.getInstance();
}
@Override
@@ -72,12 +69,12 @@ public class ItemFeatherWing extends ItemArmor implements IRunicArmor {
int amount) {
NBTTagCompound nbtData = StackUtil.getOrCreateNbtData(stack);
boolean isJmuping = nbtData.getBoolean("isJumping");
boolean isJumping = nbtData.getBoolean("isJumping");
boolean isHolding = nbtData.getBoolean("isHolding");
nbtData.setBoolean("isJumping", IC2.keyboard.isJumpKeyDown(player));
if (isJmuping) {
if (isJumping) {
byte f = nbtData.getByte("f");
nbtData.setBoolean("isHolding", true);
if (IC2.keyboard.isSneakKeyDown(player)) nbtData.setByte("f", (byte) (0));
@@ -108,7 +105,7 @@ public class ItemFeatherWing extends ItemArmor implements IRunicArmor {
nbtData.setByte("f", (byte) 0);
}
if (isJmuping && !player.onGround && player.motionY < 0) {
if (isJumping && !player.onGround && player.motionY < 0) {
player.motionY *= f1;
}