mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-28 06:45:39 +00:00
Used interfaces in implementations instead of the real classes for most scripted classes.
This commit is contained in:
1 parent
6896cec417
commit
cf33b90b26
63 files changed
+466
-551
No files matched your search
@@ -10,12 +10,12 @@ import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.event.CustomGuiEvent;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
import noppes.npcs.scripted.overlay.ScriptOverlay;
|
||||
import noppes.npcs.scripted.wrapper.NpcAPI;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -23,14 +23,14 @@ public class CustomGuiController {
|
||||
public CustomGuiController() {
|
||||
}
|
||||
|
||||
public static void openGui(ScriptPlayer player, ScriptGui gui) {
|
||||
public static void openGui(IPlayer player, ScriptGui gui) {
|
||||
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player.getMCEntity();
|
||||
entityPlayerMP.openGui(CustomNpcs.instance, EnumGuiType.CustomGui.ordinal(), player.getWorld().getMCWorld(), gui.getSlots().size(), 0, 0);
|
||||
((ContainerCustomGui)((EntityPlayerMP)player.getMCEntity()).openContainer).setGui(gui, (EntityPlayer)player.getMCEntity());
|
||||
Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.GUI_DATA, new Object[]{gui.toNBT()});
|
||||
}
|
||||
|
||||
public static boolean updateGui(ScriptPlayer player, ScriptGui gui) {
|
||||
public static boolean updateGui(IPlayer player, ScriptGui gui) {
|
||||
if (((EntityPlayerMP)player.getMCEntity()).openContainer instanceof ContainerCustomGui) {
|
||||
Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.GUI_DATA, new Object[]{gui.toNBT()});
|
||||
return true;
|
||||
@@ -39,11 +39,11 @@ public class CustomGuiController {
|
||||
}
|
||||
}
|
||||
|
||||
public static void openOverlay(ScriptPlayer player, ScriptOverlay gui) {
|
||||
public static void openOverlay(IPlayer player, ScriptOverlay gui) {
|
||||
Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()});
|
||||
}
|
||||
|
||||
public static boolean updateOverlay(ScriptPlayer player, ScriptOverlay gui) {
|
||||
public static boolean updateOverlay(IPlayer player, ScriptOverlay gui) {
|
||||
Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.event.FactionEvent;
|
||||
|
||||
public class FactionOptions {
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.FactionEvent;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
|
||||
public class PlayerFactionData {
|
||||
public HashMap<Integer,Integer> factionData = new HashMap<Integer,Integer>();
|
||||
@@ -51,7 +52,7 @@ public class PlayerFactionData {
|
||||
}
|
||||
|
||||
public void increasePoints(int factionId, int points, EntityPlayer player) {
|
||||
EventHooks.onFactionPoints(new FactionEvent.FactionPoints(new ScriptPlayer((EntityPlayerMP) player), FactionController.getInstance().get(factionId), points < 0, points));
|
||||
EventHooks.onFactionPoints(new FactionEvent.FactionPoints((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayerMP) player), FactionController.getInstance().get(factionId), points < 0, points));
|
||||
if(!factionData.containsKey(factionId)){
|
||||
Faction faction = FactionController.getInstance().get(factionId);
|
||||
factionData.put(factionId, faction == null? -1 : faction.defaultPoints);
|
||||
|
||||
@@ -23,7 +23,7 @@ import noppes.npcs.scripted.interfaces.handler.data.IQuestInterface;
|
||||
import noppes.npcs.scripted.interfaces.handler.data.IQuestObjective;
|
||||
import noppes.npcs.scripted.interfaces.IContainer;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
import noppes.npcs.scripted.wrapper.NpcAPI;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
public class Quest implements ICompatibilty, IQuest {
|
||||
public int version = VersionCompatibility.ModRev;
|
||||
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.wrapper.NpcAPI;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
public class ScriptContainer {
|
||||
private static final String lock = "lock";
|
||||
|
||||
@@ -284,36 +284,8 @@ public class ScriptController {
|
||||
return list;
|
||||
}
|
||||
|
||||
public ScriptEntity getScriptForEntity(Entity entity) {
|
||||
if(entity == null)
|
||||
return null;
|
||||
if(entity instanceof EntityNPCInterface)
|
||||
return (ScriptNpc)((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;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void saveWorld(WorldEvent.Save event){
|
||||
public void invoke(WorldEvent.Save event){
|
||||
if(!shouldSave || event.world.isRemote || event.world != MinecraftServer.getServer().worldServers[0])
|
||||
return;
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.scripted.entity.ScriptEntity;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
|
||||
public class ScriptEntityData implements IExtendedEntityProperties{
|
||||
public ScriptEntity base;
|
||||
public ScriptEntityData(ScriptEntity base){
|
||||
public IEntity base;
|
||||
public ScriptEntityData(IEntity base){
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveNBTData(NBTTagCompound compound) {
|
||||
}
|
||||
@@ -22,5 +23,4 @@ public class ScriptEntityData implements IExtendedEntityProperties{
|
||||
@Override
|
||||
public void init(Entity entity, World world) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.handler.ICloneHandler;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
import noppes.npcs.scripted.interfaces.IWorld;
|
||||
@@ -199,7 +200,7 @@ public class ServerCloneController implements ICloneHandler {
|
||||
throw new CustomNPCsException("Unknown clone tab:" + tab + " name:" + name, new Object[0]);
|
||||
} else {
|
||||
Entity entity = NoppesUtilServer.spawnClone(compound, (int)x, (int)y, (int)z, world.getMCWorld());
|
||||
return entity == null ? null : ScriptController.Instance.getScriptForEntity(entity);
|
||||
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +211,7 @@ public class ServerCloneController implements ICloneHandler {
|
||||
} else {
|
||||
Instance.cleanTags(compound);
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world.getMCWorld());
|
||||
return entity == null ? null : ScriptController.Instance.getScriptForEntity(entity);
|
||||
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.entity.ICustomNpc;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
@@ -119,7 +120,7 @@ public class NPCDataScript implements IScriptHandler {
|
||||
}
|
||||
public ICustomNpc getNpc() {
|
||||
if (this.npcAPI == null) {
|
||||
this.npcAPI = (ICustomNpc) ScriptController.Instance.getScriptForEntity(this.npc);
|
||||
this.npcAPI = (ICustomNpc) NpcAPI.Instance().getIEntity(this.npc);
|
||||
}
|
||||
return this.npcAPI;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.IScriptHandler;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
@@ -69,7 +69,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
|
||||
if (type != EnumScriptType.INIT) {
|
||||
noppes.npcs.scripted.event.PlayerEvent playerEvent = (noppes.npcs.scripted.event.PlayerEvent)event;
|
||||
EventHooks.onPlayerInit(this, (ScriptPlayer) playerEvent.player);
|
||||
EventHooks.onPlayerInit(this, playerEvent.player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
}
|
||||
public IPlayer getPlayer() {
|
||||
if (this.playerAPI == null) {
|
||||
this.playerAPI = (IPlayer) ScriptController.Instance.getScriptForEntity(this.player);
|
||||
this.playerAPI = (IPlayer) NpcAPI.Instance().getIEntity(this.player);
|
||||
}
|
||||
return this.playerAPI;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user