mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 10:49:07 +00:00
Server-side compatibility changes
This commit is contained in:
1 parent
c8f917d8fb
commit
f88cbb8b51
9 files changed
+230
-212
No files matched your search
@@ -5,6 +5,7 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.blocks.tiles.TileNpcContainer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
@@ -60,31 +61,31 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
if(gui == EnumGuiType.PlayerBankSmall)
|
||||
return new ContainerNPCBankSmall(player, x , y);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.PlayerBankUnlock)
|
||||
return new ContainerNPCBankUnlock(player, x , y);
|
||||
|
||||
if(gui == EnumGuiType.PlayerBankUprade)
|
||||
return new ContainerNPCBankUpgrade(player, x , y);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.PlayerBankLarge)
|
||||
return new ContainerNPCBankLarge(player, x , y);
|
||||
|
||||
if(gui == EnumGuiType.PlayerFollowerHire)
|
||||
return new ContainerNPCFollowerHire(npc, player);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.PlayerFollower)
|
||||
return new ContainerNPCFollower(npc, player);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.PlayerTrader)
|
||||
return new ContainerNPCTrader(npc, player);
|
||||
|
||||
if(gui == EnumGuiType.PlayerAnvil)
|
||||
return new ContainerCarpentryBench(player.inventory, player.worldObj, x, y, z);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.SetupItemGiver)
|
||||
return new ContainerNpcItemGiver(npc, player);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.SetupTrader)
|
||||
return new ContainerNPCTraderSetup(npc, player);
|
||||
|
||||
@@ -93,10 +94,10 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
if(gui == EnumGuiType.QuestReward)
|
||||
return new ContainerNpcQuestReward(player);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.QuestItem)
|
||||
return new ContainerNpcQuestTypeItem(player);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.ManageRecipes)
|
||||
return new ContainerManageRecipes(player,x);
|
||||
|
||||
@@ -108,13 +109,13 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
if(gui == EnumGuiType.Crate)
|
||||
return new ContainerCrate(player.inventory, (TileNpcContainer)player.worldObj.getTileEntity(x, y, z));
|
||||
|
||||
|
||||
if(gui == EnumGuiType.PlayerMailman)
|
||||
return new ContainerMail(player, x == 1, y == 1);
|
||||
|
||||
|
||||
if(gui == EnumGuiType.CompanionInv)
|
||||
return new ContainerNPCCompanion(npc, player);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -134,17 +135,17 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
|
||||
public void openGui(int i, int j, int k, EnumGuiType gui, EntityPlayer player) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void openGui(EntityPlayer player, Object guiscreen) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void spawnParticle(EntityLivingBase player, String string, Object... ob) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean hasClient() {
|
||||
@@ -157,7 +158,7 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
public void registerItem(Item item) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ModelBiped getSkirtModel() {
|
||||
@@ -165,8 +166,11 @@ public class CommonProxy implements IGuiHandler {
|
||||
}
|
||||
|
||||
public void spawnParticle(String particle, double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ, float scale) {
|
||||
|
||||
double motionX, double motionY, double motionZ, float scale) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public String getAchievementDesc(Achievement achievement) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ public class EventHooks {
|
||||
}
|
||||
|
||||
public static boolean onPlayerBreak(PlayerDataScript handler, PlayerEvent.BreakEvent event) {
|
||||
handler.callScript(EnumScriptType.BREAK, event,"event", event);
|
||||
handler.callScript(EnumScriptType.BREAK_BLOCK, event,"event", event);
|
||||
return WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
@@ -303,4 +303,4 @@ public class EventHooks {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public class ScriptPlayerEventHandler {
|
||||
public void invoke(AchievementEvent event) {
|
||||
if(event.entityPlayer.worldObj instanceof WorldServer) {
|
||||
PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData;
|
||||
EventHooks.onPlayerAchievement(handler, event.achievement.getDescription());
|
||||
EventHooks.onPlayerAchievement(handler, CustomNpcs.proxy.getAchievementDesc(event.achievement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,4 +450,4 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -158,9 +159,9 @@ import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
public static KeyBinding QuestLog;
|
||||
|
||||
|
||||
public static FontContainer Font;
|
||||
|
||||
|
||||
public void load() {
|
||||
Font = new FontContainer(CustomNpcs.FontType, CustomNpcs.FontSize);
|
||||
createFolders();
|
||||
@@ -210,43 +211,43 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerBlockHandler(new BlockBloodRenderer());
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
|
||||
QuestLog = new KeyBinding("Quest Log", Keyboard.KEY_L, "key.categories.gameplay");
|
||||
|
||||
|
||||
ClientRegistry.registerKeyBinding(QuestLog);
|
||||
mc.gameSettings.loadOptions();
|
||||
|
||||
|
||||
new PresetController(CustomNpcs.Dir);
|
||||
|
||||
|
||||
if(CustomNpcs.EnableUpdateChecker){
|
||||
VersionChecker checker = new VersionChecker();
|
||||
checker.start();
|
||||
}
|
||||
|
||||
|
||||
ClientCloneController.Instance = new ClientCloneController();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
|
||||
|
||||
if(CustomNpcs.InventoryGuiEnabled){
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
|
||||
if (TabRegistry.getTabList().size() < 2){
|
||||
TabRegistry.registerTab(new InventoryTabVanilla());
|
||||
}
|
||||
TabRegistry.registerTab(new InventoryTabFactions());
|
||||
TabRegistry.registerTab(new InventoryTabQuests());
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
|
||||
|
||||
if(CustomNpcs.InventoryGuiEnabled){
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
|
||||
if (TabRegistry.getTabList().size() < 2){
|
||||
TabRegistry.registerTab(new InventoryTabVanilla());
|
||||
}
|
||||
TabRegistry.registerTab(new InventoryTabFactions());
|
||||
TabRegistry.registerTab(new InventoryTabQuests());
|
||||
}
|
||||
}
|
||||
|
||||
private void createFolders() {
|
||||
File file = new File(CustomNpcs.Dir,"assets/customnpcs");
|
||||
if(!file.exists())
|
||||
file.mkdirs();
|
||||
|
||||
|
||||
File check = new File(file,"sounds");
|
||||
if(!check.exists())
|
||||
check.mkdir();
|
||||
|
||||
|
||||
File json = new File(file, "sounds.json");
|
||||
if(!json.exists()){
|
||||
try {
|
||||
@@ -261,7 +262,7 @@ public class ClientProxy extends CommonProxy {
|
||||
check = new File(file,"textures");
|
||||
if(!check.exists())
|
||||
check.mkdir();
|
||||
|
||||
|
||||
File cache = new File(check,"cache");
|
||||
if(!cache.exists())
|
||||
cache.mkdir();
|
||||
@@ -284,7 +285,7 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
|
||||
|
||||
if (ID > EnumGuiType.values().length)
|
||||
return null;
|
||||
EnumGuiType gui = EnumGuiType.values()[ID];
|
||||
@@ -293,6 +294,8 @@ public class ClientProxy extends CommonProxy {
|
||||
return getGui(npc, gui, container, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private GuiScreen getGui(EntityNPCInterface npc, EnumGuiType gui, Container container, int x, int y, int z) {
|
||||
if (gui == EnumGuiType.MainMenuDisplay){
|
||||
if(npc != null)
|
||||
@@ -311,16 +314,16 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
else if(gui == EnumGuiType.QuestReward)
|
||||
return new GuiNpcQuestReward(npc, (ContainerNpcQuestReward) container);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.QuestItem)
|
||||
return new GuiNpcQuestTypeItem(npc, (ContainerNpcQuestTypeItem) container);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.MovingPath)
|
||||
return new GuiNpcPather(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageFactions)
|
||||
return new GuiNPCManageFactions(npc);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.ManageLinked)
|
||||
return new GuiNPCManageLinkedNpc(npc);
|
||||
|
||||
@@ -329,15 +332,15 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
else if (gui == EnumGuiType.ManageRecipes)
|
||||
return new GuiNpcManageRecipes(npc,(ContainerManageRecipes) container);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.ManageDialogs)
|
||||
return new GuiNPCManageDialogs(npc);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.ManageQuests)
|
||||
return new GuiNPCManageQuest(npc);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.ManageBanks)
|
||||
return new GuiNPCManageBanks(npc,(ContainerManageBanks) container);
|
||||
return new GuiNPCManageBanks(npc,(ContainerManageBanks) container);
|
||||
|
||||
else if (gui == EnumGuiType.MainMenuGlobal)
|
||||
return new GuiNPCGlobalMainMenu(npc);
|
||||
@@ -350,37 +353,37 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
else if (gui == EnumGuiType.PlayerFollower)
|
||||
return new GuiNpcFollower(npc, (ContainerNPCFollower) container);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.PlayerTrader)
|
||||
return new GuiNPCTrader(npc, (ContainerNPCTrader) container);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.PlayerBankSmall || gui == EnumGuiType.PlayerBankUnlock || gui == EnumGuiType.PlayerBankUprade || gui == EnumGuiType.PlayerBankLarge)
|
||||
return new GuiNPCBankChest(npc, (ContainerNPCBankInterface) container);
|
||||
|
||||
else if(gui == EnumGuiType.PlayerTransporter)
|
||||
return new GuiTransportSelection(npc);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.Script)
|
||||
return new GuiScript(npc);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.PlayerAnvil)
|
||||
return new GuiNpcCarpentryBench((ContainerCarpentryBench) container);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.SetupFollower)
|
||||
return new GuiNpcFollowerSetup(npc, (ContainerNPCFollowerSetup) container);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.SetupItemGiver)
|
||||
return new GuiNpcItemGiver(npc, (ContainerNpcItemGiver) container);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.SetupTrader)
|
||||
return new GuiNpcTraderSetup(npc, (ContainerNPCTraderSetup) container);
|
||||
|
||||
else if(gui == EnumGuiType.SetupTransporter)
|
||||
return new GuiNpcTransporter(npc);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.SetupBank)
|
||||
return new GuiNpcBankSetup(npc);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.NpcRemote && Minecraft.getMinecraft().currentScreen == null)
|
||||
return new GuiNpcRemoteEditor();
|
||||
|
||||
@@ -389,48 +392,48 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
else if(gui == EnumGuiType.PlayerMailman)
|
||||
return new GuiMailmanWrite((ContainerMail) container, x == 1, y == 1);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.PlayerMailbox)
|
||||
return new GuiMailbox();
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.MerchantAdd)
|
||||
return new GuiMerchantAdd();
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.Crate)
|
||||
return new GuiCrate((ContainerCrate)container);
|
||||
|
||||
else if(gui == EnumGuiType.NpcDimensions)
|
||||
return new GuiNpcDimension();
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.Border)
|
||||
return new GuiBorderBlock(x, y, z);
|
||||
|
||||
else if(gui == EnumGuiType.BigSign)
|
||||
return new GuiBigSign(x, y, z);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.RedstoneBlock)
|
||||
return new GuiNpcRedstoneBlock(x, y, z);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.MobSpawner)
|
||||
return new GuiNpcMobSpawner(x, y, z);
|
||||
|
||||
|
||||
else if(gui == EnumGuiType.MobSpawnerMounter)
|
||||
return new GuiNpcMobSpawnerMounter(x, y, z);
|
||||
|
||||
else if (gui == EnumGuiType.Waypoint)
|
||||
return new GuiNpcWaypoint(x, y, z);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.Companion)
|
||||
return new GuiNpcCompanionStats(npc);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.CompanionTalent)
|
||||
return new GuiNpcCompanionTalents(npc);
|
||||
|
||||
|
||||
else if (gui == EnumGuiType.CompanionInv)
|
||||
return new GuiNpcCompanionInv(npc, (ContainerNPCCompanion) container);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void openGui(int i, int j, int k, EnumGuiType gui, EntityPlayer player) {
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
@@ -438,7 +441,7 @@ public class ClientProxy extends CommonProxy {
|
||||
return;
|
||||
|
||||
GuiScreen guiscreen = getGui(null, gui, null, i, j, k);
|
||||
|
||||
|
||||
|
||||
if (guiscreen != null) {
|
||||
minecraft.displayGuiScreen(guiscreen);
|
||||
@@ -469,7 +472,7 @@ public class ClientProxy extends CommonProxy {
|
||||
if (guiscreen != null) {
|
||||
minecraft.displayGuiScreen((GuiScreen)guiscreen);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -477,18 +480,18 @@ public class ClientProxy extends CommonProxy {
|
||||
if(string.equals("Spell")){
|
||||
int color = (Integer) ob[0];
|
||||
int number = (Integer) ob[1];
|
||||
for(int i = 0; i < number; i++){
|
||||
Random rand = player.worldObj.rand;
|
||||
for(int i = 0; i < number; i++){
|
||||
Random rand = player.worldObj.rand;
|
||||
double x = (rand.nextDouble() - 0.5D) * (double)player.width;
|
||||
double y = player.getEyeHeight();
|
||||
double z = (rand.nextDouble() - 0.5D) * (double)player.width;
|
||||
|
||||
double f = (rand.nextDouble() - 0.5D) * 2D;
|
||||
double f1 = -rand.nextDouble();
|
||||
double f2 = (rand.nextDouble() - 0.5D) * 2D;
|
||||
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityElementalStaffFX(player, x, y, z, f, f1, f2, color));
|
||||
}
|
||||
|
||||
double f = (rand.nextDouble() - 0.5D) * 2D;
|
||||
double f1 = -rand.nextDouble();
|
||||
double f2 = (rand.nextDouble() - 0.5D) * 2D;
|
||||
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityElementalStaffFX(player, x, y, z, f, f1, f2, color));
|
||||
}
|
||||
}
|
||||
else if(string.equals("ModelData")){
|
||||
ModelData data = (ModelData) ob[0];
|
||||
@@ -502,21 +505,21 @@ public class ClientProxy extends CommonProxy {
|
||||
EntityEnderFX fx = new EntityEnderFX(npc, (rand.nextDouble() - 0.5D) * (double)player.width, (rand.nextDouble() * (double)player.height) - height - 0.25D, (rand.nextDouble() - 0.5D) * (double)player.width, (rand.nextDouble() - 0.5D) * 2D, -rand.nextDouble(), (rand.nextDouble() - 0.5D) * 2D, particles);
|
||||
minecraft.effectRenderer.addEffect(fx);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if(particles.type == 1){
|
||||
for(int i = 0; i < 2; i++){
|
||||
double x = player.posX + (rand.nextDouble() - 0.5D) * 0.9;
|
||||
double y = (player.posY + rand.nextDouble() * 1.9) - 0.25D - height;
|
||||
double z = player.posZ + (rand.nextDouble() - 0.5D) * 0.9;
|
||||
|
||||
|
||||
double f = (rand.nextDouble() - 0.5D) * 2D;
|
||||
double f1 = -rand.nextDouble();
|
||||
double f2 = (rand.nextDouble() - 0.5D) * 2D;
|
||||
|
||||
minecraft.effectRenderer.addEffect(new EntityRainbowFX(player.worldObj, x, y, z, f, f1, f2));
|
||||
}
|
||||
for(int i = 0; i < 2; i++){
|
||||
double x = player.posX + (rand.nextDouble() - 0.5D) * 0.9;
|
||||
double y = (player.posY + rand.nextDouble() * 1.9) - 0.25D - height;
|
||||
double z = player.posZ + (rand.nextDouble() - 0.5D) * 0.9;
|
||||
|
||||
|
||||
double f = (rand.nextDouble() - 0.5D) * 2D;
|
||||
double f1 = -rand.nextDouble();
|
||||
double f2 = (rand.nextDouble() - 0.5D) * 2D;
|
||||
|
||||
minecraft.effectRenderer.addEffect(new EntityRainbowFX(player.worldObj, x, y, z, f, f1, f2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,7 +532,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public boolean hasClient() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public EntityPlayer getPlayer() {
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
@@ -544,54 +547,58 @@ public class ClientProxy extends CommonProxy {
|
||||
try{
|
||||
if(location == null)
|
||||
return;
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
if(location != null)
|
||||
texturemanager.bindTexture((ResourceLocation) location);
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
if(location != null)
|
||||
texturemanager.bindTexture((ResourceLocation) location);
|
||||
}
|
||||
catch(NullPointerException ex){
|
||||
|
||||
|
||||
}
|
||||
catch(ReportedException ex){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(String particle, double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ, float scale) {
|
||||
|
||||
double motionX, double motionY, double motionZ, float scale) {
|
||||
|
||||
RenderGlobal render = Minecraft.getMinecraft().renderGlobal;
|
||||
|
||||
|
||||
EntityFX fx = render.doSpawnParticle(particle, x, y, z, motionX, motionY, motionZ);
|
||||
if(fx == null)
|
||||
return;
|
||||
|
||||
if (particle.equals("flame")){
|
||||
ObfuscationReflectionHelper.setPrivateValue(EntityFlameFX.class, (EntityFlameFX)fx, scale, 0);
|
||||
}
|
||||
else if (particle.equals("smoke")){
|
||||
ObfuscationReflectionHelper.setPrivateValue(EntitySmokeFX.class, (EntitySmokeFX)fx, scale, 0);
|
||||
}
|
||||
if (particle.equals("flame")){
|
||||
ObfuscationReflectionHelper.setPrivateValue(EntityFlameFX.class, (EntityFlameFX)fx, scale, 0);
|
||||
}
|
||||
else if (particle.equals("smoke")){
|
||||
ObfuscationReflectionHelper.setPrivateValue(EntitySmokeFX.class, (EntitySmokeFX)fx, scale, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAchievementDesc(Achievement achievement) {
|
||||
return achievement.getDescription();
|
||||
}
|
||||
|
||||
|
||||
public static class FontContainer {
|
||||
private StringCache textFont = null;
|
||||
public boolean useCustomFont = true;
|
||||
|
||||
|
||||
private FontContainer(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public FontContainer(String fontType, int fontSize) {
|
||||
textFont = new StringCache();
|
||||
textFont.setDefaultFont("Arial", fontSize, true);
|
||||
useCustomFont = !fontType.equalsIgnoreCase("minecraft");
|
||||
try {
|
||||
if(!useCustomFont || fontType.isEmpty() || fontType.equalsIgnoreCase("default"))
|
||||
textFont.setCustomFont(new ResourceLocation("customnpcs","OpenSans.ttf"), fontSize, true);
|
||||
else
|
||||
textFont.setDefaultFont(fontType, fontSize, true);
|
||||
try {
|
||||
if(!useCustomFont || fontType.isEmpty() || fontType.equalsIgnoreCase("default"))
|
||||
textFont.setCustomFont(new ResourceLocation("customnpcs","OpenSans.ttf"), fontSize, true);
|
||||
else
|
||||
textFont.setDefaultFont(fontType, fontSize, true);
|
||||
} catch (Exception e) {
|
||||
LogWriter.info("Failed loading font so using Arial");
|
||||
}
|
||||
@@ -602,7 +609,7 @@ public class ClientProxy extends CommonProxy {
|
||||
return textFont.fontHeight;
|
||||
return Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
public int width(String text){
|
||||
if(useCustomFont)
|
||||
return textFont.getStringWidth(text);
|
||||
@@ -632,4 +639,4 @@ public class ClientProxy extends CommonProxy {
|
||||
return textFont.usedFont().getFontName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookList.add("killed");
|
||||
hookList.add("drop");
|
||||
hookList.add("respawn");
|
||||
hookList.add("break");
|
||||
hookList.add("breakBlock");
|
||||
hookList.add("chat");
|
||||
hookList.add("login");
|
||||
hookList.add("logout");
|
||||
@@ -130,7 +130,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookList.add("playSound");
|
||||
hookList.add("lightning");
|
||||
hookList.add("changedDim");
|
||||
hookList.add("achievement");
|
||||
}
|
||||
else if(handler instanceof ForgeDataScript) {
|
||||
hookList.add("init");
|
||||
@@ -418,4 +417,4 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
container.script = text;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public enum EnumScriptType {
|
||||
PLAYSOUND("playSound"),
|
||||
RESPAWN("respawn"),
|
||||
CHANGED_DIM("changedDim"),
|
||||
BREAK("break"),
|
||||
BREAK_BLOCK("breakBlock"),
|
||||
FORGE_INIT("forgeInit"),
|
||||
FORGE_ENTITY("forgeEntity"),
|
||||
FORGE_WORLD("forgeWorld");
|
||||
@@ -82,4 +82,4 @@ public enum EnumScriptType {
|
||||
private EnumScriptType(String function) {
|
||||
this.function = function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ import noppes.npcs.util.NBTJsonUtil;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ScriptController {
|
||||
|
||||
|
||||
public static ScriptController Instance;
|
||||
public static boolean HasStart = false;
|
||||
private ScriptEngineManager manager;
|
||||
@@ -184,39 +184,40 @@ public class ScriptController {
|
||||
}
|
||||
}
|
||||
public boolean loadStoredData(){
|
||||
loadCategories();
|
||||
File file = getSavedFile();
|
||||
try {
|
||||
if(!file.exists())
|
||||
return false;
|
||||
this.compound = NBTJsonUtil.LoadFile(file);
|
||||
shouldSave = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
loadCategories();
|
||||
File file = getSavedFile();
|
||||
try {
|
||||
if(!file.exists())
|
||||
return false;
|
||||
this.compound = NBTJsonUtil.LoadFile(file);
|
||||
shouldSave = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private File getSavedFile(){
|
||||
return new File(dir, "world_data.json");
|
||||
}
|
||||
private String readFile(File file) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
|
||||
while (line != null) {
|
||||
sb.append(line);
|
||||
sb.append("\n");
|
||||
line = br.readLine();
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
private String readFile(File file) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
|
||||
while (line != null) {
|
||||
sb.append(line);
|
||||
sb.append("\n");
|
||||
line = br.readLine();
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptEngine getEngineByName(String language) {
|
||||
@@ -237,7 +238,7 @@ public class ScriptController {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private List<String> getScripts(String language){
|
||||
List<String> list = new ArrayList<String>();
|
||||
String ext = languages.get(language);
|
||||
@@ -283,14 +284,14 @@ public class ScriptController {
|
||||
public void saveWorld(WorldEvent.Save event){
|
||||
if(!shouldSave || event.world.isRemote || event.world != MinecraftServer.getServer().worldServers[0])
|
||||
return;
|
||||
|
||||
|
||||
try {
|
||||
NBTJsonUtil.SaveFile(getSavedFile(), compound);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
shouldSave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,35 +98,35 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public double getX(){
|
||||
return entity.posX;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param x The entities x position
|
||||
*/
|
||||
public void setX(double x){
|
||||
entity.posX = x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The entities y position
|
||||
*/
|
||||
public double getY(){
|
||||
return entity.posY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param y The entities y position
|
||||
*/
|
||||
public void setY(double y){
|
||||
entity.posY = y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The entities x position
|
||||
*/
|
||||
public double getZ(){
|
||||
return entity.posZ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param z The entities x position
|
||||
*/
|
||||
@@ -154,7 +154,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public int getBlockZ(){
|
||||
return MathHelper.floor_double(entity.posZ);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param x The x position
|
||||
* @param y The y position
|
||||
@@ -164,7 +164,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
entity.setPosition(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param range The search range for entities around this entity
|
||||
* @return Array of entities within range
|
||||
@@ -178,7 +178,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
}
|
||||
return list.toArray(new ScriptEntity[list.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param range The search range for entities around this entity
|
||||
* @param type The EntityType you want to find
|
||||
@@ -196,7 +196,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
cls = EntityMob.class;
|
||||
else if(type == EntityType.NPC)
|
||||
cls = EntityNPCInterface.class;
|
||||
|
||||
|
||||
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range));
|
||||
List<ScriptEntity> list = new ArrayList<ScriptEntity>();
|
||||
for(Entity living : entities){
|
||||
@@ -204,16 +204,16 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
list.add(ScriptController.Instance.getScriptForEntity(living));
|
||||
}
|
||||
return list.toArray(new ScriptEntity[list.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return Whether the entity is alive or not
|
||||
*/
|
||||
public boolean isAlive(){
|
||||
return entity.isEntityAlive();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key Get temp data for this key
|
||||
* @return Returns the stored temp data
|
||||
@@ -221,7 +221,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public Object getTempData(String key){
|
||||
return tempData.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tempdata gets cleared when the entity gets unloaded or the world restarts
|
||||
* @param key The key for the data stored
|
||||
@@ -230,7 +230,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public void setTempData(String key, Object value){
|
||||
tempData.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key thats going to be tested against the temp data
|
||||
* @return Whether or not temp data containes the key
|
||||
@@ -238,21 +238,21 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public boolean hasTempData(String key){
|
||||
return tempData.containsKey(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key for the temp data to be removed
|
||||
*/
|
||||
public void removeTempData(String key){
|
||||
tempData.remove(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all tempdata
|
||||
*/
|
||||
public void clearTempData(){
|
||||
tempData.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key of the data to be returned
|
||||
* @return Returns the stored data
|
||||
@@ -266,7 +266,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
return ((NBTPrimitive)base).func_150286_g();
|
||||
return ((NBTTagString)base).func_150285_a_();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved
|
||||
* @param key The key for the data stored
|
||||
@@ -281,7 +281,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
compound.setString(key, (String)value);
|
||||
saveStoredCompound(compound);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key of the data to be checked
|
||||
* @return Returns whether or not the stored data contains the key
|
||||
@@ -289,7 +289,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public boolean hasStoredData(String key){
|
||||
return getStoredCompound().hasKey(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param key The key of the data to be removed
|
||||
*/
|
||||
@@ -298,74 +298,74 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
compound.removeTag(key);
|
||||
saveStoredCompound(compound);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all stored data
|
||||
*/
|
||||
public void clearStoredData(){
|
||||
entity.getEntityData().removeTag("CNPCStoredData");
|
||||
}
|
||||
|
||||
|
||||
private NBTTagCompound getStoredCompound(){
|
||||
NBTTagCompound compound = entity.getEntityData().getCompoundTag("CNPCStoredData");
|
||||
if(compound == null)
|
||||
entity.getEntityData().setTag("CNPCStoredData", compound = new NBTTagCompound());
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
private void saveStoredCompound(NBTTagCompound compound){
|
||||
entity.getEntityData().setTag("CNPCStoredData", compound);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The age of this entity in ticks
|
||||
*/
|
||||
public long getAge(){
|
||||
return entity.ticksExisted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Despawns this entity. Removes it permanently
|
||||
*/
|
||||
public void despawn(){
|
||||
entity.isDead = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Return whether or not this entity is standing in water
|
||||
*/
|
||||
public boolean inWater(){
|
||||
return entity.isInsideOfMaterial(Material.water);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Return whether or not this entity is standing in lava
|
||||
*/
|
||||
public boolean inLava(){
|
||||
return entity.isInsideOfMaterial(Material.lava);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Return whether or not this entity is standing in fire
|
||||
*/
|
||||
public boolean inFire(){
|
||||
return entity.isInsideOfMaterial(Material.fire);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Return whether or not this entity is on fire
|
||||
*/
|
||||
public boolean isBurning(){
|
||||
return entity.isBurning();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ticks Amount of world ticks this entity will burn. 20 ticks equals 1 second
|
||||
*/
|
||||
public void setBurning(int ticks){
|
||||
entity.setFire(ticks);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes fire from this entity
|
||||
*/
|
||||
@@ -379,7 +379,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public String getTypeName(){
|
||||
return EntityList.getEntityString(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param item Item to be dropped
|
||||
*/
|
||||
@@ -393,7 +393,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public ScriptEntity getRider(){
|
||||
return ScriptController.Instance.getScriptForEntity(entity.riddenByEntity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param entity The entity to ride this entity
|
||||
*/
|
||||
@@ -411,7 +411,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public ScriptEntity getMount(){
|
||||
return ScriptController.Instance.getScriptForEntity(entity.ridingEntity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param entity The entity this entity will mount
|
||||
*/
|
||||
@@ -429,7 +429,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public int getType(){
|
||||
return EntityType.UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @param type @EntityType to check
|
||||
@@ -438,33 +438,39 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public boolean typeOf(int type){
|
||||
return type == EntityType.UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param rotation The rotation to be set (0-360)
|
||||
*/
|
||||
public void setRotation(float rotation){
|
||||
entity.rotationYaw = rotation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Current rotation of the npc
|
||||
*/
|
||||
public float getRotation(){
|
||||
return entity.rotationYaw;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param power How strong the knockback is
|
||||
* @param direction The direction in which he flies back (0-360). Usually based on getRotation()
|
||||
*/
|
||||
public void knockback(int power, float direction){
|
||||
float v = direction * (float)Math.PI / 180.0F;
|
||||
entity.addVelocity(-MathHelper.sin(v) * (float)power, 0.1D + power * 0.04f, MathHelper.cos(v) * (float)power);
|
||||
entity.motionX *= 0.6D;
|
||||
entity.motionZ *= 0.6D;
|
||||
entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F);
|
||||
entity.addVelocity(-MathHelper.sin(v) * (float)power, 0.1D + power * 0.04f, MathHelper.cos(v) * (float)power);
|
||||
entity.motionX *= 0.6D;
|
||||
entity.motionZ *= 0.6D;
|
||||
entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F);
|
||||
}
|
||||
|
||||
|
||||
public void knockback(int xpower, int ypower, int zpower, float direction){
|
||||
float v = direction * (float)Math.PI / 180.0F;
|
||||
entity.addVelocity(-MathHelper.sin(v) * (float)xpower, 0.1D + ypower * 0.04f, MathHelper.cos(v) * (float)zpower);
|
||||
entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @return Returns whether or not this entity is sneaking
|
||||
@@ -472,7 +478,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public boolean isSneaking(){
|
||||
return entity.isSneaking();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* @return Returns whether or not this entity is sprinting
|
||||
@@ -480,7 +486,7 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
public boolean isSprinting(){
|
||||
return entity.isSprinting();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 1.7.10c
|
||||
* Expert users only
|
||||
@@ -506,4 +512,4 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
ServerCloneController.Instance.addClone(compound, name, tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user