Merge branch 'packet' into animation-events-2

This commit is contained in:
Kam committed 2025-02-14 15:22:59 -05:00
commit 25d917c338
19 files changed
+1029 -773

No files matched your search

@@ -7,6 +7,7 @@ import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.NpcAPI;
@@ -16,7 +17,7 @@ import javax.script.ScriptEngine;
import java.io.IOException;
import java.util.*;
public class EffectScript implements IScriptHandler {
public class EffectScript implements INpcScriptHandler {
public ScriptContainer container;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
@@ -50,7 +51,12 @@ public class EffectScript implements IScriptHandler {
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
}
@Override
@Override
public void callScript(EnumScriptType type, Event event) {
this.callScript(type.function, event);
}
@Override
public void callScript(String s, Event event) {
if (!this.isEnabled()) {
return;
@@ -0,0 +1,120 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
public class ItemDisplayData {
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;
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
this.writeToNBT(compound);
return compound;
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
this.setBoolean(compound, "DurabilityShow", this.durabilityShow);
this.setInteger(compound, "DurabilityColor", this.durabilityColor);
this.setInteger(compound, "ItemColor", this.itemColor);
if (this.texture != null) {
compound.setString("ItemTexture", this.texture);
}
this.setFloat(compound, "RotationX", this.rotationX);
this.setFloat(compound, "RotationY", this.rotationY);
this.setFloat(compound, "RotationZ", this.rotationZ);
this.setFloat(compound, "RotationXRate", this.rotationXRate);
this.setFloat(compound, "RotationYRate", this.rotationYRate);
this.setFloat(compound, "RotationZRate", this.rotationZRate);
this.setFloat(compound, "ScaleX", this.scaleX);
this.setFloat(compound, "ScaleY", this.scaleY);
this.setFloat(compound, "ScaleZ", this.scaleZ);
this.setFloat(compound, "TranslateX", this.translateX);
this.setFloat(compound, "TranslateY", this.translateY);
this.setFloat(compound, "TranslateZ", this.translateZ);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
if (compound.hasKey("DurabilityShow")) {
this.durabilityShow = compound.getBoolean("DurabilityShow");
}
if (compound.hasKey("DurabilityColor")) {
this.durabilityColor = compound.getInteger("DurabilityColor");
}
if (compound.hasKey("ItemColor")) {
this.itemColor = compound.getInteger("ItemColor");
}
if (compound.hasKey("ItemTexture")) {
this.texture = compound.getString("ItemTexture");
}
if (compound.hasKey("RotationX")) {
this.rotationX = compound.getFloat("RotationX");
}
if (compound.hasKey("RotationY")) {
this.rotationY = compound.getFloat("RotationY");
}
if (compound.hasKey("RotationZ")) {
this.rotationZ = compound.getFloat("RotationZ");
}
if (compound.hasKey("RotationXRate")) {
this.rotationXRate = compound.getFloat("RotationXRate");
}
if (compound.hasKey("RotationYRate")) {
this.rotationYRate = compound.getFloat("RotationYRate");
}
if (compound.hasKey("RotationZRate")) {
this.rotationZRate = compound.getFloat("RotationZRate");
}
if (compound.hasKey("ScaleX")) {
this.scaleX = compound.getFloat("ScaleX");
}
if (compound.hasKey("ScaleY")) {
this.scaleY = compound.getFloat("ScaleY");
}
if (compound.hasKey("ScaleZ")) {
this.scaleZ = compound.getFloat("ScaleZ");
}
if (compound.hasKey("TranslateX")) {
this.translateX = compound.getFloat("TranslateX");
}
if (compound.hasKey("TranslateY")) {
this.translateY = compound.getFloat("TranslateY");
}
if (compound.hasKey("TranslateZ")) {
this.translateZ = compound.getFloat("TranslateZ");
}
}
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);
}
}
}
@@ -0,0 +1,100 @@
package noppes.npcs.controllers.data;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import noppes.npcs.CustomItems;
import noppes.npcs.controllers.LinkedItemController;
public class LinkedItem {
public static final String LINKED_NBT_TAG = "LinkedId";
private int id = -1;
private String name;
public final ItemDisplayData display = new ItemDisplayData();
public double durabilityValue = 1.0D;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public int itemUseAction = 0; //0: none, 1: block, 2: bow, 3: eat, 4: drink
public boolean isNormalItem = false;
public boolean isTool = false;
public int digSpeed = 1;
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 LinkedItem() {
this("New");
}
public LinkedItem(String name) {
this.name = name;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public ItemStack createStack() {
if (LinkedItemController.Instance().contains(this)) {
ItemStack linkedStack = new ItemStack(CustomItems.linked_item);
linkedStack.setTagInfo(LinkedItem.LINKED_NBT_TAG, new NBTTagInt(this.getId()));
return linkedStack;
}
return null;
}
public INpcScriptHandler getScriptHandler() {
return LinkedItemController.Instance().getScriptHandler(this.getId());
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Id", this.id);
compound.setString("Name", this.name);
compound.setTag("Display", this.display.writeToNBT());
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("MaxStackSize",this.stackSize);
compound.setBoolean("IsTool", this.isTool);
compound.setBoolean("IsNormalItem", this.isNormalItem);
compound.setInteger("DigSpeed", this.digSpeed);
compound.setInteger("ArmorType", this.armorType);
compound.setInteger("Enchantability", this.enchantability);
compound.setInteger("MaxItemUseDuration", this.maxItemUseDuration);
compound.setInteger("ItemUseAction", this.itemUseAction);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
this.id = compound.hasKey("Id") ? compound.getInteger("Id") : LinkedItemController.Instance().getUnusedId();
this.name = compound.getString("Name");
this.display.readFromNBT(compound.getCompoundTag("Display"));
this.durabilityValue = compound.getDouble("DurabilityValue");
this.stackSize = compound.getInteger("MaxStackSize");
this.isTool = compound.getBoolean("IsTool");
this.isNormalItem = compound.getBoolean("IsNormalItem");
this.digSpeed = compound.getInteger("DigSpeed");
this.armorType = compound.getInteger("ArmorType");
this.enchantability = compound.getInteger("Enchantability");
this.maxItemUseDuration = compound.getInteger("MaxItemUseDuration");
this.itemUseAction = compound.getInteger("ItemUseAction");
}
}
@@ -1,165 +0,0 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.NpcAPI;
import javax.script.ScriptEngine;
import java.io.IOException;
import java.util.*;
public class LinkedItemScript implements IScriptHandler {
public ScriptContainer container;
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setString("ScriptLanguage", scriptLanguage);
compound.setBoolean("ScriptEnabled", enabled);
if (container != null)
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
return compound;
}
public LinkedItemScript readFromNBT(NBTTagCompound compound) {
scriptLanguage = compound.getString("ScriptLanguage");
enabled = compound.getBoolean("ScriptEnabled");
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
container = new ScriptContainer(this);
container.readFromNBT(compound.getCompoundTag("ScriptContent"));
}
return this;
}
public boolean isEnabled() {
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
}
@Override
public void callScript(String s, Event event) {
if (!this.isEnabled()) {
return;
}
ScriptEngine engine = container.engine;
engine.put("API", NpcAPI.Instance());
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
engine.put(engineObjects.getKey(), engineObjects.getValue());
}
container.run(s, event);
}
@Override
public boolean isClient() {
return FMLCommonHandler.instance().getEffectiveSide().isClient();
}
@Override
public boolean getEnabled() {
return this.enabled;
}
@Override
public void setEnabled(boolean b) {
this.enabled = b;
}
@Override
public String getLanguage() {
return this.scriptLanguage;
}
@Override
public void setLanguage(String s) {
this.scriptLanguage = s;
}
@Override
public void setScripts(List<ScriptContainer> list) {
if (list == null || list.isEmpty()) {
container = null;
return;
}
container = list.get(0);
}
@Override
public List<ScriptContainer> getScripts() {
if (container == null)
return new ArrayList<>();
return Collections.singletonList(container);
}
@Override
public String noticeString() {
return "";
}
@Override
public Map<Long, String> getConsoleText() {
TreeMap<Long, String> map = new TreeMap();
int tab = 0;
Iterator var3 = this.getScripts().iterator();
while(var3.hasNext()) {
ScriptContainer script = (ScriptContainer)var3.next();
++tab;
Iterator var5 = script.console.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<Long, String> longStringEntry = (Map.Entry)var5.next();
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + (String)longStringEntry.getValue());
}
}
return map;
}
@Override
public void clearConsole() {
Iterator var1 = this.getScripts().iterator();
while(var1.hasNext()) {
ScriptContainer script = (ScriptContainer)var1.next();
script.console.clear();
}
}
public void saveScript(ByteBuf buffer) throws IOException {
int tab = buffer.readInt();
int totalScripts = buffer.readInt();
if (totalScripts == 0) {
this.container = null;
}
if (tab == 0) {
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
ScriptContainer script = new ScriptContainer(this);
script.readFromNBT(tabCompound);
this.container = script;
} else {
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
this.setLanguage(compound.getString("ScriptLanguage"));
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
if (!ScriptController.Instance.languages.isEmpty()) {
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
} else {
this.setLanguage("ECMAScript");
}
}
this.setEnabled(compound.getBoolean("ScriptEnabled"));
}
}
}