diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 05d439dd8..b8bc9bbb1 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -120,8 +120,14 @@ public class CustomNpcs { @ConfigProp(info = "Normal players can use soulstone on animals") public static boolean SoulStoneAnimals = true; + @ConfigProp(info = "Normal players can use soulstone on villagers") + public static boolean SoulStoneVillagers = false; + @ConfigProp(info = "Normal players can use soulstone on all npcs") public static boolean SoulStoneNPCs = false; + + @ConfigProp(info = "Normal players can use soulstone on friendly npcs") + public static boolean SoulStoneFriendlyNPCs = false; @ConfigProp(info="When set to Minecraft it will use minecrafts font, when Default it will use OpenSans. Can only use fonts installed on your PC") public static String FontType = "Default"; diff --git a/src/main/java/noppes/npcs/DataAdvanced.java b/src/main/java/noppes/npcs/DataAdvanced.java index c8864dee1..ce4331244 100644 --- a/src/main/java/noppes/npcs/DataAdvanced.java +++ b/src/main/java/noppes/npcs/DataAdvanced.java @@ -53,6 +53,11 @@ public class DataAdvanced { public boolean attackOtherFactions = false; public boolean defendFaction = false; public boolean disablePitch = false; + + public String soulStonePlayerName = ""; + public boolean refuseSoulStone = false; + public boolean soulStoneInit = false; + public int minFactionPointsToSoulStone = -1; public DataAdvanced(EntityNPCInterface npc) { this.npc = npc; @@ -84,6 +89,10 @@ public class DataAdvanced { compound.setTag("NPCDialogOptions", nbtDialogs(npc.dialogs)); + compound.setBoolean("RefuseSoulStone", refuseSoulStone); + compound.setString("SoulStonePlayerName", soulStonePlayerName); + compound.setInteger("MinFactionPointsToSoulStone", minFactionPointsToSoulStone); + return compound; } @@ -114,6 +123,10 @@ public class DataAdvanced { factions.readFromNBT(compound.getCompoundTag("FactionPoints")); npc.dialogs = getDialogs(compound.getTagList("NPCDialogOptions", 10)); + + refuseSoulStone = compound.getBoolean("RefuseSoulStone"); + soulStonePlayerName = compound.getString("SoulStonePlayerName"); + minFactionPointsToSoulStone = compound.getInteger("MinFactionPointsToSoulStone"); } private HashMap getDialogs(NBTTagList tagList) { diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 3a2b2d5dc..b3b0f8151 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -123,6 +123,7 @@ public class EventHooks { ScriptController.Instance.npcScripts.callScript(EnumScriptType.INIT, event); npc.script.callScript(EnumScriptType.INIT, event); NpcAPI.EVENT_BUS.post(event); + npc.advanced.soulStoneInit = false; } public static void onNPCUpdate(EntityNPCInterface npc) { diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java b/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java index f7d6f2c75..7364fdabc 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java @@ -39,96 +39,96 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol public HashMap> data = new HashMap>(); private List list; private final String[] ignoredTags = {"CanBreakDoors", "Bred", "PlayerCreated", "Tame", "HasReproduced"}; - + private GuiNpcButton prev,next; private GuiScreen parent; - + private HashMap mapped = new HashMap(); - + public GuiCreationScreen(GuiScreen parent, EntityCustomNpc npc){ super(npc); this.parent = parent; - Map mapping = EntityList.stringToClassMapping; - for(Object name : mapping.keySet()){ - Class c = (Class) mapping.get(name); - try { - if(!EntityCustomNpc.class.isAssignableFrom(c) && EntityLiving.class.isAssignableFrom(c) && c.getConstructor(new Class[] {World.class}) != null && !Modifier.isAbstract(c.getModifiers())){ - if(RenderManager.instance.getEntityClassRenderObject(c) instanceof RendererLivingEntity) - data.put(name.toString(),c.asSubclass(EntityLivingBase.class)); - } + Map mapping = EntityList.stringToClassMapping; + for(Object name : mapping.keySet()){ + Class c = (Class) mapping.get(name); + try { + if(!EntityCustomNpc.class.isAssignableFrom(c) && EntityLiving.class.isAssignableFrom(c) && c.getConstructor(new Class[] {World.class}) != null && !Modifier.isAbstract(c.getModifiers())){ + if(RenderManager.instance.getEntityClassRenderObject(c) instanceof RendererLivingEntity) + data.put(name.toString(),c.asSubclass(EntityLivingBase.class)); + } } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { } - } + } list = new ArrayList(data.keySet()); Collections.sort(list,String.CASE_INSENSITIVE_ORDER); } - @Override - public void initGui() { - EntityLivingBase entity = (EntityLivingBase) playerdata.getEntity(npc); - xOffset = entity == null?0:50; - super.initGui(); + @Override + public void initGui() { + EntityLivingBase entity = (EntityLivingBase) playerdata.getEntity(npc); + xOffset = entity == null?0:50; + super.initGui(); - String title = "CustomNPC"; - if(entity != null) - title = (String) EntityList.classToStringMapping.get(playerdata.getEntityClass()); - this.addButton(new GuiNpcButton(1, guiLeft + 140, guiTop, 100, 20, title)); + String title = "CustomNPC"; + if(entity != null) + title = (String) EntityList.classToStringMapping.get(playerdata.getEntityClass()); + this.addButton(new GuiNpcButton(1, guiLeft + 140, guiTop, 100, 20, title)); + + this.addButton(prev = new GuiNpcButton(0, guiLeft + 118, guiTop, 20, 20, "<")); + this.addButton(next = new GuiNpcButton(2, guiLeft + 242, guiTop, 20, 20, ">")); + prev.enabled = getCurrentEntityIndex() >= 0; + next.enabled = getCurrentEntityIndex() < list.size() - 1; + + if(entity == null){ + showPlayerButtons(); + } + else if(PixelmonHelper.isPixelmon(entity)){ + showPixelmonMenu(entity); + } + else{ + showEntityButtons(entity); + } + } - this.addButton(prev = new GuiNpcButton(0, guiLeft + 118, guiTop, 20, 20, "<")); - this.addButton(next = new GuiNpcButton(2, guiLeft + 242, guiTop, 20, 20, ">")); - prev.enabled = getCurrentEntityIndex() >= 0; - next.enabled = getCurrentEntityIndex() < list.size() - 1; - - if(entity == null){ - showPlayerButtons(); - } - else if(PixelmonHelper.isPixelmon(entity)){ - showPixelmonMenu(entity); - } - else{ - showEntityButtons(entity); - } - } - private void showPlayerButtons() { int y = guiTop ; - - addButton(new GuiNpcButton(8, guiLeft + 4, y += 22, 96, 20, "model.scale")); - addButton(new GuiNpcButton(4, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); + addButton(new GuiNpcButton(8, guiLeft + 4, y += 22, 96, 20, "model.scale")); + + addButton(new GuiNpcButton(4, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(1, "Head", guiLeft, y + 5, 0xFFFFFF)); - addButton(new GuiNpcButton(5, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); + addButton(new GuiNpcButton(5, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(2, "Body", guiLeft, y + 5, 0xFFFFFF)); - - addButton(new GuiNpcButton(6, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); + + addButton(new GuiNpcButton(6, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(3, "Arms", guiLeft, y + 5, 0xFFFFFF)); - addButton(new GuiNpcButton(7, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); + addButton(new GuiNpcButton(7, guiLeft + 50, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(4, "Legs", guiLeft, y + 5, 0xFFFFFF)); addButton(new GuiNpcButton(250, guiLeft + 50, y += 22, 50, 20, new String[]{"Default","Steve64","Alex"}, this.npc.display.modelType)); addLabel(new GuiNpcLabel(250, "Model", guiLeft, y + 5, 0xFFFFFF)); - - addButton(new GuiNpcButton(44, guiLeft + 310, guiTop + 14, 80, 20, "Save Model")); - addButton(new GuiNpcButton(45, guiLeft + 310, guiTop + 36, 80, 20, "Load Model")); - - - } - - private void showPixelmonMenu(EntityLivingBase entity) { + + addButton(new GuiNpcButton(44, guiLeft + 310, guiTop + 14, 80, 20, "Save Model")); + addButton(new GuiNpcButton(45, guiLeft + 310, guiTop + 36, 80, 20, "Load Model")); + + + } + + private void showPixelmonMenu(EntityLivingBase entity) { GuiCustomScroll scroll = new GuiCustomScroll(this, 0); scroll.setSize(120, 200); scroll.guiLeft = guiLeft; scroll.guiTop = guiTop + 20; addScroll(scroll); - + scroll.setList(PixelmonHelper.getPixelmonList()); scroll.setSelected(PixelmonHelper.getName(entity)); - + Minecraft.getMinecraft().thePlayer.sendChatMessage(PixelmonHelper.getName(entity)); } @@ -137,7 +137,7 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol if(entity instanceof EntityNPCInterface) return; int y = guiTop + 20; - + NBTTagCompound compound = getExtras(entity); Set keys = compound.func_150296_c(); int i = 0; @@ -148,7 +148,7 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol if(name.equals("Age")){ i++; addLabel(new GuiNpcLabel(0, "Child", guiLeft, y + 5 + i * 22, 0xFFFFFF)); - addButton(new GuiNpcButton(30, guiLeft + 80, y + i * 22, 50, 20, new String[]{"gui.no","gui.yes"},entity.isChild()?1:0)); + addButton(new GuiNpcButton(30, guiLeft + 80, y + i * 22, 50, 20, new String[]{"gui.no","gui.yes"},entity.isChild()?1:0)); } else if(base.getId() == 1){ byte b = ((NBTTagByte)base).func_150290_f(); @@ -158,9 +158,9 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol b = playerdata.extra.getByte(name); i++; addLabel(new GuiNpcLabel(100 + i, name, guiLeft, y + 5 + i * 22, 0xFFFFFF)); - addButton(new GuiNpcButton(100 + i, guiLeft + 80, y + i * 22, 50, 20, new String[]{"gui.no","gui.yes"}, b)); - - mapped.put(i, name); + addButton(new GuiNpcButton(100 + i, guiLeft + 80, y + i * 22, 50, 20, new String[]{"gui.no","gui.yes"}, b)); + + mapped.put(i, name); } } if(EntityList.getEntityString(entity).equals("doggystyle.Dog")){ @@ -169,11 +169,11 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol Method method = entity.getClass().getMethod("getBreedID"); breed = (Integer) method.invoke(entity); } catch (Exception e) { - + } i++; addLabel(new GuiNpcLabel(201, "Breed", guiLeft, y + 5 + i * 22, 0xFFFFFF)); - addButton(new GuiNpcButton(201, guiLeft + 80, y + i * 22, 50, 20, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}, breed)); + addButton(new GuiNpcButton(201, guiLeft + 80, y + i * 22, 50, 20, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}, breed)); } } private boolean isIgnored(String tag){ @@ -186,88 +186,88 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol private NBTTagCompound getExtras(EntityLivingBase entity) { NBTTagCompound fake = new NBTTagCompound(); new EntityFakeLiving(entity.worldObj).writeEntityToNBT(fake); - + NBTTagCompound compound = new NBTTagCompound(); try{ entity.writeEntityToNBT(compound); } catch(Exception e){ - + } Set keys = fake.func_150296_c(); for(String name : keys) compound.removeTag(name); - + return compound; } private int getCurrentEntityIndex(){ - return list.indexOf(EntityList.classToStringMapping.get(playerdata.getEntityClass())); - } + return list.indexOf(EntityList.classToStringMapping.get(playerdata.getEntityClass())); + } - @Override - protected void actionPerformed(GuiButton btn) { - super.actionPerformed(btn); - GuiNpcButton button = (GuiNpcButton) btn; - if(button.id == 0){ - int index = getCurrentEntityIndex(); - if(!prev.enabled) - return; - index--; - try{ - if(index < 0){ - playerdata.setEntityClass(null); - npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; - } - else{ - playerdata.setEntityClass(data.get(list.get(index))); - - EntityLivingBase entity = playerdata.getEntity(npc); - if(entity != null){ - RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); - npc.display.texture = NPCRendererHelper.getTexture(render,entity); - } - } - //npc.display.glowTexture = ""; + @Override + protected void actionPerformed(GuiButton btn) { + super.actionPerformed(btn); + GuiNpcButton button = (GuiNpcButton) btn; + if(button.id == 0){ + int index = getCurrentEntityIndex(); + if(!prev.enabled) + return; + index--; + try{ + if(index < 0){ + playerdata.setEntityClass(null); + npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; + } + else{ + playerdata.setEntityClass(data.get(list.get(index))); + + EntityLivingBase entity = playerdata.getEntity(npc); + if(entity != null){ + RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); + npc.display.texture = NPCRendererHelper.getTexture(render,entity); + } + } + //npc.display.glowTexture = ""; npc.display.skinOverlayData.overlayList.remove(0); npc.textureLocation = null; npc.updateHitbox(); - } - catch(Exception ex){ - npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; - } - initGui(); - } - if(button.id == 2){ - int index = getCurrentEntityIndex(); - if(!next.enabled) - return; - index++; - playerdata.setEntityClass(data.get(list.get(index))); + } + catch(Exception ex){ + npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; + } + initGui(); + } + if(button.id == 2){ + int index = getCurrentEntityIndex(); + if(!next.enabled) + return; + index++; + playerdata.setEntityClass(data.get(list.get(index))); - updateTexture(); - - initGui(); - } - - if(button.id == 1){ - this.mc.displayGuiScreen(new GuiEntitySelection(this, playerdata, npc)); - } + updateTexture(); - if(button.id == 4){ - this.mc.displayGuiScreen(new GuiModelHead(this, npc)); - } - if(button.id == 5){ - this.mc.displayGuiScreen(new GuiModelBody(this, npc)); - } - if(button.id == 6){ - this.mc.displayGuiScreen(new GuiModelArms(this, npc)); - } - if(button.id == 7){ - this.mc.displayGuiScreen(new GuiModelLegs(this, npc)); - } + initGui(); + } - // New Button for Changing Models + if(button.id == 1){ + this.mc.displayGuiScreen(new GuiEntitySelection(this, playerdata, npc)); + } + + if(button.id == 4){ + this.mc.displayGuiScreen(new GuiModelHead(this, npc)); + } + if(button.id == 5){ + this.mc.displayGuiScreen(new GuiModelBody(this, npc)); + } + if(button.id == 6){ + this.mc.displayGuiScreen(new GuiModelArms(this, npc)); + } + if(button.id == 7){ + this.mc.displayGuiScreen(new GuiModelLegs(this, npc)); + } + + // New Button for Changing Models // URL Swapper if(button.id == 250){ if(npc.display.modelType == 0){ @@ -288,75 +288,75 @@ public class GuiCreationScreen extends GuiModelInterface implements ICustomScrol npc.textureLocation = null; } - if(button.id == 8){ - this.mc.displayGuiScreen(new GuiModelScale(this, playerdata, npc)); - } - if(button.id == 30){ - playerdata.extra.setInteger("Age",button.getValue() == 1?-24000:0); - playerdata.clearEntity(); - } - - if(button.id == 44){ - this.mc.displayGuiScreen(new GuiPresetSave(this, playerdata)); - } + if(button.id == 8){ + this.mc.displayGuiScreen(new GuiModelScale(this, playerdata, npc)); + } + if(button.id == 30){ + playerdata.extra.setInteger("Age",button.getValue() == 1?-24000:0); + playerdata.clearEntity(); + } - if(button.id == 45){ - this.mc.displayGuiScreen(new GuiPresetSelection(this, playerdata)); - } - if(button.id >= 100 && button.id < 200){ - String name = mapped.get(button.id - 100); - if(name != null){ - playerdata.extra.setBoolean(name, button.getValue() == 1); - playerdata.clearEntity(); - } - } - if(button.id == 201){ + if(button.id == 44){ + this.mc.displayGuiScreen(new GuiPresetSave(this, playerdata)); + } + + if(button.id == 45){ + this.mc.displayGuiScreen(new GuiPresetSelection(this, playerdata)); + } + if(button.id >= 100 && button.id < 200){ + String name = mapped.get(button.id - 100); + if(name != null){ + playerdata.extra.setBoolean(name, button.getValue() == 1); + playerdata.clearEntity(); + } + } + if(button.id == 201){ try { - EntityLivingBase entity = playerdata.getEntity(npc); + EntityLivingBase entity = playerdata.getEntity(npc); Method method = entity.getClass().getMethod("setBreedID", int.class); method.invoke(entity, ((GuiNpcButton)button).getValue()); NBTTagCompound comp = new NBTTagCompound(); entity.writeEntityToNBT(comp); playerdata.extra.setString("EntityData21", comp.getString("EntityData21")); - playerdata.clearEntity(); - updateTexture(); + playerdata.clearEntity(); + updateTexture(); } catch (Exception e) { - + } - } - } - - private void updateTexture(){ - try{ - EntityLivingBase entity = playerdata.getEntity(npc); - if(entity != null){ - RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); - npc.display.texture = NPCRendererHelper.getTexture(render,entity); - } - else{ - npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; - } - //npc.display.glowTexture = ""; - npc.display.skinOverlayData.overlayList.remove(0); - npc.textureLocation = null; - npc.updateHitbox(); } - catch(Exception ex){ - npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; - } - } - - @Override - public void close(){ - Client.sendData(EnumPacketServer.ModelDataSave, playerdata.writeToNBT()); - displayGuiScreen(parent); - } + } + + private void updateTexture(){ + try{ + EntityLivingBase entity = playerdata.getEntity(npc); + if(entity != null){ + RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); + npc.display.texture = NPCRendererHelper.getTexture(render,entity); + } + else{ + npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; + } + //npc.display.glowTexture = ""; + npc.display.skinOverlayData.overlayList.remove(0); + npc.textureLocation = null; + npc.updateHitbox(); + } + catch(Exception ex){ + npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; + } + } + + @Override + public void close(){ + Client.sendData(EnumPacketServer.ModelDataSave, playerdata.writeToNBT()); + displayGuiScreen(parent); + } @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { playerdata.clearEntity(); playerdata.extra.setString("Name", scroll.getSelected()); - + EntityLivingBase entity = playerdata.getEntity(npc); RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); npc.display.texture = NPCRendererHelper.getTexture(render, entity); diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java b/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java index 6536f822f..799d019ab 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java @@ -119,7 +119,7 @@ public class GuiNPCTrader extends GuiContainerNPCInterface{ } else if (!container.isSlotEnabled(slot, player)) { String title = StatCollector.translateToLocal("trader.slotdisabled"); - this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title))/2, 131, 0x00DD00); + this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title))/2, 131, 0xFF4000 ); } else{ String title = StatCollector.translateToLocal("trader.sufficient"); diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 47caf4f90..bfcb6dab2 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -260,22 +260,22 @@ public class RenderNPCInterface extends RenderLiving{ GL11.glDepthMask(!npc.isInvisible()); GL11.glPushMatrix(); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glLoadIdentity(); - GL11.glTranslatef(npc.display.overlayRenderTicks * 0.001F * overlayData.getSpeedX(), npc.display.overlayRenderTicks * 0.001F * overlayData.getSpeedY(), 0.0F); - GL11.glScalef(overlayData.getScaleX(), overlayData.getScaleY(), 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + GL11.glTranslatef(npc.display.overlayRenderTicks * 0.001F * overlayData.getSpeedX(), npc.display.overlayRenderTicks * 0.001F * overlayData.getSpeedY(), 0.0F); + GL11.glScalef(overlayData.getScaleX(), overlayData.getScaleY(), 1.0F); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - float scale = 1.005f * overlayData.getSize(); - GL11.glTranslatef(overlayData.getOffsetX(), overlayData.getOffsetY(), overlayData.getOffsetZ()); - GL11.glScalef(scale, scale, scale); - if(mainModel instanceof ModelMPM){ - ((ModelMPM)mainModel).isArmor = true; - mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); - ((ModelMPM)mainModel).isArmor = false; - } - else - mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + float scale = 1.005f * overlayData.getSize(); + GL11.glTranslatef(overlayData.getOffsetX(), overlayData.getOffsetY(), overlayData.getOffsetZ()); + GL11.glScalef(scale, scale, scale); + if(mainModel instanceof ModelMPM){ + ((ModelMPM)mainModel).isArmor = true; + mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); + ((ModelMPM)mainModel).isArmor = false; + } + else + mainModel.render(entityliving, par2, par3, par4, par5, par6, par7); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_TEXTURE); diff --git a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java index f0390478e..f6b936b46 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java +++ b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java @@ -68,12 +68,12 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ NoppesUtilPlayer.consumeItem(entityplayer, role.inventoryCurrency.getStackInSlot(i + 18), role.ignoreDamage, role.ignoreNBT); ItemStack soldItem = item.copy(); givePlayer(soldItem, entityplayer); - role.addPurchase(i, entityplayer); + role.addPurchase(i, entityplayer.getDisplayName()); return soldItem; } public boolean isSlotEnabled(int slot, EntityPlayer player) { - return role.isSlotEnabled(slot, player); + return role.isSlotEnabled(slot, player.getDisplayName()); } public boolean canBuy(int slot, EntityPlayer player) { ItemStack currency = role.inventoryCurrency.getStackInSlot(slot); diff --git a/src/main/java/noppes/npcs/entity/data/DataTimers.java b/src/main/java/noppes/npcs/entity/data/DataTimers.java index 228e7a02b..85c62217c 100644 --- a/src/main/java/noppes/npcs/entity/data/DataTimers.java +++ b/src/main/java/noppes/npcs/entity/data/DataTimers.java @@ -99,7 +99,7 @@ public class DataTimers implements ITimers { DataTimers.Timer timer = (DataTimers.Timer)var3.next(); NBTTagCompound c = new NBTTagCompound(); c.setInteger("ID", timer.id); - c.setInteger("TimerTicks", timer.id); + c.setInteger("TimerTicks", timer.timerTicks); c.setBoolean("Repeat", timer.repeat); c.setInteger("Ticks", timer.ticks); list.appendTag(c); diff --git a/src/main/java/noppes/npcs/items/ItemSoulstoneEmpty.java b/src/main/java/noppes/npcs/items/ItemSoulstoneEmpty.java index 74e739860..3ebba0a74 100644 --- a/src/main/java/noppes/npcs/items/ItemSoulstoneEmpty.java +++ b/src/main/java/noppes/npcs/items/ItemSoulstoneEmpty.java @@ -1,9 +1,11 @@ package noppes.npcs.items; +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -13,11 +15,12 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.ServerCloneController; +import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleCompanion; import noppes.npcs.roles.RoleFollower; -import cpw.mods.fml.common.registry.GameRegistry; public class ItemSoulstoneEmpty extends Item { public ItemSoulstoneEmpty(){ @@ -75,21 +78,29 @@ public class ItemSoulstoneEmpty extends Item { return true; if(entity instanceof EntityNPCInterface){ EntityNPCInterface npc = (EntityNPCInterface) entity; - if(npc.advanced.role == EnumRoleType.Companion){ + if (npc.advanced.refuseSoulStone) return false; + if (CustomNpcs.SoulStoneFriendlyNPCs && npc.getFaction() != null) { + int p = npc.advanced.minFactionPointsToSoulStone; + if (p == -1 && npc.getFaction().isFriendlyToPlayer(player)) return true; + else if (p != -1) { + PlayerData data = PlayerDataController.instance.getPlayerData(player); + return data.factionData.getFactionPoints(npc.getFaction().getId()) >= p; + } + } + if (npc.advanced.role == EnumRoleType.Companion){ RoleCompanion role = (RoleCompanion) npc.roleInterface; if(role.getOwner() == player) return true; } - if(npc.advanced.role == EnumRoleType.Follower){ + if (npc.advanced.role == EnumRoleType.Follower){ RoleFollower role = (RoleFollower) npc.roleInterface; if(role.getOwner() == player) return !role.refuseSoulStone; } return CustomNpcs.SoulStoneNPCs; } - if(entity instanceof EntityAnimal) - return CustomNpcs.SoulStoneAnimals; - + if (entity instanceof EntityAnimal) return CustomNpcs.SoulStoneAnimals; + if (entity instanceof EntityVillager) return CustomNpcs.SoulStoneVillagers; return false; } } diff --git a/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java b/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java index 416bb62a3..b563329e9 100644 --- a/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java +++ b/src/main/java/noppes/npcs/items/ItemSoulstoneFilled.java @@ -78,7 +78,8 @@ public class ItemSoulstoneFilled extends Item { npc.ai.startPos = new int[]{x, y, z}; npc.setHealth(npc.getMaxHealth()); npc.setPosition((float)x + 0.5F, npc.getStartYPos(), (float)z + 0.5F); - + npc.advanced.soulStonePlayerName = player.getDisplayName(); + npc.advanced.soulStoneInit = true; if(npc.advanced.role == EnumRoleType.Companion && player != null){ PlayerData data = PlayerDataController.instance.getPlayerData(player); if(data.hasCompanion()) diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index 3c918dc57..60fe8ce75 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -118,23 +118,21 @@ public class RoleTrader extends RoleInterface{ return false; } - public void addPurchase(int slot, EntityPlayer player) { + public void addPurchase(int slot, String playerName) { if(slot >= 18 || slot < 0) return; ++purchases[slot]; - ++getArrayByName(player.getDisplayName(), playerPurchases)[slot]; + ++getArrayByName(playerName, playerPurchases)[slot]; } - public boolean isSlotEnabled(int slot, EntityPlayer player) { + public boolean isSlotEnabled(int slot, String playerName) { if(slot >= 18 || slot < 0) return false; if (disableSlot[slot] > 0) return false; - if (getArrayByName(player.getDisplayName(), playerDisableSlot)[slot] > 0) return false; - return true; + return getArrayByName(playerName, playerDisableSlot)[slot] <= 0; } public int[] getArrayByName(String name, HashMap map) { - int[] a = map.get(name); - if (a == null) a = map.put(name, new int[18]); - return a; + map.computeIfAbsent(name, k -> new int[18]); + return map.get(name); } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 29074db9d..3d8c3619a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -1,21 +1,29 @@ package noppes.npcs.scripted.entity; +import java.util.ArrayList; +import java.util.UUID; + import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.constants.*; +import noppes.npcs.constants.EnumAnimation; +import noppes.npcs.constants.EnumJobType; +import noppes.npcs.constants.EnumNavType; +import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.constants.EnumStandingType; import noppes.npcs.controllers.data.Line; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptFaction; +import noppes.npcs.scripted.constants.AnimationType; +import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.interfaces.ITimers; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.handler.IOverlayHandler; import noppes.npcs.scripted.interfaces.item.IItemStack; -import noppes.npcs.scripted.constants.AnimationType; -import noppes.npcs.scripted.constants.EntityType; -import noppes.npcs.scripted.interfaces.entity.ICustomNpc; -import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.scripted.roles.ScriptJobBard; import noppes.npcs.scripted.roles.ScriptJobConversation; import noppes.npcs.scripted.roles.ScriptJobFollower; @@ -31,12 +39,8 @@ import noppes.npcs.scripted.roles.ScriptRoleInterface; import noppes.npcs.scripted.roles.ScriptRoleMailman; import noppes.npcs.scripted.roles.ScriptRoleTrader; import noppes.npcs.scripted.roles.ScriptRoleTransporter; -import noppes.npcs.scripted.NpcAPI; import noppes.npcs.util.ValueUtil; -import java.util.ArrayList; -import java.util.UUID; - public class ScriptNpc extends ScriptLiving implements ICustomNpc { public EntityNPCInterface npc; @@ -862,6 +866,34 @@ public class ScriptNpc extends ScriptLiving imp npc.stats.canDespawn = canDespawn; npc.stats.playerSetCanDespawn = canDespawn; } + + public boolean spawnedFromSoulStone() { + return !npc.advanced.soulStonePlayerName.equals(""); + } + + public String getSoulStonePlayerName() { + return npc.advanced.soulStonePlayerName; + } + + public boolean getRefuseSoulStone() { + return npc.advanced.refuseSoulStone; + } + + public void setRefuseSoulStone(boolean refuse) { + npc.advanced.refuseSoulStone = refuse; + } + + public boolean isSoulStoneInit() { + return npc.advanced.soulStoneInit; + } + + public int getMinPointsToSoulStone() { + return npc.advanced.minFactionPointsToSoulStone; + } + + public void setMinPointsToSoulStone(int points) { + npc.advanced.minFactionPointsToSoulStone = points; + } public void giveItem(IPlayer player, IItemStack item){ npc.givePlayerItem((EntityPlayer) player.getMCEntity(), item.getMCItemStack()); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index d723f4bfb..e709cc83f 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -278,6 +278,40 @@ public class ScriptPlayer extends ScriptLivingBase chat.setChatStyle(style); player.addChatMessage(chat); } + + public void sendMessage(String message, String color, boolean bold, boolean italic, boolean underlined) { + EnumChatFormatting c = getColor(color); + if (c == null) return; + sendMessage(message, c, bold, italic, underlined); + } + + public void sendMessage(String message, String color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined) { + EnumChatFormatting c = getColor(color); + if (c == null) return; + sendMessage(message, c, bold, italic, obfuscated, strikethrough, underlined); + } + + private EnumChatFormatting getColor(String color) { + switch (color) { + case "black": return EnumChatFormatting.BLACK; + case "dark_blue": return EnumChatFormatting.DARK_BLUE; + case "dark_green": return EnumChatFormatting.DARK_GREEN; + case "dark_aqua": return EnumChatFormatting.DARK_AQUA; + case "dark_red": return EnumChatFormatting.DARK_RED; + case "dark_purple": return EnumChatFormatting.DARK_PURPLE; + case "gold": return EnumChatFormatting.GOLD; + case "gray": return EnumChatFormatting.GRAY; + case "dark_gray": return EnumChatFormatting.DARK_GRAY; + case "blue": return EnumChatFormatting.BLUE; + case "green": return EnumChatFormatting.GREEN; + case "aqua": return EnumChatFormatting.AQUA; + case "red": return EnumChatFormatting.RED; + case "light_purple": return EnumChatFormatting.LIGHT_PURPLE; + case "yellow": return EnumChatFormatting.YELLOW; + case "white": return EnumChatFormatting.WHITE; + default: return null; + } + } /** * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java index 754395065..93afe8911 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/ICustomNpc.java @@ -7,11 +7,11 @@ package noppes.npcs.scripted.interfaces.entity; import net.minecraft.entity.EntityCreature; import noppes.npcs.scripted.ScriptFaction; -import noppes.npcs.scripted.interfaces.ISkinOverlay; +import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.scripted.interfaces.handler.IOverlayHandler; import noppes.npcs.scripted.interfaces.item.IItemStack; -import noppes.npcs.scripted.interfaces.ITimers; -import noppes.npcs.scripted.roles.*; +import noppes.npcs.scripted.roles.ScriptJobInterface; +import noppes.npcs.scripted.roles.ScriptRoleInterface; public interface ICustomNpc extends IEntityLiving { /** @@ -623,7 +623,48 @@ public interface ICustomNpc extends IEntityLiving { * @param canDespawn True if the NPC should naturally despawn. False otherwise. */ void setNaturallyDespawns(boolean canDespawn); - + + /** + * @return true if this npc was spawned by a player using soulstone + */ + boolean spawnedFromSoulStone(); + + /** + * @return the name of the player who spawned this npc using soulstone. null if not spawned by soulstone + */ + String getSoulStonePlayerName(); + + /** + * @return true if npc was spawned by soul stone. becomes false after the init function is called. + */ + boolean isSoulStoneInit(); + + /** + * @return does this npc refuse to be taken by soul stone + */ + boolean getRefuseSoulStone(); + + /** + * @param refuse set if this npc refuses to be taken by soul stone + */ + void setRefuseSoulStone(boolean refuse); + + /** + * requires SoulStoneFriendlyNPCs in config to be true + * -1 by default + * if -1, the minimum points are the faction's friendly points + * @return the minimum faction points needed to soulstone this npc + */ + int getMinPointsToSoulStone(); + + /** + * requires SoulStoneFriendlyNPCs in config to be true + * -1 by default + * if -1, the minimum points are the faction's friendly points + * @param points the minimum faction points needed to soulstone this npc + */ + void setMinPointsToSoulStone(int points); + /** * @param player The player to give the item to * @param item The item given to the player diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java index e6cb61dd3..eba6dd9eb 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java @@ -100,6 +100,10 @@ public interface IPlayer extends IEntityLivingBase void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean underlined); void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined); + + void sendMessage(String message, String color, boolean bold, boolean italic, boolean underlined); + + void sendMessage(String message, String color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined); /** * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 8aa4f13dc..810e987c4 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -1,7 +1,6 @@ package noppes.npcs.scripted.roles; import foxz.utils.Market; -import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; import noppes.npcs.scripted.NpcAPI; @@ -105,7 +104,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader public boolean isSlotEnabled(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return false; - return role.isSlotEnabled(slot, (EntityPlayer)player.getMCEntity()); + return role.isSlotEnabled(slot, player.getDisplayName()); } public void disableSlot(int slot) {