mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 21:59:05 +00:00
ScriptEntity instances are now properly retrieved in event scripts
This commit is contained in:
1 parent
4de969f6c9
commit
d1c4adf371
4 files changed
+50
-22
No files matched your search
@@ -20,12 +20,16 @@ import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.EventScriptContainer;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.controllers.PlayerData;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.ScriptWorld;
|
||||
import noppes.npcs.scripted.event.PlayerEvent;
|
||||
import noppes.npcs.scripted.interfaces.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
@@ -35,7 +39,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
public List<EventScriptContainer> scripts = new ArrayList();
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
private EntityPlayer player;
|
||||
private ScriptPlayer playerAPI;
|
||||
private IPlayer playerAPI;
|
||||
private long lastPlayerUpdate = 0L;
|
||||
public long lastInited = -1L;
|
||||
public boolean hadInteract = true;
|
||||
@@ -43,16 +47,16 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
private Map<Long, String> console = new TreeMap();
|
||||
public List<Integer> errored = new ArrayList();
|
||||
|
||||
public ScriptPlayer dummyPlayer;
|
||||
public ScriptWorld dummyWorld;
|
||||
public IPlayer dummyPlayer;
|
||||
public IWorld dummyWorld;
|
||||
|
||||
public PlayerDataScript(EntityPlayer player) {
|
||||
if(player != null) {
|
||||
this.player = player;
|
||||
if (player instanceof EntityPlayer)
|
||||
dummyPlayer = new ScriptPlayer((EntityPlayerMP) player);
|
||||
dummyPlayer = (IPlayer) ScriptController.Instance.getScriptForEntity(this.player);
|
||||
if (player.worldObj instanceof WorldServer)
|
||||
dummyWorld = new ScriptWorld((WorldServer) player.worldObj);
|
||||
dummyWorld = (IWorld) NpcAPI.Instance().getIWorld((WorldServer) this.player.worldObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +123,8 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
ScriptEngine engine = script.engine;
|
||||
engine.put("player", dummyPlayer);
|
||||
engine.put("world", dummyWorld);
|
||||
engine.put("player", dummyPlayer);
|
||||
PlayerEvent result = (PlayerEvent) engine.get("event");
|
||||
if(result == null)
|
||||
engine.put("event", result = new PlayerEvent(this.getPlayer()));
|
||||
@@ -184,10 +188,11 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptPlayer getPlayer() {
|
||||
if(this.playerAPI == null) {
|
||||
this.playerAPI = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(this.player);
|
||||
public IPlayer getPlayer() {
|
||||
if (this.playerAPI == null) {
|
||||
this.playerAPI = (IPlayer) NpcAPI.Instance().getIEntity(this.player);
|
||||
}
|
||||
|
||||
return this.playerAPI;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ public abstract class NpcAPI {
|
||||
|
||||
public abstract IEntity getIEntity(Entity var1);
|
||||
|
||||
public abstract IPlayer getIPlayer(EntityPlayerMP var1);
|
||||
|
||||
public abstract IBlock getIBlock(World var1, BlockPos var2);
|
||||
|
||||
public abstract IBlock getIBlock(World world, int x, int y, int z);
|
||||
|
||||
@@ -16,7 +16,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.scripted.*;
|
||||
import noppes.npcs.scripted.entity.ScriptLivingBase;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.interfaces.*;
|
||||
|
||||
public class PlayerEvent extends CustomNPCsEvent {
|
||||
@@ -148,7 +147,7 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
public final float pitch;
|
||||
public final float volume;
|
||||
|
||||
public SoundEvent(ScriptPlayer player, String name, float pitch, float volume) {
|
||||
public SoundEvent(IPlayer player, String name, float pitch, float volume) {
|
||||
super(player);
|
||||
this.name = name;
|
||||
this.pitch = pitch;
|
||||
@@ -390,7 +389,7 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
public final int y;
|
||||
public final int z;
|
||||
|
||||
public Sleep(ScriptPlayer player, int x, int y, int z) {
|
||||
public Sleep(IPlayer player, int x, int y, int z) {
|
||||
super(player);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -434,7 +433,7 @@ public class PlayerEvent extends CustomNPCsEvent {
|
||||
}
|
||||
|
||||
public static class RangedChargeEvent extends PlayerEvent {
|
||||
public RangedChargeEvent(ScriptPlayer player) {
|
||||
public RangedChargeEvent(IPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ import java.util.UUID;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.passive.EntityTameable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -27,11 +32,13 @@ import net.minecraftforge.common.util.FakePlayer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.client.EntityUtil;
|
||||
import noppes.npcs.controllers.PixelmonHelper;
|
||||
import noppes.npcs.controllers.ScriptEntityData;
|
||||
import noppes.npcs.scripted.*;
|
||||
import noppes.npcs.containers.ContainerNpcInterface;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.entity.*;
|
||||
import noppes.npcs.scripted.interfaces.*;
|
||||
import noppes.npcs.util.LRUHashMap;
|
||||
|
||||
@@ -48,18 +55,37 @@ public class WrapperNpcAPI extends NpcAPI {
|
||||
}
|
||||
|
||||
public IEntity getIEntity(Entity entity) {
|
||||
/*
|
||||
if (entity != null && !entity.worldObj.isRemote) {
|
||||
return (entity instanceof EntityNPCInterface ? ((EntityNPCInterface)entity).wrappedNPC : entity instanceof EntityPlayerMP ? getIPlayer((EntityPlayerMP) entity) : WrapperEntityData.get(entity));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IPlayer getIPlayer(EntityPlayerMP player) {
|
||||
if (player != null && !player.worldObj.isRemote) {
|
||||
return new ScriptPlayer(player);
|
||||
} else {
|
||||
*/
|
||||
if(entity == null)
|
||||
return null;
|
||||
if(entity instanceof EntityNPCInterface)
|
||||
return ((EntityNPCInterface) entity).script.dummyNpc;
|
||||
else{
|
||||
ScriptEntityData data = (ScriptEntityData) entity.getExtendedProperties("ScriptedObject");
|
||||
if(data != null)
|
||||
return data.base;
|
||||
if(entity instanceof EntityPlayerMP)
|
||||
data = new ScriptEntityData(new ScriptPlayer((EntityPlayerMP) entity));
|
||||
else if(PixelmonHelper.isPixelmon(entity))
|
||||
return new ScriptPixelmon((EntityTameable) entity);
|
||||
else if(entity instanceof EntityAnimal)
|
||||
data = new ScriptEntityData(new ScriptAnimal((EntityAnimal) entity));
|
||||
else if(entity instanceof EntityMob)
|
||||
data = new ScriptEntityData(new ScriptMonster((EntityMob) entity));
|
||||
else if(entity instanceof EntityLiving)
|
||||
data = new ScriptEntityData(new ScriptLiving((EntityLiving) entity));
|
||||
else if(entity instanceof EntityLivingBase)
|
||||
data = new ScriptEntityData(new ScriptLivingBase((EntityLivingBase)entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
return data.base;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user