Move purely display data into ScriptItemCustom.Display

This commit is contained in:
somehussar committed 2025-02-11 22:39:08 +01:00
1 parent adef51cd53
commit 9188499e7e
4 files changed
+115 -107

No files matched your search

@@ -46,7 +46,7 @@ public class CustomItemRenderer implements IItemRenderer {
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack);
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.texture);
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture);
if (!imageData.imageLoaded()) {
return;
}
@@ -64,34 +64,34 @@ public class CustomItemRenderer implements IItemRenderer {
if (!entityItem.ignoreFrustumCheck) {
entityItem.ignoreFrustumCheck = true;
float entityXZSize = (float) Math.sqrt(Math.pow(scriptCustomItem.scaleX,2) + Math.pow(scriptCustomItem.scaleZ,2));
this.setEntitySize(entityItem, entityXZSize * 0.25F, scriptCustomItem.scaleY * 0.25F);
float entityXZSize = (float) Math.sqrt(Math.pow(scriptCustomItem.itemDisplay.scaleX,2) + Math.pow(scriptCustomItem.itemDisplay.scaleZ,2));
this.setEntitySize(entityItem, entityXZSize * 0.25F, scriptCustomItem.itemDisplay.scaleY * 0.25F);
double XSize = entityItem.boundingBox.maxX - entityItem.boundingBox.minX;
double YSize = entityItem.boundingBox.maxY - entityItem.boundingBox.minY;
double ZSize = entityItem.boundingBox.maxZ - entityItem.boundingBox.minZ;
entityItem.boundingBox.maxX = entityItem.boundingBox.minX + XSize * scriptCustomItem.scaleX;
entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * scriptCustomItem.scaleY;
entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * scriptCustomItem.scaleZ;
entityItem.boundingBox.maxX = entityItem.boundingBox.minX + XSize * scriptCustomItem.itemDisplay.scaleX;
entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * scriptCustomItem.itemDisplay.scaleY;
entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * scriptCustomItem.itemDisplay.scaleZ;
}
float entityRenderTicks = Minecraft.getMinecraft().timer.renderPartialTicks;
float bobbing = MathHelper.sin(((float)entityItem.age + entityRenderTicks) / 10.0F + entityItem.hoverStart) * 0.1F + 0.1F;
if(!scriptCustomItem.isNormalItem){
GL11.glRotatef(scriptCustomItem.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZ, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZ, 0, 0, 1);
}
GL11.glRotatef(scriptCustomItem.rotationXRate * entityRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.rotationYRate * entityRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZRate * entityRenderTicks %360, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationXRate * entityRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationYRate * entityRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZRate * entityRenderTicks %360, 0, 0, 1);
if (!renderInFrame) {
if(!scriptCustomItem.isNormalItem){
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
GL11.glTranslatef(0.0F, (Math.max(scriptCustomItem.scaleY, 1) - 1) * (1.0F / 4), 0.0F);
GL11.glScalef(scriptCustomItem.itemDisplay.scaleX, scriptCustomItem.itemDisplay.scaleY, scriptCustomItem.itemDisplay.scaleZ);
GL11.glTranslatef(0.0F, (Math.max(scriptCustomItem.itemDisplay.scaleY, 1) - 1) * (1.0F / 4), 0.0F);
}
GL11.glTranslatef(0.0F, -bobbing, 0.0F);
}
@@ -144,23 +144,23 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glRotatef(-80, 0, 1, 0);
GL11.glRotatef(80, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.rotationXRate * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.rotationYRate * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZRate * item3dRenderTicks %360, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationXRate * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationYRate * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZRate * item3dRenderTicks %360, 0, 0, 1);
GL11.glScalef(0.6F, 0.6F,0.6F);
}
else {
GL11.glTranslatef(scriptCustomItem.translateX, scriptCustomItem.translateY, scriptCustomItem.translateZ);
GL11.glRotatef(scriptCustomItem.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZ, 0, 0, 1);
GL11.glTranslatef(scriptCustomItem.itemDisplay.translateX, scriptCustomItem.itemDisplay.translateY, scriptCustomItem.itemDisplay.translateZ);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZ, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.rotationXRate * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.rotationYRate * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZRate * item3dRenderTicks %360, 0, 0, 1);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationXRate * item3dRenderTicks %360, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationYRate * item3dRenderTicks %360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.itemDisplay.rotationZRate * item3dRenderTicks %360, 0, 0, 1);
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
GL11.glScalef(scriptCustomItem.itemDisplay.scaleX, scriptCustomItem.itemDisplay.scaleY, scriptCustomItem.itemDisplay.scaleZ);
}
int color = scriptCustomItem.getColor();
@@ -230,7 +230,7 @@ public class CustomItemRenderer implements IItemRenderer {
int pass = 0;
GL11.glPushMatrix();
ClientCacheHandler.getImageData(scriptCustomItem.texture).bindTexture();
ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture).bindTexture();
if (renderInFrame)
{
@@ -277,7 +277,7 @@ public class CustomItemRenderer implements IItemRenderer {
}
if(!scriptCustomItem.isNormalItem)
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
GL11.glScalef(scriptCustomItem.itemDisplay.scaleX, scriptCustomItem.itemDisplay.scaleY, scriptCustomItem.itemDisplay.scaleZ);
GL11.glTranslatef(-f7, -f8, -((f9 + f10) * (float)b0 / 2.0F));
for (int k = 0; k < b0; ++k)
@@ -289,7 +289,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
}*/
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.texture);
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture);
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, imageData.getTotalWidth(), imageData.getTotalHeight(), f9);
if (itemStack.hasEffect(pass))
@@ -389,7 +389,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
ClientCacheHandler.getImageData(scriptCustomItem.texture).bindTexture();
ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture).bindTexture();
renderCustomItemSlot(0,0,16,16, itemRed, itemGreen, itemBlue);
GL11.glEnable(GL11.GL_LIGHTING);
@@ -464,7 +464,7 @@ public class CustomItemRenderer implements IItemRenderer {
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
ClientCacheHandler.getImageData(scriptCustomItem.texture).bindTexture();
ClientCacheHandler.getImageData(scriptCustomItem.itemDisplay.texture).bindTexture();
Tessellator tessellator = Tessellator.instance;
IIcon icon = entityLivingBase.getItemIcon(itemStack, par3);
@@ -519,7 +519,7 @@ public class CustomItemRenderer implements IItemRenderer {
public static void renderCustomItemIn2D(ItemStack itemStack, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_)
{
ImageData imageData = ClientCacheHandler.getImageData(ItemScripted.GetWrapper(itemStack).texture);
ImageData imageData = ClientCacheHandler.getImageData(ItemScripted.GetWrapper(itemStack).itemDisplay.texture);
int width = imageData.getTotalWidth();
int height = imageData.getTotalHeight();
@@ -82,7 +82,7 @@ public class ItemLinked extends Item implements ItemRenderInterface {
public boolean showDurabilityBar(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptCustomItem && (new ScriptCustomItem(stack)).durabilityShow;
return istack instanceof ScriptCustomItem && (new ScriptCustomItem(stack)).itemDisplay.durabilityShow;
}
public double getDurabilityForDisplay(ItemStack stack) {
@@ -153,6 +153,6 @@ public class ItemLinked extends Item implements ItemRenderInterface {
public void renderSpecial() {}
public void renderOffset(ScriptCustomItem scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.scaleX, 0.2F * scriptCustomItem.scaleY, 0.07F * scriptCustomItem.scaleZ);
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
}
}
@@ -89,7 +89,7 @@ public class ItemScripted extends Item implements ItemRenderInterface {
public boolean showDurabilityBar(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptCustomItem && (new ScriptCustomItem(stack)).durabilityShow;
return istack instanceof ScriptCustomItem && (new ScriptCustomItem(stack)).itemDisplay.durabilityShow;
}
public double getDurabilityForDisplay(ItemStack stack) {
@@ -160,6 +160,6 @@ public class ItemScripted extends Item implements ItemRenderInterface {
public void renderSpecial() {}
public void renderOffset(ScriptCustomItem scriptCustomItem) {
GL11.glTranslatef(0.135F * scriptCustomItem.scaleX, 0.2F * scriptCustomItem.scaleY, 0.07F * scriptCustomItem.scaleZ);
GL11.glTranslatef(0.135F * scriptCustomItem.itemDisplay.scaleX, 0.2F * scriptCustomItem.itemDisplay.scaleY, 0.07F * scriptCustomItem.itemDisplay.scaleZ);
}
}
@@ -21,10 +21,7 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
public boolean enabled = false;
public boolean loaded = false;
public boolean durabilityShow = false;
public double durabilityValue = 1.0D;
public int durabilityColor = -1;
public int itemColor = 0x8B4513;
public int stackSize = 64;
public int maxItemUseDuration = 20;
@@ -36,12 +33,11 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
public int enchantability;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public float translateX, translateY, translateZ;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public float rotationXRate, rotationYRate, rotationZRate;
// TODO: Move to ItemDisplay
public Display itemDisplay = new Display();
// END_TODO
public long lastInited = -1;
public ScriptCustomItem(ItemStack item) {
@@ -148,13 +144,13 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
public String getTexture() {
return this.texture == null ? "" : this.texture;
return this.itemDisplay.texture == null ? "" : this.itemDisplay.texture;
}
public void setTexture(String texture){
if(texture == null)
texture = "";
this.texture = texture;
this.itemDisplay.texture = texture;
saveItemData();
}
@@ -218,29 +214,29 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
public boolean getDurabilityShow() {
return this.durabilityShow;
return this.itemDisplay.durabilityShow;
}
public void setDurabilityShow(boolean bo) {
this.durabilityShow = bo;
this.itemDisplay.durabilityShow = bo;
saveItemData();
}
public int getDurabilityColor() {
return this.durabilityColor;
return this.itemDisplay.durabilityColor;
}
public void setDurabilityColor(int color) {
this.durabilityColor = color;
this.itemDisplay.durabilityColor = color;
saveItemData();
}
public int getColor() {
return this.itemColor;
return this.itemDisplay.itemColor;
}
public void setColor(int color) {
this.itemColor = color;
this.itemDisplay.itemColor = color;
saveItemData();
}
@@ -272,79 +268,79 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
public void setRotation(float rotationX, float rotationY, float rotationZ){
this.rotationX = rotationX;
this.rotationY = rotationY;
this.rotationZ = rotationZ;
this.itemDisplay.rotationX = rotationX;
this.itemDisplay.rotationY = rotationY;
this.itemDisplay.rotationZ = rotationZ;
saveItemData();
}
public void setRotationRate(float rotationXRate, float rotationYRate, float rotationZRate){
this.rotationXRate = rotationXRate;
this.rotationYRate = rotationYRate;
this.rotationZRate = rotationZRate;
this.itemDisplay.rotationXRate = rotationXRate;
this.itemDisplay.rotationYRate = rotationYRate;
this.itemDisplay.rotationZRate = rotationZRate;
saveItemData();
}
public void setScale(float scaleX, float scaleY, float scaleZ){
this.scaleX = scaleX;
this.scaleY = scaleY;
this.scaleZ = scaleZ;
this.itemDisplay.scaleX = scaleX;
this.itemDisplay.scaleY = scaleY;
this.itemDisplay.scaleZ = scaleZ;
saveItemData();
}
public void setTranslate(float translateX, float translateY, float translateZ){
this.translateX = translateX;
this.translateY = translateY;
this.translateZ = translateZ;
this.itemDisplay.translateX = translateX;
this.itemDisplay.translateY = translateY;
this.itemDisplay.translateZ = translateZ;
saveItemData();
}
public float getRotationX() {
return rotationX;
return this.itemDisplay.rotationX;
}
public float getRotationY() {
return rotationY;
return this.itemDisplay.rotationY;
}
public float getRotationZ() {
return rotationZ;
return this.itemDisplay.rotationZ;
}
public float getRotationXRate() {
return rotationXRate;
return this.itemDisplay.rotationXRate;
}
public float getRotationYRate() {
return rotationYRate;
return this.itemDisplay.rotationYRate;
}
public float getRotationZRate() {
return rotationZRate;
return this.itemDisplay.rotationZRate;
}
public float getScaleX() {
return scaleX;
return this.itemDisplay.scaleX;
}
public float getScaleY() {
return scaleY;
return this.itemDisplay.scaleY;
}
public float getScaleZ() {
return scaleZ;
return this.itemDisplay.scaleZ;
}
public float getTranslateX() {
return translateX;
return this.itemDisplay.translateX;
}
public float getTranslateY() {
return translateY;
return this.itemDisplay.translateY;
}
public float getTranslateZ() {
return translateZ;
return this.itemDisplay.translateZ;
}
public NBTTagCompound getMCNbt() {
@@ -360,28 +356,28 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
compound.setBoolean("DurabilityShow",this.durabilityShow);
compound.setBoolean("DurabilityShow",this.itemDisplay.durabilityShow);
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("DurabilityColor",this.durabilityColor );
compound.setInteger("ItemColor",this.itemColor);
compound.setInteger("DurabilityColor",this.itemDisplay.durabilityColor );
compound.setInteger("ItemColor",this.itemDisplay.itemColor);
compound.setInteger("MaxStackSize",this.stackSize);
compound.setString("ItemTexture",this.texture);
compound.setString("ItemTexture",this.itemDisplay.texture);
compound.setFloat("RotationX",this.rotationX);
compound.setFloat("RotationY",this.rotationY);
compound.setFloat("RotationZ",this.rotationZ);
compound.setFloat("RotationX",this.itemDisplay.rotationX);
compound.setFloat("RotationY",this.itemDisplay.rotationY);
compound.setFloat("RotationZ",this.itemDisplay.rotationZ);
compound.setFloat("RotationXRate",this.rotationXRate);
compound.setFloat("RotationYRate",this.rotationYRate);
compound.setFloat("RotationZRate",this.rotationZRate);
compound.setFloat("RotationXRate",this.itemDisplay.rotationXRate);
compound.setFloat("RotationYRate",this.itemDisplay.rotationYRate);
compound.setFloat("RotationZRate",this.itemDisplay.rotationZRate);
compound.setFloat("ScaleX",this.scaleX);
compound.setFloat("ScaleY",this.scaleY);
compound.setFloat("ScaleZ",this.scaleZ);
compound.setFloat("ScaleX",this.itemDisplay.scaleX);
compound.setFloat("ScaleY",this.itemDisplay.scaleY);
compound.setFloat("ScaleZ",this.itemDisplay.scaleZ);
compound.setFloat("TranslateX",this.translateX);
compound.setFloat("TranslateY",this.translateY);
compound.setFloat("TranslateZ",this.translateZ);
compound.setFloat("TranslateX",this.itemDisplay.translateX);
compound.setFloat("TranslateY",this.itemDisplay.translateY);
compound.setFloat("TranslateZ",this.itemDisplay.translateZ);
compound.setBoolean("IsTool", this.isTool);
compound.setBoolean("IsNormalItem", this.isNormalItem);
@@ -395,30 +391,30 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
}
public void setItemNBT(NBTTagCompound compound) {
this.durabilityShow = compound.getBoolean("DurabilityShow");
this.itemDisplay.durabilityShow = compound.getBoolean("DurabilityShow");
this.durabilityValue = compound.getDouble("DurabilityValue");
if (compound.hasKey("DurabilityColor")) {
this.durabilityColor = compound.getInteger("DurabilityColor");
this.itemDisplay.durabilityColor = compound.getInteger("DurabilityColor");
}
this.itemColor = compound.getInteger("ItemColor");
this.itemDisplay.itemColor = compound.getInteger("ItemColor");
this.stackSize = compound.getInteger("MaxStackSize");
this.texture = compound.getString("ItemTexture");
this.itemDisplay.texture = compound.getString("ItemTexture");
this.rotationX = compound.getFloat("RotationX");
this.rotationY = compound.getFloat("RotationY");
this.rotationZ = compound.getFloat("RotationZ");
this.itemDisplay.rotationX = compound.getFloat("RotationX");
this.itemDisplay.rotationY = compound.getFloat("RotationY");
this.itemDisplay.rotationZ = compound.getFloat("RotationZ");
this.rotationXRate = compound.getFloat("RotationXRate");
this.rotationYRate = compound.getFloat("RotationYRate");
this.rotationZRate = compound.getFloat("RotationZRate");
this.itemDisplay.rotationXRate = compound.getFloat("RotationXRate");
this.itemDisplay.rotationYRate = compound.getFloat("RotationYRate");
this.itemDisplay.rotationZRate = compound.getFloat("RotationZRate");
this.scaleX = compound.getFloat("ScaleX");
this.scaleY = compound.getFloat("ScaleY");
this.scaleZ = compound.getFloat("ScaleZ");
this.itemDisplay.scaleX = compound.getFloat("ScaleX");
this.itemDisplay.scaleY = compound.getFloat("ScaleY");
this.itemDisplay.scaleZ = compound.getFloat("ScaleZ");
this.translateX = compound.getFloat("TranslateX");
this.translateY = compound.getFloat("TranslateY");
this.translateZ = compound.getFloat("TranslateZ");
this.itemDisplay.translateX = compound.getFloat("TranslateX");
this.itemDisplay.translateY = compound.getFloat("TranslateY");
this.itemDisplay.translateZ = compound.getFloat("TranslateZ");
this.isTool = compound.getBoolean("IsTool");
this.isNormalItem = compound.getBoolean("IsNormalItem");
@@ -461,4 +457,16 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IN
this.setItemNBT(c.getCompoundTag("ItemData"));
}
}
public static class Display {
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public float translateX, translateY, translateZ;
public int itemColor = 0x8B4513;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public float rotationXRate, rotationYRate, rotationZRate;
public boolean durabilityShow = false;
public int durabilityColor = -1;
}
}