progress on linked items

This commit is contained in:
luisc committed 2025-02-13 18:11:58 -06:00
1 parent fb87e2a72c
commit 44e5c8b4c5
8 files changed
+546 -109

No files matched your search

@@ -48,13 +48,11 @@ import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.controllers.data.*;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.EntityProjectile;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
@@ -64,7 +62,6 @@ import noppes.npcs.util.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ExecutorService;
@@ -473,7 +470,11 @@ public class NpcAPI extends AbstractNpcAPI {
if (scriptItemCache.containsKey(itemstack)) {
scriptStack = scriptItemCache.get(itemstack).getObject();
} else {
if (itemstack.getItem() instanceof ItemScripted) {
String linkedItemName = itemstack.getTagCompound().getString(LinkedItem.LINKED_NBT_TAG);
LinkedItem linkedItem = LinkedItemController.Instance().get(linkedItemName);
if (linkedItem != null && itemstack.getItem() instanceof ItemLinked) {
scriptStack = new ScriptLinkedItem(itemstack);
} else if (itemstack.getItem() instanceof ItemScripted) {
scriptStack = new ScriptCustomItem(itemstack);
} else if (itemstack.getItem() instanceof ItemArmor) {
scriptStack = new ScriptItemArmor(itemstack);
@@ -2,9 +2,10 @@ package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.data.ItemDisplayData;
public abstract class ScriptCustomizableItem extends ScriptItemStack {
public final Display itemDisplay = new Display();
public final ItemDisplayData itemDisplay = new ItemDisplayData();
public ScriptCustomizableItem(ItemStack item) {
super(item);
@@ -188,112 +189,12 @@ public abstract class ScriptCustomizableItem extends ScriptItemStack {
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
this.setBoolean(compound, "DurabilityShow",this.itemDisplay.durabilityShow);
this.setInteger(compound, "DurabilityColor",this.itemDisplay.durabilityColor);
this.setInteger(compound, "ItemColor",this.itemDisplay.itemColor);
if (this.itemDisplay.texture != null) {
compound.setString("ItemTexture", this.itemDisplay.texture);
}
this.setFloat(compound, "RotationX",this.itemDisplay.rotationX);
this.setFloat(compound, "RotationY",this.itemDisplay.rotationY);
this.setFloat(compound, "RotationZ",this.itemDisplay.rotationZ);
this.setFloat(compound, "RotationXRate",this.itemDisplay.rotationXRate);
this.setFloat(compound, "RotationYRate",this.itemDisplay.rotationYRate);
this.setFloat(compound, "RotationZRate",this.itemDisplay.rotationZRate);
this.setFloat(compound, "ScaleX",this.itemDisplay.scaleX);
this.setFloat(compound, "ScaleY",this.itemDisplay.scaleY);
this.setFloat(compound, "ScaleZ",this.itemDisplay.scaleZ);
this.setFloat(compound, "TranslateX",this.itemDisplay.translateX);
this.setFloat(compound, "TranslateY",this.itemDisplay.translateY);
this.setFloat(compound, "TranslateZ",this.itemDisplay.translateZ);
this.itemDisplay.writeToNBT(compound);
return compound;
}
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
if (value != null) {
compound.setBoolean(key, value);
}
}
private void setInteger(NBTTagCompound compound, String key, Integer value) {
if (value != null) {
compound.setInteger(key, value);
}
}
private void setFloat(NBTTagCompound compound, String key, Float value) {
if (value != null) {
compound.setFloat(key, value);
}
}
public void setItemNBT(NBTTagCompound compound) {
if (compound.hasKey("DurabilityShow")) {
this.itemDisplay.durabilityShow = compound.getBoolean("DurabilityShow");
}
if (compound.hasKey("DurabilityColor")) {
this.itemDisplay.durabilityColor = compound.getInteger("DurabilityColor");
}
if (compound.hasKey("ItemColor")) {
this.itemDisplay.itemColor = compound.getInteger("ItemColor");
}
if (compound.hasKey("ItemTexture")) {
this.itemDisplay.texture = compound.getString("ItemTexture");
}
if (compound.hasKey("RotationX")) {
this.itemDisplay.rotationX = compound.getFloat("RotationX");
}
if (compound.hasKey("RotationY")) {
this.itemDisplay.rotationY = compound.getFloat("RotationY");
}
if (compound.hasKey("RotationZ")) {
this.itemDisplay.rotationZ = compound.getFloat("RotationZ");
}
if (compound.hasKey("RotationXRate")) {
this.itemDisplay.rotationXRate = compound.getFloat("RotationXRate");
}
if (compound.hasKey("RotationYRate")) {
this.itemDisplay.rotationYRate = compound.getFloat("RotationYRate");
}
if (compound.hasKey("RotationZRate")) {
this.itemDisplay.rotationZRate = compound.getFloat("RotationZRate");
}
if (compound.hasKey("ScaleX")) {
this.itemDisplay.scaleX = compound.getFloat("ScaleX");
}
if (compound.hasKey("ScaleY")) {
this.itemDisplay.scaleY = compound.getFloat("ScaleY");
}
if (compound.hasKey("ScaleZ")) {
this.itemDisplay.scaleZ = compound.getFloat("ScaleZ");
}
if (compound.hasKey("TranslateX")) {
this.itemDisplay.translateX = compound.getFloat("TranslateX");
}
if (compound.hasKey("TranslateY")) {
this.itemDisplay.translateY = compound.getFloat("TranslateY");
}
if (compound.hasKey("TranslateZ")) {
this.itemDisplay.translateZ = compound.getFloat("TranslateZ");
}
this.itemDisplay.readFromNBT(compound);
}
public static class Display {
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public Float translateX = 0F, translateY = 0F, translateZ = 0F;
public Integer itemColor = 0x8B4513;
public Float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public Float rotationX = 0F, rotationY = 0F, rotationZ = 0F;
public Float rotationXRate = 0F, rotationYRate = 0F, rotationZRate = 0F;
public Boolean durabilityShow = false;
public Integer durabilityColor = -1;
}
}
@@ -0,0 +1,145 @@
package noppes.npcs.scripted.item;
import net.minecraft.item.ItemStack;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.data.LinkedItem;
public class ScriptLinkedItem extends ScriptCustomizableItem {
private final LinkedItem linkedItem;
public ScriptLinkedItem(ItemStack item) {
super(item);
String linkedItemName = item.getTagCompound().getString(LinkedItem.LINKED_NBT_TAG);
this.linkedItem = LinkedItemController.Instance().get(linkedItemName);
this.itemDisplay.texture = null;
this.itemDisplay.translateX = null;
this.itemDisplay.translateY = null;
this.itemDisplay.translateZ = null;
this.itemDisplay.itemColor = null;
this.itemDisplay.scaleX = null;
this.itemDisplay.scaleY = null;
this.itemDisplay.scaleZ = null;
this.itemDisplay.rotationX = null;
this.itemDisplay.rotationY = null;
this.itemDisplay.rotationZ = null;
this.itemDisplay.rotationXRate = null;
this.itemDisplay.rotationYRate = null;
this.itemDisplay.rotationZRate = null;
this.itemDisplay.durabilityShow = null;
this.itemDisplay.durabilityColor = null;
}
public LinkedItem getLinkedItem() {
return this.linkedItem;
}
@Override
public int getMaxStackSize() {
return this.linkedItem.stackSize;
}
@Override
public int getArmorType() {
return this.linkedItem.armorType;
}
@Override
public boolean isTool() {
return this.linkedItem.isTool;
}
@Override
public boolean isNormalItem() {
return this.linkedItem.isNormalItem;
}
@Override
public int getDigSpeed() {
return this.linkedItem.digSpeed;
}
@Override
public double getDurabilityValue() {
return this.linkedItem.durabilityValue;
}
@Override
public int getMaxItemUseDuration() {
return this.linkedItem.maxItemUseDuration;
}
@Override
public int getItemUseAction() {
return this.linkedItem.itemUseAction;
}
@Override
public int getEnchantability() {
return this.linkedItem.enchantability;
}
public String getTexture() {
return this.itemDisplay.texture == null ? this.linkedItem.display.texture : this.itemDisplay.texture;
}
public Boolean getDurabilityShow() {
return this.itemDisplay.durabilityShow != null ? this.itemDisplay.durabilityShow : this.linkedItem.display.durabilityShow;
}
public Integer getDurabilityColor() {
return this.itemDisplay.durabilityColor != null ? this.itemDisplay.durabilityColor : this.linkedItem.display.durabilityColor;
}
public Integer getColor() {
return this.itemDisplay.itemColor != null ? this.itemDisplay.itemColor : this.linkedItem.display.itemColor;
}
public Float getRotationX() {
return this.itemDisplay.rotationX != null ? this.itemDisplay.rotationX : this.linkedItem.display.rotationX;
}
public Float getRotationY() {
return this.itemDisplay.rotationY != null ? this.itemDisplay.rotationY : this.linkedItem.display.rotationY;
}
public Float getRotationZ() {
return this.itemDisplay.rotationZ != null ? this.itemDisplay.rotationZ : this.linkedItem.display.rotationZ;
}
public Float getRotationXRate() {
return this.itemDisplay.rotationXRate != null ? this.itemDisplay.rotationXRate : this.linkedItem.display.rotationXRate;
}
public Float getRotationYRate() {
return this.itemDisplay.rotationYRate != null ? this.itemDisplay.rotationYRate : this.linkedItem.display.rotationYRate;
}
public Float getRotationZRate() {
return this.itemDisplay.rotationZRate != null ? this.itemDisplay.rotationZRate : this.linkedItem.display.rotationZRate;
}
public Float getScaleX() {
return this.itemDisplay.scaleX != null ? this.itemDisplay.scaleX : this.linkedItem.display.scaleX;
}
public Float getScaleY() {
return this.itemDisplay.scaleY != null ? this.itemDisplay.scaleY : this.linkedItem.display.scaleY;
}
public Float getScaleZ() {
return this.itemDisplay.scaleZ != null ? this.itemDisplay.scaleZ : this.linkedItem.display.scaleZ;
}
public Float getTranslateX() {
return this.itemDisplay.translateX != null ? this.itemDisplay.translateX : this.linkedItem.display.translateX;
}
public Float getTranslateY() {
return this.itemDisplay.translateY != null ? this.itemDisplay.translateY : this.linkedItem.display.translateY;
}
public Float getTranslateZ() {
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : this.linkedItem.display.translateZ;
}
}