mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 17:34:26 +00:00
Compare commits
30
Commits
1.10
...
java21-scripting
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba2721d3df | ||
|
|
b1f5f90915 | ||
|
|
b4aab454fe | ||
|
|
a7706b5e72 | ||
|
|
92afb0a69e | ||
|
|
5e7828ff66 | ||
|
|
e973605be6 | ||
|
|
0b60f4b455 | ||
|
|
43154bba15 | ||
|
|
5d2b667aa6 | ||
|
|
96496a40e2 | ||
|
|
77ef063198 | ||
|
|
fe1c21582a | ||
|
|
49757c7cb5 | ||
|
|
ce9941e3ee | ||
|
|
7b6c7c1c33 | ||
|
|
b848dc0d7a | ||
|
|
e9f810dc21 | ||
|
|
20583d9b0d | ||
|
|
2b6f63a3e3 | ||
|
|
b86c1ceabb | ||
|
|
07640d9b6b | ||
|
|
f2c7121912 | ||
|
|
44b3ddedd8 | ||
|
|
b490e04bb0 | ||
|
|
99616854a7 | ||
|
|
236b901e61 | ||
|
|
810e29ca75 | ||
|
|
d119a7524e | ||
|
|
2b5fcc12cc |
No files matched your search
+7
-1
@@ -5,7 +5,13 @@ plugins {
|
|||||||
id 'idea'
|
id 'idea'
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "1.10"
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion.set(JavaLanguageVersion.of(8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
version = "1.10.2"
|
||||||
group= "kamkeel.customnpc-plus"
|
group= "kamkeel.customnpc-plus"
|
||||||
archivesBaseName = "CustomNPC-Plus"
|
archivesBaseName = "CustomNPC-Plus"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@
|
|||||||
def embedMixin = !project.hasProperty("nomixin");
|
def embedMixin = !project.hasProperty("nomixin");
|
||||||
dependencies {
|
dependencies {
|
||||||
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
|
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
|
||||||
runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
// runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
||||||
|
|
||||||
if(embedMixin){
|
if(embedMixin){
|
||||||
// Normal Jar will include built in Mixins
|
// Normal Jar will include built in Mixins
|
||||||
|
|||||||
+1
-1
Submodule src/api updated: 445fc594f3...bbbea878fe.
@@ -230,6 +230,10 @@ public class PacketUtil {
|
|||||||
tabCompound.setInteger("TotalScripts", containers.size());
|
tabCompound.setInteger("TotalScripts", containers.size());
|
||||||
GuiDataPacket.sendGuiData(player, tabCompound);
|
GuiDataPacket.sendGuiData(player, tabCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NBTTagCompound loadComplete = new NBTTagCompound();
|
||||||
|
loadComplete.setInteger("LoadComplete", 1);
|
||||||
|
GuiDataPacket.sendGuiData(player, loadComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveScripts(IScriptHandler data, ByteBuf buffer) throws IOException {
|
public static void saveScripts(IScriptHandler data, ByteBuf buffer) throws IOException {
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ public final class CustomGuiClosePacket extends AbstractPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||||
if (!(player.openContainer instanceof ContainerCustomGui))
|
|
||||||
return;
|
|
||||||
|
|
||||||
NBTTagCompound comp = ByteBufUtils.readNBT(in);
|
NBTTagCompound comp = ByteBufUtils.readNBT(in);
|
||||||
EventHooks.onCustomGuiClose((IPlayer) NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(comp));
|
EventHooks.onCustomGuiClose((IPlayer) NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(comp));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public final class RoleGetPacket extends AbstractPacket {
|
|||||||
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
compound.setBoolean("RoleData", true);
|
compound.setBoolean("RoleData", true);
|
||||||
|
compound.setInteger("RoleOrdinal", npc.advanced.role.ordinal());
|
||||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.roleInterface.writeToNBT(compound));
|
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.roleInterface.writeToNBT(compound));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ import noppes.npcs.scripted.NpcAPI;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.10")
|
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.10.2")
|
||||||
public class CustomNpcs {
|
public class CustomNpcs {
|
||||||
|
|
||||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||||
|
|||||||
@@ -390,6 +390,11 @@ public class EventHooks {
|
|||||||
return NpcAPI.EVENT_BUS.post(event);
|
return NpcAPI.EVENT_BUS.post(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean onPlayerRightClick(PlayerDataScript handler, PlayerEvent.RightClickEvent event) {
|
||||||
|
handler.callScript(EnumScriptType.RIGHT_CLICK, event);
|
||||||
|
return NpcAPI.EVENT_BUS.post(event);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean onProfileChange(PlayerDataScript handler, IPlayer player, IProfile profile, int newSlot, int prevSlot, boolean post) {
|
public static boolean onProfileChange(PlayerDataScript handler, IPlayer player, IProfile profile, int newSlot, int prevSlot, boolean post) {
|
||||||
PlayerEvent.ProfileEvent.Changed event = new PlayerEvent.ProfileEvent.Changed(player, profile, newSlot, prevSlot, post);
|
PlayerEvent.ProfileEvent.Changed event = new PlayerEvent.ProfileEvent.Changed(player, profile, newSlot, prevSlot, post);
|
||||||
handler.callScript(EnumScriptType.PROFILE_CHANGE, event);
|
handler.callScript(EnumScriptType.PROFILE_CHANGE, event);
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ public class ScriptItemEventHandler {
|
|||||||
|
|
||||||
ItemNpcTool.setColor(held.getTagCompound(), color);
|
ItemNpcTool.setColor(held.getTagCompound(), color);
|
||||||
e.setCanceled(true);
|
e.setCanceled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import net.minecraftforge.event.entity.item.ItemTossEvent;
|
|||||||
import net.minecraftforge.event.entity.living.*;
|
import net.minecraftforge.event.entity.living.*;
|
||||||
import net.minecraftforge.event.entity.player.*;
|
import net.minecraftforge.event.entity.player.*;
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
|
import noppes.npcs.api.IWorld;
|
||||||
import noppes.npcs.api.entity.IPlayer;
|
import noppes.npcs.api.entity.IPlayer;
|
||||||
import noppes.npcs.api.item.IItemCustomizable;
|
import noppes.npcs.api.item.IItemCustomizable;
|
||||||
import noppes.npcs.config.ConfigMain;
|
import noppes.npcs.config.ConfigMain;
|
||||||
@@ -34,8 +35,10 @@ import noppes.npcs.controllers.ScriptController;
|
|||||||
import noppes.npcs.controllers.data.*;
|
import noppes.npcs.controllers.data.*;
|
||||||
import noppes.npcs.entity.EntityNPCInterface;
|
import noppes.npcs.entity.EntityNPCInterface;
|
||||||
import noppes.npcs.items.ItemNpcTool;
|
import noppes.npcs.items.ItemNpcTool;
|
||||||
|
import noppes.npcs.items.ItemScripted;
|
||||||
import noppes.npcs.quests.QuestItem;
|
import noppes.npcs.quests.QuestItem;
|
||||||
import noppes.npcs.scripted.NpcAPI;
|
import noppes.npcs.scripted.NpcAPI;
|
||||||
|
import noppes.npcs.scripted.event.ItemEvent;
|
||||||
|
|
||||||
import static noppes.npcs.config.ConfigMain.TrackedQuestUpdateFrequency;
|
import static noppes.npcs.config.ConfigMain.TrackedQuestUpdateFrequency;
|
||||||
|
|
||||||
@@ -123,9 +126,46 @@ public class ScriptPlayerEventHandler {
|
|||||||
|
|
||||||
if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer && event.entityPlayer instanceof EntityPlayerMP) {
|
if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer && event.entityPlayer instanceof EntityPlayerMP) {
|
||||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.entityPlayer);
|
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.entityPlayer);
|
||||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
|
IPlayer ip = NoppesUtilServer.getIPlayer(event.entityPlayer);
|
||||||
noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent(scriptPlayer, 1, NpcAPI.Instance().getIEntity(event.target));
|
|
||||||
event.setCanceled(EventHooks.onPlayerInteract(handler, ev));
|
noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent rightClickEvent = new noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent(ip, 1, NpcAPI.Instance().getIEntity(event.target));
|
||||||
|
boolean rightClick = EventHooks.onPlayerRightClick(handler, rightClickEvent);
|
||||||
|
|
||||||
|
noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent(ip, 1, NpcAPI.Instance().getIEntity(event.target));
|
||||||
|
boolean interact = EventHooks.onPlayerInteract(handler, ev);
|
||||||
|
|
||||||
|
event.setCanceled(rightClick || interact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void invoke(PlayerInteractEvent event) {
|
||||||
|
if (event.entityPlayer == null || event.entityPlayer.worldObj == null || event.entityPlayer.worldObj.isRemote || !(event.entityPlayer instanceof EntityPlayerMP))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IPlayer ip = NoppesUtilServer.getIPlayer(event.entityPlayer);
|
||||||
|
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.entityPlayer);
|
||||||
|
PlayerData pd = PlayerData.get(event.entityPlayer);
|
||||||
|
if (pd == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR){
|
||||||
|
if (pd.hadInteract) {
|
||||||
|
pd.hadInteract = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent rightClickEvent = new noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent(ip, 0, null);
|
||||||
|
event.setCanceled(EventHooks.onPlayerRightClick(handler, rightClickEvent));
|
||||||
|
} else if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){
|
||||||
|
pd.hadInteract = true;
|
||||||
|
IWorld iw = (IWorld) NpcAPI.Instance().getIWorld(event.world);
|
||||||
|
Object blockCtx = NpcAPI.Instance().getIBlock(iw, event.x, event.y, event.z);
|
||||||
|
noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent rightClickEvent = new noppes.npcs.scripted.event.player.PlayerEvent.RightClickEvent(ip, 2, blockCtx);
|
||||||
|
event.setCanceled(EventHooks.onPlayerRightClick(handler, rightClickEvent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.minecraft.network.Packet;
|
|||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.Facing;
|
||||||
|
|
||||||
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
|
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
|
||||||
|
|
||||||
@@ -18,6 +19,11 @@ public class TileVariant extends TileEntity {
|
|||||||
public int variant = 14;
|
public int variant = 14;
|
||||||
public int rotation;
|
public int rotation;
|
||||||
|
|
||||||
|
// Rotation = 0 Couch is Facing North
|
||||||
|
// Rotation = 1 Couch is Facing East
|
||||||
|
// Rotation = 2 Couch is Facing South
|
||||||
|
// Rotation = 3 Couch is Facing West
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound compound) {
|
public void readFromNBT(NBTTagCompound compound) {
|
||||||
super.readFromNBT(compound);
|
super.readFromNBT(compound);
|
||||||
version = compound.getInteger("CNPCVersion");
|
version = compound.getInteger("CNPCVersion");
|
||||||
|
|||||||
@@ -98,8 +98,6 @@ public class ImageDownloadAlt extends SimpleTexture {
|
|||||||
this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet()) {
|
this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet()) {
|
||||||
public void run() {
|
public void run() {
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
ImageDownloadAlt.logger.debug("Downloading http texture from {} to {}", new Object[]{ImageDownloadAlt.this.imageUrl, ImageDownloadAlt.this.cacheFile});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(ImageDownloadAlt.this.imageUrl);
|
URL url = new URL(ImageDownloadAlt.this.imageUrl);
|
||||||
connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
|||||||
public Map<String, List<String>> languages = new HashMap<String, List<String>>();
|
public Map<String, List<String>> languages = new HashMap<String, List<String>>();
|
||||||
|
|
||||||
private static int activeConsole = 0;
|
private static int activeConsole = 0;
|
||||||
|
boolean loaded = false;
|
||||||
|
|
||||||
public GuiScript(EntityNPCInterface npc) {
|
public GuiScript(EntityNPCInterface npc) {
|
||||||
super(npc);
|
super(npc);
|
||||||
@@ -258,12 +259,15 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
|||||||
}
|
}
|
||||||
this.languages = languages;
|
this.languages = languages;
|
||||||
initGui();
|
initGui();
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
setScript();
|
if(loaded){
|
||||||
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
setScript();
|
||||||
|
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ public class SubGuiMagic extends SubGuiInterface implements ITextfieldListener,
|
|||||||
addLabel(new GuiNpcLabel(50, "magic.interaction", guiLeft + 170, guiTop + 30 + 160 + 5));
|
addLabel(new GuiNpcLabel(50, "magic.interaction", guiLeft + 170, guiTop + 30 + 160 + 5));
|
||||||
interactionField = new GuiNpcTextField(90, this, fontRendererObj, guiLeft + 245, guiTop + 30 + 160, 45, 20, "");
|
interactionField = new GuiNpcTextField(90, this, fontRendererObj, guiLeft + 245, guiTop + 30 + 160, 45, 20, "");
|
||||||
interactionField.setFloatsOnly();
|
interactionField.setFloatsOnly();
|
||||||
|
interactionField.setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0.0f);
|
||||||
|
|
||||||
addTextField(interactionField);
|
addTextField(interactionField);
|
||||||
if (selectedInteraction != null) {
|
if (selectedInteraction != null) {
|
||||||
interactionField.setText(interactionValues.get(selectedInteraction) + "");
|
interactionField.setText(interactionValues.get(selectedInteraction) + "");
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
|||||||
@Override
|
@Override
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
if (compound.hasKey("RoleData")) {
|
if (compound.hasKey("RoleData")) {
|
||||||
|
npc.advanced.setRole(compound.getInteger("RoleOrdinal"));
|
||||||
if (npc.roleInterface != null)
|
if (npc.roleInterface != null)
|
||||||
npc.roleInterface.readFromNBT(compound);
|
npc.roleInterface.readFromNBT(compound);
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
|
if(compound.hasKey("LoadComplete")){
|
||||||
|
loaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compound.hasKey("Tab")) {
|
if (!compound.hasKey("Tab")) {
|
||||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||||
@@ -58,16 +63,18 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
super.save();
|
if(loaded) {
|
||||||
List<ScriptContainer> containers = this.script.getScripts();
|
super.save();
|
||||||
for (int i = 0; i < containers.size(); i++) {
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
ScriptContainer container = containers.get(i);
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
EventScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
ScriptContainer container = containers.get(i);
|
||||||
|
EventScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
|
NBTTagCompound scriptData = new NBTTagCompound();
|
||||||
|
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||||
|
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||||
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||||
|
EventScriptPacket.Save(-1, containers.size(), scriptData);
|
||||||
}
|
}
|
||||||
NBTTagCompound scriptData = new NBTTagCompound();
|
|
||||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
|
||||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
|
||||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
|
||||||
EventScriptPacket.Save(-1, containers.size(), scriptData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,11 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
|
if(compound.hasKey("LoadComplete")){
|
||||||
|
loaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compound.hasKey("Tab")) {
|
if (!compound.hasKey("Tab")) {
|
||||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||||
@@ -54,16 +59,18 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
super.save();
|
if(loaded){
|
||||||
List<ScriptContainer> containers = this.script.getScripts();
|
super.save();
|
||||||
for (int i = 0; i < containers.size(); i++) {
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
ScriptContainer container = containers.get(i);
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
GlobalNPCScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
ScriptContainer container = containers.get(i);
|
||||||
|
GlobalNPCScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
|
NBTTagCompound scriptData = new NBTTagCompound();
|
||||||
|
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||||
|
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||||
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||||
|
GlobalNPCScriptPacket.Save(-1, containers.size(), scriptData);
|
||||||
}
|
}
|
||||||
NBTTagCompound scriptData = new NBTTagCompound();
|
|
||||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
|
||||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
|
||||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
|
||||||
GlobalNPCScriptPacket.Save(-1, containers.size(), scriptData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,10 +30,13 @@ public class GuiScriptBlock extends GuiScriptInterface {
|
|||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
this.tileScripted.setNBT(compound);
|
this.tileScripted.setNBT(compound);
|
||||||
super.setGuiData(compound);
|
super.setGuiData(compound);
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
super.save();
|
if(loaded) {
|
||||||
BlockScriptPacket.Save(tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
|
super.save();
|
||||||
|
BlockScriptPacket.Save(tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
|||||||
public final GuiNPCManageEffects parent;
|
public final GuiNPCManageEffects parent;
|
||||||
public final CustomEffect effect;
|
public final CustomEffect effect;
|
||||||
private final EffectScript scriptHandler;
|
private final EffectScript scriptHandler;
|
||||||
|
boolean loaded = false;
|
||||||
|
|
||||||
public GuiScriptEffect(GuiNPCManageEffects parent, CustomEffect effect) {
|
public GuiScriptEffect(GuiNPCManageEffects parent, CustomEffect effect) {
|
||||||
this.drawDefaultBackground = true;
|
this.drawDefaultBackground = true;
|
||||||
@@ -315,6 +315,11 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
|
if(compound.hasKey("LoadComplete")){
|
||||||
|
loaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compound.hasKey("Tab")) {
|
if (!compound.hasKey("Tab")) {
|
||||||
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
||||||
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||||
@@ -326,7 +331,6 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
|||||||
this.scriptHandler.container = container;
|
this.scriptHandler.container = container;
|
||||||
this.initGui();
|
this.initGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copiedSetGuiData(NBTTagCompound compound) {
|
private void copiedSetGuiData(NBTTagCompound compound) {
|
||||||
@@ -350,19 +354,21 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
this.setScript();
|
if(loaded) {
|
||||||
|
this.setScript();
|
||||||
|
|
||||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||||
for (int i = 0; i < containers.size(); i++) {
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
ScriptContainer container = containers.get(i);
|
ScriptContainer container = containers.get(i);
|
||||||
EffectScriptPacket.Save(effect.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
EffectScriptPacket.Save(effect.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
|
NBTTagCompound scriptData = new NBTTagCompound();
|
||||||
|
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||||
|
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||||
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||||
|
|
||||||
|
EffectScriptPacket.Save(effect.id, -1, containers.size(), scriptData);
|
||||||
}
|
}
|
||||||
NBTTagCompound scriptData = new NBTTagCompound();
|
|
||||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
|
||||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
|
||||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
|
||||||
|
|
||||||
EffectScriptPacket.Save(effect.id, -1, containers.size(), scriptData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void textUpdate(String text) {
|
public void textUpdate(String text) {
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ public class GuiScriptForge extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
|
if(compound.hasKey("LoadComplete")){
|
||||||
|
loaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compound.hasKey("Tab")) {
|
if (!compound.hasKey("Tab")) {
|
||||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||||
@@ -84,16 +89,18 @@ public class GuiScriptForge extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
super.save();
|
if(loaded) {
|
||||||
List<ScriptContainer> containers = this.script.getScripts();
|
super.save();
|
||||||
for (int i = 0; i < containers.size(); i++) {
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
ScriptContainer container = containers.get(i);
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
ForgeScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
ScriptContainer container = containers.get(i);
|
||||||
|
ForgeScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
|
NBTTagCompound scriptData = new NBTTagCompound();
|
||||||
|
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||||
|
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||||
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||||
|
ForgeScriptPacket.Save(-1, containers.size(), scriptData);
|
||||||
}
|
}
|
||||||
NBTTagCompound scriptData = new NBTTagCompound();
|
|
||||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
|
||||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
|
||||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
|
||||||
ForgeScriptPacket.Save(-1, containers.size(), scriptData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
public Map<String, List<String>> languages = new HashMap();
|
public Map<String, List<String>> languages = new HashMap();
|
||||||
private int scriptLimit = 1;
|
private int scriptLimit = 1;
|
||||||
public List<String> hookList = new ArrayList<String>();
|
public List<String> hookList = new ArrayList<String>();
|
||||||
|
protected boolean loaded = false;
|
||||||
|
|
||||||
public GuiScriptInterface() {
|
public GuiScriptInterface() {
|
||||||
this.drawDefaultBackground = true;
|
this.drawDefaultBackground = true;
|
||||||
@@ -338,7 +339,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
this.setScript();
|
if(loaded)
|
||||||
|
this.setScript();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void textUpdate(String text) {
|
public void textUpdate(String text) {
|
||||||
|
|||||||
@@ -44,12 +44,15 @@ public class GuiScriptItem extends GuiScriptInterface {
|
|||||||
this.item.setMCNbt(compound);
|
this.item.setMCNbt(compound);
|
||||||
this.item.loadScriptData();
|
this.item.loadScriptData();
|
||||||
super.setGuiData(compound);
|
super.setGuiData(compound);
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
super.save();
|
if(loaded) {
|
||||||
ItemScriptPacket.Save(this.item.getMCNbt());
|
super.save();
|
||||||
|
ItemScriptPacket.Save(this.item.getMCNbt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConsoleText() {
|
protected String getConsoleText() {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
|||||||
public final GuiNPCManageLinked parent;
|
public final GuiNPCManageLinked parent;
|
||||||
public final LinkedItem linkedItem;
|
public final LinkedItem linkedItem;
|
||||||
private final LinkedItemScript scriptHandler;
|
private final LinkedItemScript scriptHandler;
|
||||||
|
boolean loaded = false;
|
||||||
|
|
||||||
public GuiScriptLinkedItem(GuiNPCManageLinked parent, LinkedItem linkedItem) {
|
public GuiScriptLinkedItem(GuiNPCManageLinked parent, LinkedItem linkedItem) {
|
||||||
this.drawDefaultBackground = true;
|
this.drawDefaultBackground = true;
|
||||||
@@ -326,6 +327,11 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
|
if(compound.hasKey("LoadComplete")){
|
||||||
|
loaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compound.hasKey("Tab")) {
|
if (!compound.hasKey("Tab")) {
|
||||||
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
||||||
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||||
@@ -361,19 +367,21 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
this.setScript();
|
if(loaded) {
|
||||||
|
this.setScript();
|
||||||
|
|
||||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||||
for (int i = 0; i < containers.size(); i++) {
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
ScriptContainer container = containers.get(i);
|
ScriptContainer container = containers.get(i);
|
||||||
LinkedItemScriptPacket.Save(linkedItem.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
LinkedItemScriptPacket.Save(linkedItem.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
|
NBTTagCompound scriptData = new NBTTagCompound();
|
||||||
|
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||||
|
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||||
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||||
|
|
||||||
|
LinkedItemScriptPacket.Save(linkedItem.id, -1, containers.size(), scriptData);
|
||||||
}
|
}
|
||||||
NBTTagCompound scriptData = new NBTTagCompound();
|
|
||||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
|
||||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
|
||||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
|
||||||
|
|
||||||
LinkedItemScriptPacket.Save(linkedItem.id, -1, containers.size(), scriptData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void textUpdate(String text) {
|
public void textUpdate(String text) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
|||||||
hookList.add(EnumScriptType.INIT.function);
|
hookList.add(EnumScriptType.INIT.function);
|
||||||
hookList.add(EnumScriptType.TICK.function);
|
hookList.add(EnumScriptType.TICK.function);
|
||||||
hookList.add(EnumScriptType.INTERACT.function);
|
hookList.add(EnumScriptType.INTERACT.function);
|
||||||
|
hookList.add(EnumScriptType.RIGHT_CLICK.function);
|
||||||
hookList.add(EnumScriptType.ATTACK.function);
|
hookList.add(EnumScriptType.ATTACK.function);
|
||||||
hookList.add(EnumScriptType.ATTACKED.function);
|
hookList.add(EnumScriptType.ATTACKED.function);
|
||||||
hookList.add(EnumScriptType.DAMAGED_ENTITY.function);
|
hookList.add(EnumScriptType.DAMAGED_ENTITY.function);
|
||||||
@@ -90,6 +91,11 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
|
if(compound.hasKey("LoadComplete")){
|
||||||
|
loaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!compound.hasKey("Tab")) {
|
if (!compound.hasKey("Tab")) {
|
||||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||||
@@ -109,16 +115,18 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
super.save();
|
if(loaded) {
|
||||||
List<ScriptContainer> containers = this.script.getScripts();
|
super.save();
|
||||||
for (int i = 0; i < containers.size(); i++) {
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
ScriptContainer container = containers.get(i);
|
for (int i = 0; i < containers.size(); i++) {
|
||||||
PlayerScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
ScriptContainer container = containers.get(i);
|
||||||
|
PlayerScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
|
}
|
||||||
|
NBTTagCompound scriptData = new NBTTagCompound();
|
||||||
|
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||||
|
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||||
|
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||||
|
PlayerScriptPacket.Save(-1, containers.size(), scriptData);
|
||||||
}
|
}
|
||||||
NBTTagCompound scriptData = new NBTTagCompound();
|
|
||||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
|
||||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
|
||||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
|
||||||
PlayerScriptPacket.Save(-1, containers.size(), scriptData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,12 +136,20 @@ public abstract class GuiDiagram extends Gui {
|
|||||||
String nameFrom = iconFrom != null ? getIconName(iconFrom) : "Unknown";
|
String nameFrom = iconFrom != null ? getIconName(iconFrom) : "Unknown";
|
||||||
String nameTo = iconTo != null ? getIconName(iconTo) : "Unknown";
|
String nameTo = iconTo != null ? getIconName(iconTo) : "Unknown";
|
||||||
tooltip.add(nameFrom + " > " + nameTo + ":");
|
tooltip.add(nameFrom + " > " + nameTo + ":");
|
||||||
tooltip.add(conn.hoverText);
|
// Split Hover Text by newlines
|
||||||
|
if (conn.hoverText != null && !conn.hoverText.isEmpty()) {
|
||||||
|
String[] lines = conn.hoverText.split("\n");
|
||||||
|
tooltip.addAll(Arrays.asList(lines));
|
||||||
|
}
|
||||||
if (allowTwoWay) {
|
if (allowTwoWay) {
|
||||||
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
||||||
if (reverse != null) {
|
if (reverse != null) {
|
||||||
tooltip.add(nameTo + " > " + nameFrom + ":");
|
tooltip.add(nameTo + " > " + nameFrom + ":");
|
||||||
tooltip.add(reverse.hoverText);
|
// Split Hover Text by newlines
|
||||||
|
if (reverse.hoverText != null && !reverse.hoverText.isEmpty()) {
|
||||||
|
String[] lines = reverse.hoverText.split("\n");
|
||||||
|
tooltip.addAll(Arrays.asList(lines));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tooltip;
|
return tooltip;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class BlockCouchWoolRenderer extends BlockRendererInterface {
|
|||||||
setCouchWood(var1.getBlockMetadata());
|
setCouchWood(var1.getBlockMetadata());
|
||||||
if (tile.hasCornerLeft) {
|
if (tile.hasCornerLeft) {
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glRotatef(90, 0, 1, 0);
|
GL11.glRotatef(270, 0, 1, 0);
|
||||||
modelCouchCorner.CouchBack.render(0.0625F);
|
modelCouchCorner.CouchBack.render(0.0625F);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
} else if (tile.hasCornerRight)
|
} else if (tile.hasCornerRight)
|
||||||
@@ -119,8 +119,12 @@ public class BlockCouchWoolRenderer extends BlockRendererInterface {
|
|||||||
float[] color = ColorUtil.hexToRGB(tile.color);
|
float[] color = ColorUtil.hexToRGB(tile.color);
|
||||||
GL11.glColor3f(color[0], color[1], color[2]);
|
GL11.glColor3f(color[0], color[1], color[2]);
|
||||||
|
|
||||||
if (tile.hasCornerLeft)
|
if (tile.hasCornerLeft){
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glRotatef(270, 0, 1, 0);
|
||||||
modelCouchCorner.Cussion.render(0.0625F);
|
modelCouchCorner.Cussion.render(0.0625F);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
else if (tile.hasCornerRight)
|
else if (tile.hasCornerRight)
|
||||||
modelCouchCorner.Cussion.render(0.0625F);
|
modelCouchCorner.Cussion.render(0.0625F);
|
||||||
else if (tile.hasLeft && tile.hasRight)
|
else if (tile.hasLeft && tile.hasRight)
|
||||||
|
|||||||
@@ -92,22 +92,20 @@ public class ScriptContainer {
|
|||||||
|
|
||||||
private String getFullCode() {
|
private String getFullCode() {
|
||||||
if (!this.evaluated) {
|
if (!this.evaluated) {
|
||||||
this.fullscript = this.script;
|
// build includes first
|
||||||
if (!this.fullscript.isEmpty()) {
|
StringBuilder sb = new StringBuilder();
|
||||||
this.fullscript = this.fullscript + "\n";
|
for (String loc : this.scripts) {
|
||||||
}
|
String code = ScriptController.Instance.scripts.get(loc);
|
||||||
|
|
||||||
Iterator var1 = this.scripts.iterator();
|
|
||||||
|
|
||||||
while (var1.hasNext()) {
|
|
||||||
String loc = (String) var1.next();
|
|
||||||
String code = (String) ScriptController.Instance.scripts.get(loc);
|
|
||||||
if (code != null && !code.isEmpty()) {
|
if (code != null && !code.isEmpty()) {
|
||||||
this.fullscript = this.fullscript + code + "\n";
|
sb.append(code).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// then your per‐hook script
|
||||||
this.unknownFunctions = new HashSet<String>();
|
if (this.script != null && !this.script.isEmpty()) {
|
||||||
|
sb.append(this.script).append("\n");
|
||||||
|
}
|
||||||
|
this.fullscript = sb.toString();
|
||||||
|
this.unknownFunctions = new HashSet<>();
|
||||||
}
|
}
|
||||||
return this.fullscript;
|
return this.fullscript;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||||
@@ -55,6 +59,7 @@ public class ScriptController {
|
|||||||
|
|
||||||
public GlobalNPCDataScript globalNpcScripts = new GlobalNPCDataScript((EntityNPCInterface) null);
|
public GlobalNPCDataScript globalNpcScripts = new GlobalNPCDataScript((EntityNPCInterface) null);
|
||||||
public long lastGlobalNpcUpdate = 0L;
|
public long lastGlobalNpcUpdate = 0L;
|
||||||
|
private URLClassLoader loader;
|
||||||
|
|
||||||
public ScriptController() {
|
public ScriptController() {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
@@ -64,34 +69,31 @@ public class ScriptController {
|
|||||||
LogWriter.info("Script Engines Available:");
|
LogWriter.info("Script Engines Available:");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.nashornFactory = new NashornScriptEngineFactory();
|
File nashornJar = new File("mods/nashorn.jar"); // Adjust path if needed
|
||||||
LogWriter.info("→ standalone Nashorn loaded");
|
this.loader = new URLClassLoader(new URL[]{nashornJar.toURI().toURL()}, CustomNpcs.class.getClassLoader());
|
||||||
} catch (NoClassDefFoundError e) {
|
|
||||||
|
ClassLoader cl = CustomNpcs.class.getClassLoader();
|
||||||
|
Thread.currentThread().setContextClassLoader(cl);
|
||||||
|
LogWriter.info("ClassLoader: " + cl);
|
||||||
|
LogWriter.info("Parent: " + cl.getParent());
|
||||||
|
|
||||||
|
Class<?> factoryClass = Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory", true, loader);
|
||||||
|
this.nashornFactory = (ScriptEngineFactory) factoryClass.getDeclaredConstructor().newInstance();
|
||||||
|
this.languages.put("ECMAScript", ".js");
|
||||||
|
LogWriter.info("→ standalone Nashorn loaded: " + this.nashornFactory.getEngineName());
|
||||||
|
} catch (Exception e) {
|
||||||
// fallback to built-in (Java 8–11) — also guarded
|
// fallback to built-in (Java 8–11) — also guarded
|
||||||
try {
|
try {
|
||||||
ScriptEngine eng = manager.getEngineByName("nashorn");
|
ScriptEngine eng = manager.getEngineByName("nashorn");
|
||||||
if (eng != null) {
|
if (eng != null) {
|
||||||
this.nashornFactory = eng.getFactory();
|
this.nashornFactory = eng.getFactory();
|
||||||
|
this.languages.put("ECMAScript", ".js");
|
||||||
LogWriter.info("→ built-in Nashorn loaded");
|
LogWriter.info("→ built-in Nashorn loaded");
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LogWriter.error("No Nashorn engine available");
|
LogWriter.error("No Nashorn engine available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ScriptEngineFactory fac : manager.getEngineFactories()) {
|
|
||||||
if (fac.getExtensions().isEmpty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ScriptEngine scriptEngine = fac.getScriptEngine();
|
|
||||||
try {
|
|
||||||
scriptEngine.put("$RunTest", null);
|
|
||||||
String ext = "." + fac.getExtensions().get(0).toLowerCase();
|
|
||||||
LogWriter.info("Engine " + fac.getEngineName() + " running " + fac.getLanguageName() + " with extension: " + ext);
|
|
||||||
languages.put(fac.getLanguageName(), ext);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File forgeScriptsFile() {
|
private File forgeScriptsFile() {
|
||||||
@@ -299,31 +301,113 @@ public class ScriptController {
|
|||||||
|
|
||||||
public ScriptEngine getEngineByName(String language) {
|
public ScriptEngine getEngineByName(String language) {
|
||||||
if (nashornNames.contains(language) && this.nashornFactory != null) {
|
if (nashornNames.contains(language) && this.nashornFactory != null) {
|
||||||
ScriptEngine scriptEngine;
|
try {
|
||||||
if (ConfigScript.EnableBannedClasses) {
|
ScriptEngine scriptEngine;
|
||||||
try {
|
Class<?> factoryClass = Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory",
|
||||||
ClassFilter filter = s -> {
|
true, this.loader);
|
||||||
for (String className : ConfigScript.BannedClasses) {
|
|
||||||
if (s.compareTo(className) == 0) {
|
if (ConfigScript.EnableBannedClasses) {
|
||||||
return false;
|
Class<?> classFilterClass = Class.forName("jdk.nashorn.api.scripting.ClassFilter",
|
||||||
|
true, this.loader);
|
||||||
|
|
||||||
|
Object classFilter = Proxy.newProxyInstance(
|
||||||
|
classFilterClass.getClassLoader(),
|
||||||
|
new Class[]{classFilterClass},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
if ("exposeToScripts".equals(method.getName()) && args.length == 1) {
|
||||||
|
String className = (String) args[0];
|
||||||
|
for (String banned : ConfigScript.BannedClasses) {
|
||||||
|
if (className.equals(banned)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
throw new UnsupportedOperationException("Unsupported method: " + method);
|
||||||
return true;
|
});
|
||||||
};
|
|
||||||
NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory;
|
Method getScriptEngine = factoryClass.getMethod(
|
||||||
scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter);
|
"getScriptEngine",
|
||||||
} catch (Exception e) {
|
classFilterClass);
|
||||||
scriptEngine = this.nashornFactory.getScriptEngine();
|
|
||||||
|
scriptEngine = (ScriptEngine) getScriptEngine.invoke(this.nashornFactory, classFilter);
|
||||||
|
} else {
|
||||||
|
Method getScriptEngine = factoryClass.getMethod("getScriptEngine");
|
||||||
|
scriptEngine = (ScriptEngine) getScriptEngine.invoke(this.nashornFactory);
|
||||||
}
|
}
|
||||||
} else {
|
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
||||||
scriptEngine = this.nashornFactory.getScriptEngine();
|
return scriptEngine;
|
||||||
|
} catch (Exception exception) {
|
||||||
|
LogWriter.except(exception);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
|
||||||
return scriptEngine;
|
|
||||||
}
|
}
|
||||||
return manager.getEngineByName(language);
|
return manager.getEngineByName(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScriptEngine getOpenJDKNashornEngine() {
|
||||||
|
ScriptEngine engine;
|
||||||
|
try {
|
||||||
|
// Load factory and class filter
|
||||||
|
Class<?> factoryClass = Class.forName("org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory");
|
||||||
|
Object factory = factoryClass.getConstructor().newInstance();
|
||||||
|
|
||||||
|
// Load ClassFilter interface (from Nashorn 15.6)
|
||||||
|
Class<?> classFilterClass = Class.forName("org.openjdk.nashorn.api.scripting.ClassFilter");
|
||||||
|
|
||||||
|
Object classFilter;
|
||||||
|
if (ConfigScript.EnableBannedClasses) {
|
||||||
|
// Create proxy instance of ClassFilter
|
||||||
|
classFilter = Proxy.newProxyInstance(
|
||||||
|
classFilterClass.getClassLoader(),
|
||||||
|
new Class[]{classFilterClass},
|
||||||
|
(proxy, method, args) -> {
|
||||||
|
if ("exposeToScripts".equals(method.getName()) && args.length == 1) {
|
||||||
|
String className = (String) args[0];
|
||||||
|
for (String banned : ConfigScript.BannedClasses) {
|
||||||
|
if (className.equals(banned)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException("Unsupported method: " + method);
|
||||||
|
});
|
||||||
|
|
||||||
|
Method getEngineMethod = factoryClass.getMethod(
|
||||||
|
"getScriptEngine",
|
||||||
|
String[].class,
|
||||||
|
ClassLoader.class,
|
||||||
|
classFilterClass
|
||||||
|
);
|
||||||
|
|
||||||
|
String[] args = new String[] {
|
||||||
|
"--language=es6",
|
||||||
|
"--optimistic-types=true",
|
||||||
|
"--lazy-compilation=true"
|
||||||
|
};
|
||||||
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
|
engine = (ScriptEngine) getEngineMethod.invoke(
|
||||||
|
factory,
|
||||||
|
(Object) args,
|
||||||
|
loader,
|
||||||
|
classFilter
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Method getEngineMethod = factoryClass.getMethod("getScriptEngine", String[].class);
|
||||||
|
String[] args = new String[] {
|
||||||
|
"--language=es6",
|
||||||
|
"--optimistic-types=true",
|
||||||
|
"--lazy-compilation=true"
|
||||||
|
};
|
||||||
|
engine = (ScriptEngine) getEngineMethod.invoke(factory, (Object) args);
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
||||||
|
return engine;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static List<String> immutableList(String... elements) {
|
private static List<String> immutableList(String... elements) {
|
||||||
return Collections.unmodifiableList(Arrays.asList(elements));
|
return Collections.unmodifiableList(Arrays.asList(elements));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ public class DataScript implements INpcScriptHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void callScript(String hookName, Event event) {
|
public void callScript(String hookName, Event event) {
|
||||||
try {
|
try {
|
||||||
EnumScriptType enumScriptType = EnumScriptType.valueOf(hookName);
|
EnumScriptType enumScriptType = EnumScriptType.valueOfIgnoreCase(hookName);
|
||||||
this.callScript(enumScriptType, event);
|
this.callScript(enumScriptType, event);
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package noppes.npcs.controllers.data.action;
|
package noppes.npcs.controllers.data.action;
|
||||||
|
|
||||||
import noppes.npcs.api.handler.data.IAction;
|
import noppes.npcs.api.handler.data.IAction;
|
||||||
import noppes.npcs.config.ConfigScript;
|
|
||||||
import noppes.npcs.scripted.ScriptedActionManager;
|
import noppes.npcs.scripted.ScriptedActionManager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -128,7 +127,7 @@ public class Action implements IAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IAction addData(String key, Object v) {
|
public IAction setData(String key, Object v) {
|
||||||
dataStore.put(key, v);
|
dataStore.put(key, v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -139,6 +138,11 @@ public class Action implements IAction {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasData(String key) {
|
||||||
|
return dataStore.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUpdateEveryXTick() {
|
public int getUpdateEveryXTick() {
|
||||||
return updateEveryXTick;
|
return updateEveryXTick;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class ModelPartData {
|
|||||||
public byte pattern = 0;
|
public byte pattern = 0;
|
||||||
public boolean playerTexture;
|
public boolean playerTexture;
|
||||||
|
|
||||||
private ResourceLocation location;
|
public ResourceLocation location;
|
||||||
|
|
||||||
public ModelPartData() {
|
public ModelPartData() {
|
||||||
playerTexture = true;
|
playerTexture = true;
|
||||||
|
|||||||
@@ -136,7 +136,11 @@ public class ScriptWorld implements IWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IBlock getTopBlock(int x, int z) {
|
public IBlock getTopBlock(int x, int z) {
|
||||||
return NpcAPI.Instance().getIBlock(this, x, world.getTopSolidOrLiquidBlock(x, z), z);
|
int yAbove = world.getTopSolidOrLiquidBlock(x, z);
|
||||||
|
if (yAbove <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return NpcAPI.Instance().getIBlock(this, x, yAbove - 1, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBlock getTopBlock(IPos pos) {
|
public IBlock getTopBlock(IPos pos) {
|
||||||
|
|||||||
@@ -13,13 +13,16 @@ import noppes.npcs.api.IDamageSource;
|
|||||||
import noppes.npcs.api.entity.IEntity;
|
import noppes.npcs.api.entity.IEntity;
|
||||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||||
import noppes.npcs.api.entity.IPlayer;
|
import noppes.npcs.api.entity.IPlayer;
|
||||||
|
import noppes.npcs.api.event.IItemEvent;
|
||||||
import noppes.npcs.api.event.IPlayerEvent;
|
import noppes.npcs.api.event.IPlayerEvent;
|
||||||
import noppes.npcs.api.handler.data.IPlayerEffect;
|
import noppes.npcs.api.handler.data.IPlayerEffect;
|
||||||
import noppes.npcs.api.handler.data.IProfile;
|
import noppes.npcs.api.handler.data.IProfile;
|
||||||
|
import noppes.npcs.api.item.IItemCustomizable;
|
||||||
import noppes.npcs.api.item.IItemStack;
|
import noppes.npcs.api.item.IItemStack;
|
||||||
import noppes.npcs.constants.EnumScriptType;
|
import noppes.npcs.constants.EnumScriptType;
|
||||||
import noppes.npcs.scripted.NpcAPI;
|
import noppes.npcs.scripted.NpcAPI;
|
||||||
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
||||||
|
import noppes.npcs.scripted.event.ItemEvent;
|
||||||
|
|
||||||
public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
|
public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
|
||||||
public final IPlayer player;
|
public final IPlayer player;
|
||||||
@@ -650,6 +653,38 @@ public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Cancelable
|
||||||
|
public static class RightClickEvent extends PlayerEvent implements IPlayerEvent.RightClickEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0:air, 1:entity, 2:block
|
||||||
|
*/
|
||||||
|
public final int type;
|
||||||
|
public final Object target;
|
||||||
|
|
||||||
|
public RightClickEvent(IPlayer player, int type, Object target) {
|
||||||
|
super(player);
|
||||||
|
this.type = type;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHookName() {
|
||||||
|
return EnumScriptType.RIGHT_CLICK.function;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPlayer getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class UpdateEvent extends PlayerEvent implements IPlayerEvent.UpdateEvent {
|
public static class UpdateEvent extends PlayerEvent implements IPlayerEvent.UpdateEvent {
|
||||||
public UpdateEvent(IPlayer player) {
|
public UpdateEvent(IPlayer player) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|||||||
Reference in new issue
Block a user