Implemented Scripted Custom Items.

This commit is contained in:
Luis C.M committed 2022-05-11 01:10:31 -05:00
1 parent 5520fc5f2b
commit 26f5f86dca
34 files changed
+1476 -137

No files matched your search

+5 -52
View File
@@ -72,55 +72,7 @@ import noppes.npcs.blocks.tiles.TileWallBanner;
import noppes.npcs.blocks.tiles.TileWaypoint;
import noppes.npcs.blocks.tiles.TileWeaponRack;
import noppes.npcs.constants.EnumNpcToolMaterial;
import noppes.npcs.items.ItemBattleAxe;
import noppes.npcs.items.ItemBroadSword;
import noppes.npcs.items.ItemBullet;
import noppes.npcs.items.ItemClaw;
import noppes.npcs.items.ItemCrossbow;
import noppes.npcs.items.ItemDagger;
import noppes.npcs.items.ItemDaggerReversed;
import noppes.npcs.items.ItemElementalStaff;
import noppes.npcs.items.ItemExcalibur;
import noppes.npcs.items.ItemGlaive;
import noppes.npcs.items.ItemGun;
import noppes.npcs.items.ItemGunChainsaw;
import noppes.npcs.items.ItemKunai;
import noppes.npcs.items.ItemKunaiReversed;
import noppes.npcs.items.ItemLeafBlade;
import noppes.npcs.items.ItemMachineGun;
import noppes.npcs.items.ItemMounter;
import noppes.npcs.items.ItemMusic;
import noppes.npcs.items.ItemMusicBanjo;
import noppes.npcs.items.ItemMusicClarinet;
import noppes.npcs.items.ItemMusicOracina;
import noppes.npcs.items.ItemMusicViolin;
import noppes.npcs.items.ItemMusket;
import noppes.npcs.items.ItemNpcArmor;
import noppes.npcs.items.ItemNpcArmorColorable;
import noppes.npcs.items.ItemNpcBlock;
import noppes.npcs.items.ItemNpcCloner;
import noppes.npcs.items.ItemNpcColored;
import noppes.npcs.items.ItemNpcInterface;
import noppes.npcs.items.ItemNpcMovingPath;
import noppes.npcs.items.ItemNpcScripter;
import noppes.npcs.items.ItemNpcWand;
import noppes.npcs.items.ItemNpcWeaponInterface;
import noppes.npcs.items.ItemOrb;
import noppes.npcs.items.ItemPlaceholder;
import noppes.npcs.items.ItemRotatedShield;
import noppes.npcs.items.ItemScythe;
import noppes.npcs.items.ItemShield;
import noppes.npcs.items.ItemSkirt;
import noppes.npcs.items.ItemSlingshot;
import noppes.npcs.items.ItemSoulstoneEmpty;
import noppes.npcs.items.ItemSoulstoneFilled;
import noppes.npcs.items.ItemSpear;
import noppes.npcs.items.ItemStaff;
import noppes.npcs.items.ItemTeleporter;
import noppes.npcs.items.ItemThrowingShuriken;
import noppes.npcs.items.ItemThrowingWeapon;
import noppes.npcs.items.ItemWand;
import noppes.npcs.items.ItemWarhammer;
import noppes.npcs.items.*;
import cpw.mods.fml.common.registry.GameRegistry;
public class CustomItems {
@@ -130,7 +82,8 @@ public class CustomItems {
public static Item scripter;
public static Item moving;
public static Item mount;
public static Item teleporter;
public static Item teleporter;
public static Item scripted_item;
public static Item soulstoneEmpty;
public static Item soulstoneFull;
@@ -300,8 +253,7 @@ public class CustomItems {
public static CreativeTabNpcs tabWeapon;
public static CreativeTabNpcs tabBlocks = new CreativeTabNpcs("cnpcsb");
public static CreativeTabNpcs tabMisc = new CreativeTabNpcs("cnpcsm");
public static void load(){
GameRegistry.registerTileEntity(TileRedstoneBlock.class, "TileRedstoneBlock");
GameRegistry.registerTileEntity(TileBlockAnvil.class, "TileBlockAnvil");
@@ -338,6 +290,7 @@ public class CustomItems {
moving = new ItemNpcMovingPath().setUnlocalizedName("npcMovingPath").setFull3D();
mount = new ItemMounter().setUnlocalizedName("npcMounter").setFull3D();
teleporter = new ItemTeleporter().setUnlocalizedName("npcTeleporter").setFull3D();
scripted_item = new ItemScripted().setUnlocalizedName("scripted_item").setFull3D();
redstoneBlock = new BlockNpcRedstone().setHardness(50.0F).setResistance(2000).setBlockName("npcRedstoneBlock").setBlockTextureName("customnpcs:npcRedstoneBlock").setCreativeTab(tab);
carpentyBench = new BlockCarpentryBench().setBlockName("npcCarpentyBench").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
+47 -2
View File
@@ -21,11 +21,10 @@ import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.world.WorldEvent;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.ForgeDataScript;
import noppes.npcs.controllers.data.NPCDataScript;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.*;
import noppes.npcs.scripted.entity.ScriptNpc;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.event.*;
import noppes.npcs.scripted.event.PlayerEvent.ChatEvent;
@@ -40,6 +39,8 @@ import noppes.npcs.scripted.interfaces.ICustomGui;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
import noppes.npcs.constants.EnumScriptType;
import org.apache.commons.lang3.StringUtils;
@@ -50,6 +51,50 @@ public class EventHooks {
public EventHooks() {
}
public static void onScriptItemInit(ScriptCustomItem handler) {
if (!handler.isClient()) {
noppes.npcs.scripted.event.ItemEvent.InitEvent event = new noppes.npcs.scripted.event.ItemEvent.InitEvent(handler);
handler.callScript(EnumScriptType.INIT, event);
WrapperNpcAPI.EVENT_BUS.post(event);
}
}
public static void onScriptItemUpdate(ScriptCustomItem handler, EntityPlayer player) {
if (!handler.isClient()) {
noppes.npcs.scripted.event.ItemEvent.UpdateEvent event = new noppes.npcs.scripted.event.ItemEvent.UpdateEvent(handler, (ScriptPlayer)ScriptController.Instance.getScriptForEntity(player));
handler.callScript(EnumScriptType.TICK, event);
WrapperNpcAPI.EVENT_BUS.post(event);
}
}
public static boolean onScriptItemTossed(ScriptCustomItem handler, EntityPlayer player, EntityItem entity) {
ItemEvent.TossedEvent event = new ItemEvent.TossedEvent(handler, (ScriptPlayer)ScriptController.Instance.getScriptForEntity(player), (ScriptEntity)NpcAPI.Instance().getIEntity(entity));
handler.callScript(EnumScriptType.TOSSED, event);
return WrapperNpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemPickedUp(ScriptCustomItem handler, EntityPlayer player) {
ItemEvent.PickedUpEvent event = new ItemEvent.PickedUpEvent(handler, (ScriptPlayer)ScriptController.Instance.getScriptForEntity(player));
handler.callScript(EnumScriptType.PICKEDUP, event);
return WrapperNpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemSpawn(ScriptCustomItem handler, EntityItem entity) {
ItemEvent.SpawnEvent event = new ItemEvent.SpawnEvent(handler, (ScriptEntity)NpcAPI.Instance().getIEntity(entity));
handler.callScript(EnumScriptType.SPAWN, event);
return WrapperNpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemInteract(ScriptCustomItem handler, noppes.npcs.scripted.event.ItemEvent.InteractEvent event) {
handler.callScript(EnumScriptType.INTERACT, event);
return WrapperNpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemAttack(ScriptCustomItem handler, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) {
handler.callScript(EnumScriptType.ATTACK, event);
return WrapperNpcAPI.EVENT_BUS.post(event);
}
public static void onNPCInit(EntityNPCInterface npc) {
if(npc == null || npc.wrappedNPC == null)
return;
@@ -54,6 +54,7 @@ import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.item.ScriptCustomItem;
public class PacketHandlerServer{
@@ -123,6 +124,8 @@ public class PacketHandlerServer{
npcScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)
forgeScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
itemScriptPackets(type, buffer, player);
else if (item.getItem() == CustomItems.scripter)
scriptPackets(type, buffer, player, npc);
else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock))
@@ -187,6 +190,26 @@ public class PacketHandlerServer{
}
}
private void itemScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
if (type == EnumPacketServer.ScriptItemDataGet) {
ScriptCustomItem iw = new ScriptCustomItem(player.getHeldItem());
NBTTagCompound compound = iw.getMCNbt();
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound});
} else if (type == EnumPacketServer.ScriptItemDataSave) {
if (!player.capabilities.isCreativeMode) {
return;
}
NBTTagCompound compound = Server.readNBT(buffer);
ScriptCustomItem wrapper = new ScriptCustomItem(player.getHeldItem());
wrapper.setMCNbt(compound);
wrapper.lastInited = -1L;
wrapper.saveScriptData();
player.sendContainerToPlayer(player.inventoryContainer);
}
}
private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.DimensionsGet){
HashMap<String,Integer> map = new HashMap<String,Integer>();
@@ -27,8 +27,11 @@ import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
@@ -36,6 +39,7 @@ import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent;
@@ -46,13 +50,17 @@ import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.event.world.*;
import net.minecraftforge.event.world.WorldEvent.PotentialSpawns;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.event.ForgeEvent;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
import org.lwjgl.input.Mouse;
public class ScriptPlayerEventHandler {
@@ -70,6 +78,17 @@ public class ScriptPlayerEventHandler {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
ScriptPlayer scriptPlayer = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(player);
EventHooks.onPlayerTick(handler, scriptPlayer);
for(int i = 0; i < player.inventory.getSizeInventory(); ++i) {
ItemStack item = player.inventory.getStackInSlot(i);
try {
if (item.stackSize > 0 && item.getItem() == CustomItems.scripted_item) {
ScriptCustomItem isw = (ScriptCustomItem) WrapperNpcAPI.Instance().getIItemStack(item);
EventHooks.onScriptItemUpdate(isw, player);
}
} catch(Exception e) {}
}
}
PlayerData playerData = PlayerDataController.instance.getPlayerData(player);
@@ -96,6 +115,14 @@ public class ScriptPlayerEventHandler {
ScriptPlayer scriptPlayer = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(event.entityPlayer);
noppes.npcs.scripted.event.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.PlayerEvent.InteractEvent(scriptPlayer, 1, NpcAPI.Instance().getIEntity(event.target));
event.setCanceled(EventHooks.onPlayerInteract(handler, ev));
try {
if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
ScriptCustomItem isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem());
noppes.npcs.scripted.event.ItemEvent.InteractEvent eve = new noppes.npcs.scripted.event.ItemEvent.InteractEvent(isw, handler.getPlayer(), 2, NpcAPI.Instance().getIBlock(event.entityPlayer.worldObj, new BlockPos(event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ)));
event.setCanceled(EventHooks.onScriptItemInteract(isw, eve));
}
} catch(Exception e) {}
}
}
@@ -229,6 +256,13 @@ public class ScriptPlayerEventHandler {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
ScriptPlayer scriptPlayer = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(event.player);
EventHooks.onPlayerPickUp(handler, scriptPlayer, event.pickedUp);
try {
if (event.player.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
ScriptCustomItem isw = ItemScripted.GetWrapper(event.player.getHeldItem());
EventHooks.onScriptItemPickedUp(isw, event.player);
}
} catch(Exception e) {}
}
}
@@ -325,6 +359,13 @@ public class ScriptPlayerEventHandler {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
ScriptPlayer scriptPlayer = (ScriptPlayer) ScriptController.Instance.getScriptForEntity(event.player);
EventHooks.onPlayerToss(handler, scriptPlayer, event.entityItem);
try {
if (event.player.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
ScriptCustomItem isw = ItemScripted.GetWrapper(event.player.getHeldItem());
EventHooks.onScriptItemTossed(isw, event.player, event.entityItem);
}
} catch (Exception e){};
}
}
@@ -423,6 +464,17 @@ public class ScriptPlayerEventHandler {
noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent((ScriptPlayer)ScriptController.Instance.getScriptForEntity((EntityPlayer)event.source.getEntity()), event.entityLiving, event.ammount, event.source);
event.setCanceled(EventHooks.onPlayerDamagedEntity(handler, pevent1));
event.ammount = pevent1.damage;
try {
if (((EntityPlayer) event.source.getEntity()).getHeldItem().getItem() != null
&& ((EntityPlayer) event.source.getEntity()).getHeldItem().getItem() == CustomItems.scripted_item
&& !event.isCanceled()) {
ScriptCustomItem isw = ItemScripted.GetWrapper(((EntityPlayer) event.source.getEntity()).getHeldItem());
noppes.npcs.scripted.event.ItemEvent.AttackEvent eve = new noppes.npcs.scripted.event.ItemEvent.AttackEvent(isw, handler.getPlayer(), 1, event.entityLiving);
eve.setCanceled(event.isCanceled());
event.setCanceled(EventHooks.onScriptItemAttack(isw, eve));
}
} catch(Exception e) {}
}
}
@@ -464,6 +516,20 @@ public class ScriptPlayerEventHandler {
}
}
@SubscribeEvent
public void invoke(EntityJoinWorldEvent event) {
if (!event.world.isRemote && event.entity instanceof EntityItem) {
EntityItem entity = (EntityItem)event.entity;
ItemStack stack = entity.getEntityItem();
try {
if (stack.stackSize > 0 && stack.getItem() == CustomItems.scripted_item && EventHooks.onScriptItemSpawn(ItemScripted.GetWrapper(stack), entity)) {
event.setCanceled(true);
}
} catch(Exception e) {}
}
}
@SubscribeEvent(
priority = EventPriority.HIGHEST
)
@@ -100,6 +100,7 @@ import noppes.npcs.client.gui.roles.GuiNpcItemGiver;
import noppes.npcs.client.gui.roles.GuiNpcTraderSetup;
import noppes.npcs.client.gui.roles.GuiNpcTransporter;
import noppes.npcs.client.gui.script.GuiScriptGlobal;
import noppes.npcs.client.gui.script.GuiScriptItem;
import noppes.npcs.client.model.*;
import noppes.npcs.client.renderer.*;
import noppes.npcs.client.renderer.blocks.BlockBannerRenderer;
@@ -133,6 +134,7 @@ import noppes.npcs.containers.*;
import noppes.npcs.controllers.PlayerData;
import noppes.npcs.entity.*;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.interfaces.IWorld;
import org.lwjgl.input.Keyboard;
@@ -358,6 +360,9 @@ public class ClientProxy extends CommonProxy {
else if(gui == EnumGuiType.Script && CustomNpcs.ScriptingEnabled)
return new GuiScript(npc);
else if (gui == EnumGuiType.ScriptItem)
return new GuiScriptItem(Minecraft.getMinecraft().thePlayer);
else if(gui == EnumGuiType.PlayerAnvil)
return new GuiNpcCarpentryBench((ContainerCarpentryBench) container);
@@ -536,7 +541,11 @@ public class ClientProxy extends CommonProxy {
@Override
public void registerItem(Item item) {
MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer());
if (item instanceof ItemScripted) {
MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer());
} else {
MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer());
}
}
public static void bindTexture(ResourceLocation location) {
@@ -43,6 +43,8 @@ import noppes.npcs.entity.EntityNPCInterface;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptItemStack;
public class PacketHandlerClient extends PacketHandlerServer{
@@ -0,0 +1,28 @@
package noppes.npcs.client.gui.script;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomItems;
import noppes.npcs.client.Client;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.scripted.item.ScriptCustomItem;
public class GuiScriptItem extends GuiScriptInterface {
private ScriptCustomItem item;
public GuiScriptItem(EntityPlayer player) {
this.handler = this.item = new ScriptCustomItem(new ItemStack(CustomItems.scripted_item));
Client.sendData(EnumPacketServer.ScriptItemDataGet, new Object[0]);
}
public void setGuiData(NBTTagCompound compound) {
this.item.setMCNbt(compound);
super.setGuiData(compound);
}
public void save() {
super.save();
Client.sendData(EnumPacketServer.ScriptItemDataSave, new Object[]{this.item.getMCNbt()});
}
}
@@ -0,0 +1,472 @@
package noppes.npcs.client.renderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.IResource;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.items.ItemRenderInterface;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import static net.minecraft.client.renderer.entity.RenderItem.renderInFrame;
public class CustomItemRenderer implements IItemRenderer {
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private static final ResourceLocation enchant = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private final Random random = new Random();
private int itemRenderTicks = 0;
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return type != ItemRenderType.FIRST_PERSON_MAP;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
return false;
}
@Override
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
InputStream inputstream = null;
ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack);
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1) {
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(scriptCustomItem.texture));
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
scriptCustomItem.width = bufferedimage.getWidth();
scriptCustomItem.height = bufferedimage.getHeight();
scriptCustomItem.saveItemData();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputstream != null) {
inputstream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
if(scriptCustomItem.width == -1 || scriptCustomItem.height == -1)
return;
if (type == ItemRenderType.INVENTORY) {
renderInventoryCustomItem(scriptCustomItem);
return;
}
((ItemScripted) itemStack.getItem()).renderCustomAttributes(itemStack);
if (type == ItemRenderType.ENTITY) {
EntityItem entityItem = (EntityItem) data[1];
renderEntityCustomItem(scriptCustomItem, itemStack, entityItem);
return;
}
EntityLivingBase entityLivingBase = (EntityLivingBase) data[1];
renderItem3d(scriptCustomItem, entityLivingBase, itemStack);
}
public void renderEntityCustomItem(ScriptCustomItem scriptCustomItem, ItemStack itemStack, EntityItem entityItem) {
this.itemRenderTicks++;
int pass = 0;
float bobbingY = (float)(Math.sin((float)this.itemRenderTicks/40.0F) + 1) * scriptCustomItem.scaleY/6.0F;
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, bobbingY, 0.0F);
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
Tessellator tessellator = Tessellator.instance;
float f14 = 0.0F;
float f15 = 1.0F;
float f4 = 0.0F;
float f5 = 1.0F;
float f6 = 1.0F;
float f7 = 0.5F;
float f8 = 0.25F;
float f10;
if (RenderManager.instance.options.fancyGraphics)
{
GL11.glPushMatrix();
if (renderInFrame)
{
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
}
else
{
GL11.glRotatef((((float)entityItem.age) / 20.0F + entityItem.hoverStart) * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
}
float f9 = 0.0625F;
f10 = 0.021875F;
int j = itemStack.stackSize;
byte b0;
if (j < 2)
{
b0 = 1;
}
else if (j < 16)
{
b0 = 2;
}
else if (j < 32)
{
b0 = 3;
}
else
{
b0 = 4;
}
GL11.glTranslatef(-f7, -f8, -((f9 + f10) * (float)b0 / 2.0F));
for (int k = 0; k < b0; ++k)
{
// Makes items offset when in 3D, like when in 2D, looks much better. Considered a vanilla bug...
GL11.glTranslatef(0f, 0f, f9 + f10);
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, scriptCustomItem.width, scriptCustomItem.height, f9);
if (itemStack.hasEffect(pass))
{
GL11.glDepthFunc(GL11.GL_EQUAL);
GL11.glDisable(GL11.GL_LIGHTING);
RenderManager.instance.renderEngine.bindTexture(RES_ITEM_GLINT);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
float f11 = 0.76F;
GL11.glColor4f(0.5F * f11, 0.25F * f11, 0.8F * f11, 1.0F);
GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glPushMatrix();
float f12 = 0.125F;
GL11.glScalef(f12, f12, f12);
float f13 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
GL11.glTranslatef(f13, 0.0F, 0.0F);
GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f9);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(f12, f12, f12);
f13 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
GL11.glTranslatef(-f13, 0.0F, 0.0F);
GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f9);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDepthFunc(GL11.GL_LEQUAL);
}
}
GL11.glPopMatrix();
}
else
{
int j = itemStack.stackSize;
int b0;
if (j < 2)
{
b0 = 1;
}
else if (j < 16)
{
b0 = 2;
}
else if (j < 32)
{
b0 = 3;
}
else
{
b0 = 4;
}
for (int l = 0; l < b0; ++l)
{
GL11.glPushMatrix();
if (l > 0)
{
f10 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
float f16 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
float f17 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
GL11.glTranslatef(f10, f16, f17);
}
if (!renderInFrame)
{
GL11.glRotatef(180.0F - RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
}
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f14, (double)f5);
tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f15, (double)f5);
tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f15, (double)f4);
tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f14, (double)f4);
tessellator.draw();
GL11.glPopMatrix();
}
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
}
public void renderInventoryCustomItem(ScriptCustomItem scriptCustomItem) {
GL11.glPushMatrix();
int color = scriptCustomItem.getColor();
float itemRed = (color >> 16 & 255) / 255f;
float itemGreen = (color >> 8 & 255) / 255f;
float itemBlue = (color & 255) / 255f;
GL11.glColor4f(itemRed, itemGreen, itemBlue, 1.0F);
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
renderCustomItemSlot(0,0,16,16, scriptCustomItem.item);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
if (scriptCustomItem.item.hasEffect(0))
{
renderEffect(Minecraft.getMinecraft().getTextureManager(), 0, 0);
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
public void renderEffect(TextureManager manager, int x, int y)
{
GL11.glDepthFunc(GL11.GL_EQUAL);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDepthMask(false);
manager.bindTexture(RES_ITEM_GLINT);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);
this.renderGlint(x - 2, y - 2, 20, 20);
GL11.glDepthMask(true);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDepthFunc(GL11.GL_LEQUAL);
}
private void renderGlint(int p_77018_2_, int p_77018_3_, int p_77018_4_, int p_77018_5_)
{
for (int j1 = 0; j1 < 2; ++j1)
{
OpenGlHelper.glBlendFunc(772, 1, 0, 0);
float f = 0.00390625F;
float f1 = 0.00390625F;
float f2 = (float)(Minecraft.getSystemTime() % (long)(3000 + j1 * 1873)) / (3000.0F + (float)(j1 * 1873)) * 256.0F;
float f3 = 0.0F;
Tessellator tessellator = Tessellator.instance;
float f4 = 4.0F;
if (j1 == 1)
{
f4 = -1.0F;
}
tessellator.startDrawingQuads();
tessellator.addVertexWithUV((double)(p_77018_2_ + 0), (double)(p_77018_3_ + p_77018_5_), 0, (double)((f2 + (float)p_77018_5_ * f4) * f), (double)((f3 + (float)p_77018_5_) * f1));
tessellator.addVertexWithUV((double)(p_77018_2_ + p_77018_4_), (double)(p_77018_3_ + p_77018_5_), 0, (double)((f2 + (float)p_77018_4_ + (float)p_77018_5_ * f4) * f), (double)((f3 + (float)p_77018_5_) * f1));
tessellator.addVertexWithUV((double)(p_77018_2_ + p_77018_4_), (double)(p_77018_3_ + 0), 0, (double)((f2 + (float)p_77018_4_) * f), (double)((f3 + 0.0F) * f1));
tessellator.addVertexWithUV((double)(p_77018_2_ + 0), (double)(p_77018_3_ + 0), 0, (double)((f2 + 0.0F) * f), (double)((f3 + 0.0F) * f1));
tessellator.draw();
}
}
public void renderCustomItemSlot(int posX, int posY, int imageWidth, int imageHeight, ItemStack itemStack) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.addVertexWithUV((double)(posX), (double)(posY + imageHeight), 0, 0, 1);
tessellator.addVertexWithUV((double)(posX + imageWidth), (double)(posY + imageHeight), 0, 1, 1);
tessellator.addVertexWithUV((double)(posX + imageWidth), (double)(posY), 0, 1, 0);
tessellator.addVertexWithUV((double)(posX), (double)(posY), 0, 0, 0);
tessellator.draw();
}
public void renderItem3d(ScriptCustomItem scriptCustomItem, EntityLivingBase entityLivingBase, ItemStack itemStack) {
Minecraft mc = Minecraft.getMinecraft();
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
ResourceLocation location = new ResourceLocation(scriptCustomItem.texture);
texturemanager.bindTexture(location);
Tessellator tessellator = Tessellator.instance;
IIcon icon = entityLivingBase.getItemIcon(itemStack, par3);
if (icon == null) {
return;
}
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
renderCustomItemIn2D(itemStack, tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 0.0625F);
if (itemStack.hasEffect(par3)) {
GL11.glDepthFunc(GL11.GL_EQUAL);
GL11.glDisable(GL11.GL_LIGHTING);
texturemanager.bindTexture(enchant);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
float f7 = 0.76F;
GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
GL11.glMatrixMode(GL11.GL_TEXTURE);
GL11.glPushMatrix();
float f8 = 0.125F;
GL11.glScalef(f8, f8, f8);
float f9 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
GL11.glTranslatef(f9, 0.0F, 0.0F);
GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(f8, f8, f8);
f9 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
GL11.glTranslatef(-f9, 0.0F, 0.0F);
GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDepthFunc(GL11.GL_LEQUAL);
}
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
public static void renderCustomItemIn2D(ItemStack itemStack, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_)
{
GL11.glEnable(GL11.GL_BLEND);
int width = ItemScripted.GetWrapper(itemStack).width;
int height = ItemScripted.GetWrapper(itemStack).height;
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(0.0F, 0.0F, 1.0F);
p_78439_0_.addVertexWithUV(0.0D, 0.0D, 0.0D, (double)p_78439_1_, (double)p_78439_4_);
p_78439_0_.addVertexWithUV(1.0D, 0.0D, 0.0D, (double)p_78439_3_, (double)p_78439_4_);
p_78439_0_.addVertexWithUV(1.0D, 1.0D, 0.0D, (double)p_78439_3_, (double)p_78439_2_);
p_78439_0_.addVertexWithUV(0.0D, 1.0D, 0.0D, (double)p_78439_1_, (double)p_78439_2_);
p_78439_0_.draw();
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(0.0F, 0.0F, -1.0F);
p_78439_0_.addVertexWithUV(0.0D, 1.0D, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)p_78439_2_);
p_78439_0_.addVertexWithUV(1.0D, 1.0D, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)p_78439_2_);
p_78439_0_.addVertexWithUV(1.0D, 0.0D, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)p_78439_4_);
p_78439_0_.addVertexWithUV(0.0D, 0.0D, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)p_78439_4_);
p_78439_0_.draw();
float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float)width;
float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float)height;
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(-1.0F, 0.0F, 0.0F);
int k;
float f7;
float f8;
for (k = 0; k < width; ++k)
{
f7 = (float)k / (float)width;
f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5;
p_78439_0_.addVertexWithUV((double)f7, 0.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_4_);
p_78439_0_.addVertexWithUV((double)f7, 0.0D, 0.0D, (double)f8, (double)p_78439_4_);
p_78439_0_.addVertexWithUV((double)f7, 1.0D, 0.0D, (double)f8, (double)p_78439_2_);
p_78439_0_.addVertexWithUV((double)f7, 1.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_2_);
}
p_78439_0_.draw();
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(1.0F, 0.0F, 0.0F);
float f9;
for (k = 0; k < width; ++k)
{
f7 = (float)k / (float)width;
f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5;
f9 = f7 + 1.0F / (float)width;
p_78439_0_.addVertexWithUV((double)f9, 1.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_2_);
p_78439_0_.addVertexWithUV((double)f9, 1.0D, 0.0D, (double)f8, (double)p_78439_2_);
p_78439_0_.addVertexWithUV((double)f9, 0.0D, 0.0D, (double)f8, (double)p_78439_4_);
p_78439_0_.addVertexWithUV((double)f9, 0.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_4_);
}
p_78439_0_.draw();
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(0.0F, 1.0F, 0.0F);
for (k = 0; k < height; ++k)
{
f7 = (float)k / (float)height;
f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6;
f9 = f7 + 1.0F / (float)height;
p_78439_0_.addVertexWithUV(0.0D, (double)f9, 0.0D, (double)p_78439_1_, (double)f8);
p_78439_0_.addVertexWithUV(1.0D, (double)f9, 0.0D, (double)p_78439_3_, (double)f8);
p_78439_0_.addVertexWithUV(1.0D, (double)f9, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)f8);
p_78439_0_.addVertexWithUV(0.0D, (double)f9, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)f8);
}
p_78439_0_.draw();
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(0.0F, -1.0F, 0.0F);
for (k = 0; k < height; ++k)
{
f7 = (float)k / (float)height;
f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6;
p_78439_0_.addVertexWithUV(1.0D, (double)f7, 0.0D, (double)p_78439_3_, (double)f8);
p_78439_0_.addVertexWithUV(0.0D, (double)f7, 0.0D, (double)p_78439_1_, (double)f8);
p_78439_0_.addVertexWithUV(0.0D, (double)f7, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)f8);
p_78439_0_.addVertexWithUV(1.0D, (double)f7, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)f8);
}
p_78439_0_.draw();
}
}
@@ -1,5 +1,56 @@
package noppes.npcs.constants;
public enum EnumGuiType {
MainMenuDisplay, MainMenuInv, MainMenuStats, ManageFactions, MainMenuAdvanced, MainMenuGlobal, PlayerBankSmall, PlayerFollowerHire, PlayerFollower, SetupItemGiver, SetupTrader, SetupFollower, PlayerTrader, PlayerTransporter, RedstoneBlock, SetupTransporter, ManageTransport, ManageBanks, MobSpawner, SetupBank, ManageDialogs, ManageQuests, PlayerAnvil, QuestReward, ManageRecipes, QuestItem, NpcRemote, ScriptEvent, MoneyBag, MainMenuAI, MovingPath, PlayerBankUnlock, PlayerBankUprade, PlayerBankLarge, MobSpawnerAdd, PlayerMailbox, PlayerMailman, Waypoint, MerchantAdd, MobSpawnerMounter, Crate, NpcDimensions, Border, BigSign, Script, Companion, CompanionInv, CompanionTalent, CompanionTrader, ManageLinked, CustomGui;
MainMenuDisplay,
MainMenuInv,
MainMenuStats,
ManageFactions,
MainMenuAdvanced,
MainMenuGlobal,
PlayerBankSmall,
PlayerFollowerHire,
PlayerFollower,
SetupItemGiver,
SetupTrader,
SetupFollower,
PlayerTrader,
PlayerTransporter,
RedstoneBlock,
SetupTransporter,
ManageTransport,
ManageBanks,
MobSpawner,
SetupBank,
ManageDialogs,
ManageQuests,
PlayerAnvil,
QuestReward,
ManageRecipes,
QuestItem,
NpcRemote,
ScriptEvent,
MoneyBag,
MainMenuAI,
MovingPath,
PlayerBankUnlock,
PlayerBankUprade,
PlayerBankLarge,
MobSpawnerAdd,
PlayerMailbox,
PlayerMailman,
Waypoint,
MerchantAdd,
MobSpawnerMounter,
Crate,
NpcDimensions,
Border,
BigSign,
Script,
Companion,
CompanionInv,
CompanionTalent,
CompanionTrader,
ManageLinked,
CustomGui,
ScriptItem;
}
@@ -1,5 +1,41 @@
package noppes.npcs.constants;
package
noppes.npcs.constants;
public enum EnumPacketClient {
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN, OVERLAY_DATA, OVERLAY_CLOSE, SWING_PLAYER_ARM;
CHAT,
MESSAGE,
SYNCRECIPES_ADD,
SYNCRECIPES_WORKBENCH,
DIALOG,
QUEST_COMPLETION,
EDIT_NPC,
PLAY_SOUND,
PLAY_MUSIC,
UPDATE_NPC,
ROLE,
GUI,
SCRIPTED_PARTICLE,
PARTICLE,
DELETE_NPC,
SCROLL_LIST,
SCROLL_DATA,
SCROLL_DATA_PART,
SCROLL_SELECTED,
GUI_REDSTONE,
GUI_WAYPOINT,
GUI_DATA,
GUI_ERROR,
GUI_CLOSE,
VILLAGER_LIST,
CHATBUBBLE,
SYNCRECIPES_CARPENTRYBENCH,
CLONE,
OPEN_BOOK,
DIALOG_DUMMY,
CONFIG,
ISGUIOPEN,
OVERLAY_DATA,
OVERLAY_CLOSE,
SWING_PLAYER_ARM,
UPDATE_ITEM
}
@@ -43,6 +43,9 @@ public enum EnumPacketServer {
ScriptNPCSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptNPCGet(false),
ScriptItemDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false),
ScriptItemDataGet(false),
LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED),
ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true),
PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA),
@@ -0,0 +1,112 @@
package noppes.npcs.items;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
public class ItemScripted extends Item implements ItemRenderInterface {
public ItemScripted() {
maxStackSize = 1;
setCreativeTab(CustomItems.tab);
CustomNpcs.proxy.registerItem(this);
setHasSubtypes(true);
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister){
this.itemIcon = Items.iron_pickaxe.getIconFromDamage(0);
}
@Override
public int getColorFromItemStack(ItemStack itemStack, int par2){
return 0x8B4513;
}
@Override
public boolean requiresMultipleRenderPasses(){
return true;
}
@Override
public Item setUnlocalizedName(String name){
GameRegistry.registerItem(this, name);
return super.setUnlocalizedName(name);
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer entityPlayer)
{
if(!world.isRemote)
return stack;
if(entityPlayer.isSneaking()) {
CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, entityPlayer);
}
entityPlayer.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
public int getMaxItemUseDuration(ItemStack stack){
return (new ScriptCustomItem(stack)).getMaxItemUseDuration();
}
public static ScriptCustomItem GetWrapper(ItemStack stack) {
return new ScriptCustomItem(stack);
}
public boolean showDurabilityBar(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptCustomItem && (new ScriptCustomItem(stack)).durabilityShow;
}
public double getDurabilityForDisplay(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptCustomItem ? 1.0D - (new ScriptCustomItem(stack)).durabilityValue : 1.0D;
}
public int getItemStackLimit(ItemStack stack) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
return istack instanceof ScriptCustomItem ? (new ScriptCustomItem(stack)).getMaxStackSize() : super.getItemStackLimit(stack);
}
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
return true;
}
@Override
public void renderSpecial() {}
public void renderCustomAttributes(ItemStack itemStack) {
ScriptCustomItem scriptCustomItem = GetWrapper(itemStack);
GL11.glTranslatef(scriptCustomItem.translateX, scriptCustomItem.translateY, scriptCustomItem.translateZ);
GL11.glRotatef(scriptCustomItem.rotationX, 1, 0, 0);
GL11.glRotatef(scriptCustomItem.rotationY, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZ, 0, 0, 1);
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
int color = scriptCustomItem.getColor();
float itemRed = (color >> 16 & 255) / 255f;
float itemGreen = (color >> 8 & 255) / 255f;
float itemBlue = (color & 255) / 255f;
GL11.glColor4f(itemRed, itemGreen, itemBlue, 1.0F);
}
}
@@ -20,6 +20,7 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptItemStack;
public abstract class NpcAPI {
private static NpcAPI instance = null;
@@ -86,7 +87,7 @@ public abstract class NpcAPI {
public abstract ScriptPlayer[] getAllServerPlayers();
public abstract ScriptItemStack createItem(String id, int damage, int size);
public abstract IItemStack createItem(String id, int damage, int size);
public abstract ScriptParticle createParticle(String directory);
@@ -15,6 +15,7 @@ import noppes.npcs.containers.ContainerCustomGui;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.IContainer;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
public class ScriptContainer implements IContainer {
private IInventory inventory;
@@ -26,10 +26,15 @@ import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileBigSign;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.IBlock;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
public class ScriptWorld implements IWorld {
private static Map<String,Object> tempData = new HashMap<String,Object>();
@@ -322,11 +327,8 @@ public class ScriptWorld implements IWorld {
* @param size The number of items in the item
* @return Returns the item
*/
public ScriptItemStack createItem(String id, int damage, int size){
Item item = (Item)Item.itemRegistry.getObject(id);
if(item == null)
return null;
return new ScriptItemStack(new ItemStack(item, size, damage));
public IItemStack createItem(String id, int damage, int size){
return WrapperNpcAPI.Instance().createItem(id,damage,size);
}
/**
@@ -5,11 +5,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptItemStack;
import java.util.ArrayList;
import java.util.Locale;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
public T player;
@@ -430,7 +427,7 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T>{
return compound.getCompoundTag("JRMCEP").getString("extracode");
}
public ScriptItemStack[] getInventory(){
public IItemStack[] getInventory(){
NBTTagCompound compound = new NBTTagCompound();
this.player.writeToNBT(compound);
@@ -28,6 +28,7 @@ import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.INbt;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.item.ScriptItemStack;
public class ScriptEntity<T extends Entity> implements IEntity {
protected T entity;
@@ -7,12 +7,13 @@ import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.MathHelper;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IEntityLivingBase;
import noppes.npcs.scripted.wrapper.ScriptDamageSource;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
protected T entity;
@@ -173,11 +174,8 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
* @since 1.7.10c
* @return The item the entity is holding
*/
public ScriptItemStack getHeldItem(){
ItemStack item = entity.getHeldItem();
if(item == null)
return null;
return new ScriptItemStack(item);
public IItemStack getHeldItem(){
return WrapperNpcAPI.Instance().getIItemStack(entity.getHeldItem());
}
/**
@@ -194,11 +192,8 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
* @param slot Slot of what armor piece to get, 0:boots, 1:pants, 2:body, 3:head
* @return The item in the given slot
*/
public ScriptItemStack getArmor(int slot){
ItemStack item = entity.getEquipmentInSlot(slot + 1);
if(item == null)
return null;
return new ScriptItemStack(item);
public IItemStack getArmor(int slot){
return WrapperNpcAPI.Instance().getIItemStack(entity.getEquipmentInSlot(slot + 1));
}
/**
@@ -8,7 +8,8 @@ import noppes.npcs.controllers.Line;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.ScriptFaction;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.constants.AnimationType;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.ICustomNpc;
@@ -28,6 +29,7 @@ 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.wrapper.WrapperNpcAPI;
import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
@@ -358,11 +360,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
/**
* @return The item held in the right hand
*/
public ScriptItemStack getRightItem(){
ItemStack item = npc.inventory.getWeapon();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
public IItemStack getRightItem(){
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.getWeapon());
}
/**
@@ -379,11 +378,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
/**
* @return The item held in the left hand
*/
public ScriptItemStack getLefttItem(){
ItemStack item = npc.getOffHand();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
public IItemStack getLefttItem(){
return WrapperNpcAPI.Instance().getIItemStack(npc.getOffHand());
}
/**
@@ -400,11 +396,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
/**
* @return Returns the projectile the npc uses
*/
public ScriptItemStack getProjectileItem(){
ItemStack item = npc.inventory.getProjectile();
if(item == null || item.getItem() == null)
return null;
return new ScriptItemStack(item);
public IItemStack getProjectileItem(){
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.getProjectile());
}
/**
@@ -488,11 +481,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @return Returns the worn armor in slot
*/
@Override
public ScriptItemStack getArmor(int slot){
ItemStack item = npc.inventory.armor.get(slot);
if(item == null)
return null;
return new ScriptItemStack(item);
public IItemStack getArmor(int slot){
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.armor.get(slot));
}
/**
@@ -514,8 +504,8 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
* @param slot The slot from the NPC's drop list to return (0-8)
* @return
*/
public ScriptItemStack getLootItem(int slot) {
return new ScriptItemStack(npc.inventory.getStackInSlot(slot+7));
public IItemStack getLootItem(int slot) {
return WrapperNpcAPI.Instance().getIItemStack(npc.inventory.getStackInSlot(slot+7));
}
/**
@@ -1,7 +1,6 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -20,11 +19,12 @@ import noppes.npcs.controllers.*;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.scripted.*;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.event.FactionEvent;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.handler.data.IQuest;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
@@ -238,12 +238,12 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
* @since 1.7.10d
* @return Returns a IItemStack array size 36
*/
public ScriptItemStack[] getInventory(){
ScriptItemStack[] items = new ScriptItemStack[36];
public IItemStack[] getInventory(){
IItemStack[] items = new IItemStack[36];
for(int i = 0; i < player.inventory.mainInventory.length; i++){
ItemStack item = player.inventory.mainInventory[i];
if(item != null)
items[i] = new ScriptItemStack(item);
items[i] = WrapperNpcAPI.Instance().getIItemStack(item);
}
return items;
}
@@ -0,0 +1,89 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.interfaces.IEntity;
import noppes.npcs.scripted.interfaces.IPlayer;
import noppes.npcs.scripted.item.ScriptCustomItem;
public class ItemEvent extends CustomNPCsEvent {
public ScriptCustomItem item;
public ItemEvent(ScriptCustomItem item) {
this.item = item;
}
public static class InitEvent extends ItemEvent {
public InitEvent(ScriptCustomItem item) {
super(item);
}
}
public static class UpdateEvent extends ItemEvent {
public IPlayer player;
public UpdateEvent(ScriptCustomItem item, IPlayer player) {
super(item);
this.player = player;
}
}
@Cancelable
public static class TossedEvent extends ItemEvent {
public IEntity entity;
public IPlayer player;
public TossedEvent(ScriptCustomItem item, IPlayer player, IEntity entity) {
super(item);
this.entity = entity;
this.player = player;
}
}
public static class PickedUpEvent extends ItemEvent {
public IPlayer player;
public PickedUpEvent(ScriptCustomItem item, IPlayer player) {
super(item);
this.player = player;
}
}
@Cancelable
public static class SpawnEvent extends ItemEvent {
public IEntity entity;
public SpawnEvent(ScriptCustomItem item, IEntity entity){
super(item);
this.entity = entity;
}
}
@Cancelable
public static class InteractEvent extends ItemEvent {
public final int type;
public final Object target;
public IPlayer player;
public InteractEvent(ScriptCustomItem item, IPlayer player, int type, Object target) {
super(item);
this.type = type;
this.target = target;
this.player = player;
}
}
@Cancelable
public static class AttackEvent extends ItemEvent {
public final int type;//1: Hit, 2: Whiff //TODO: Implement type 2
public final Object target;
public IPlayer player;
public AttackEvent(ScriptCustomItem item, IPlayer player, int type, Object target) {
super(item);
this.type = type;
this.target = target;
this.player = player;
}
}
}
@@ -6,17 +6,16 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
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.interfaces.*;
import noppes.npcs.scripted.item.ScriptItemStack;
public class PlayerEvent extends CustomNPCsEvent {
public final IPlayer player;
@@ -5,10 +5,9 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.entity.ScriptPlayer;
public interface IContainer {
@@ -0,0 +1,25 @@
package noppes.npcs.scripted.interfaces;
public interface ICustomItem extends IItemStack {
String getTexture();
void setTexture(String var2);
void setMaxStackSize(int var1);
double getDurabilityValue();
void setDurabilityValue(float var1);
boolean getDurabilityShow();
void setDurabilityShow(boolean var1);
int getDurabilityColor();
void setDurabilityColor(int var1);
int getColor();
void setColor(int var1);
}
@@ -6,9 +6,8 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.EntityCreature;
import noppes.npcs.constants.EnumNavType;
import noppes.npcs.scripted.ScriptFaction;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.entity.ScriptLivingBase;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.roles.*;
@@ -196,7 +195,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return The item held in the right hand
*/
public ScriptItemStack getRightItem();
public IItemStack getRightItem();
/**
* @param item Item to be held in the right hand
@@ -206,7 +205,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return The item held in the left hand
*/
public ScriptItemStack getLefttItem();
public IItemStack getLefttItem();
/**
* @param item Item to be held in the left hand
@@ -216,7 +215,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
/**
* @return Returns the projectile the npc uses
*/
public ScriptItemStack getProjectileItem();
public IItemStack getProjectileItem();
/**
* @param item Item to be used as projectile
@@ -272,7 +271,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
* @param slot The armor slot to return. 0:head, 1:body, 2:legs, 3:boots
* @return Returns the worn armor in slot
*/
public ScriptItemStack getArmor(int slot);
public IItemStack getArmor(int slot);
/**
* @param slot The armor slot to set. 0:head, 1:body, 2:legs, 3:boots
@@ -285,7 +284,7 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
* @param slot The slot from the NPC's drop list to return (0-8)
* @return The item in the NPC's drop list slot
*/
public ScriptItemStack getLootItem(int slot);
public IItemStack getLootItem(int slot);
/**
*
@@ -7,7 +7,7 @@ package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.Entity;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
public interface IEntity<T extends Entity> {
public double getYOffset();
@@ -2,7 +2,7 @@ package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.entity.ScriptLivingBase;
public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T> {
@@ -82,7 +82,7 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
* @since 1.7.10c
* @return The item the entity is holding
*/
public ScriptItemStack getHeldItem();
public IItemStack getHeldItem();
/**
* Note not all Living Entities support this
@@ -96,7 +96,7 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
* @param slot Slot of what armor piece to get, 0:boots, 1:pants, 2:body, 3:head
* @return The item in the given slot
*/
public ScriptItemStack getArmor(int slot);
public IItemStack getArmor(int slot);
/**
* Note not all Living Entities support this
@@ -1,7 +1,7 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.ScriptPixelmonPlayerData;
public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T> {
@@ -90,7 +90,7 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
* @since 1.7.10d
* @return Returns a IItemStack array size 36
*/
public ScriptItemStack[] getInventory();
public IItemStack[] getInventory();
/**
* @param item The Item type to be removed
@@ -5,6 +5,7 @@ import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.*;
import noppes.npcs.scripted.entity.ScriptEntity;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.item.ScriptItemStack;
public interface IWorld {
/**
@@ -166,7 +167,7 @@ public interface IWorld {
* @param size The number of items in the item
* @return Returns the item
*/
public ScriptItemStack createItem(String id, int damage, int size);
public IItemStack createItem(String id, int damage, int size);
/**
* @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png"
@@ -0,0 +1,413 @@
package noppes.npcs.scripted.item;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.EventHooks;
import noppes.npcs.NBTTags;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.IScriptHandler;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.interfaces.ICustomItem;
import java.util.*;
public class ScriptCustomItem extends ScriptItemStack implements ICustomItem, IScriptHandler {
public List<ScriptContainer> scripts = new ArrayList();
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public long lastInited = -1L;
public boolean durabilityShow = false;
public double durabilityValue = 1.0D;
public int durabilityColor = -1;
public int itemColor = 0x8B4513;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public boolean loaded = false;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public int width = -1, height = -1;
public float translateX, translateY, translateZ;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public ScriptCustomItem(ItemStack item) {
super(item);
loadScriptData();
loadItemData();
}
public NBTTagCompound getScriptNBT(NBTTagCompound compound) {
compound.setTag("Scripts", NBTTags.NBTScript(this.scripts));
compound.setString("ScriptLanguage", this.scriptLanguage);
compound.setBoolean("ScriptEnabled", this.enabled);
return compound;
}
public void setScriptNBT(NBTTagCompound compound) {
if (compound.hasKey("Scripts")) {
this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this);
this.scriptLanguage = compound.getString("ScriptLanguage");
this.enabled = compound.getBoolean("ScriptEnabled");
}
}
public int getType() {
return 6;
}
public void callScript(EnumScriptType type, Event event) {
if (!this.loaded) {
this.loadScriptData();
this.loaded = true;
}
if (this.isEnabled()) {
if (ScriptController.Instance.lastLoaded > this.lastInited) {
this.lastInited = ScriptController.Instance.lastLoaded;
if (type != EnumScriptType.INIT) {
EventHooks.onScriptItemInit(this);
}
}
Iterator var3 = this.scripts.iterator();
while(var3.hasNext()) {
ScriptContainer script = (ScriptContainer)var3.next();
script.run(type, event);
}
}
}
private boolean isEnabled() {
return this.enabled && ScriptController.HasStart;
}
public boolean isClient() {
return false;
}
public boolean getEnabled() {
return this.enabled;
}
public void setEnabled(boolean bo) {
this.enabled = bo;
}
public String getLanguage() {
return this.scriptLanguage;
}
public void setLanguage(String lang) {
this.scriptLanguage = lang;
}
public List<ScriptContainer> getScripts() {
return this.scripts;
}
public String noticeString() {
return "ScriptedItem";
}
public Map<Long, String> getConsoleText() {
Map<Long, String> map = new TreeMap();
int tab = 0;
Iterator var3 = this.getScripts().iterator();
while(var3.hasNext()) {
ScriptContainer script = (ScriptContainer)var3.next();
++tab;
Iterator var5 = script.console.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<Long, String> entry = (Map.Entry)var5.next();
map.put(entry.getKey(), " tab " + tab + ":\n" + (String)entry.getValue());
}
}
return map;
}
public void clearConsole() {
Iterator var1 = this.getScripts().iterator();
while(var1.hasNext()) {
ScriptContainer script = (ScriptContainer)var1.next();
script.console.clear();
}
}
public String getTexture() {
return this.texture == null ? "" : this.texture;
}
public void setTexture(String texture){
if(texture == null)
texture = "";
this.texture = texture;
saveItemData();
}
public int getMaxStackSize() {
return this.stackSize;
}
public void setMaxStackSize(int size) {
if (size >= 1 && size <= 64) {
this.stackSize = size;
saveItemData();
} else {
throw new CustomNPCsException("Stacksize has to be between 1 and 64", new Object[0]);
}
}
public double getDurabilityValue() {
return this.durabilityValue;
}
public void setDurabilityValue(float value) {
this.durabilityValue = (double)value;
saveItemData();
}
public boolean getDurabilityShow() {
return this.durabilityShow;
}
public void setDurabilityShow(boolean bo) {
this.durabilityShow = bo;
saveItemData();
}
public int getDurabilityColor() {
return this.durabilityColor;
}
public void setDurabilityColor(int color) {
this.durabilityColor = color;
saveItemData();
}
public int getColor() {
return this.itemColor;
}
public void setColor(int color) {
this.itemColor = color;
saveItemData();
}
public int getMaxItemUseDuration(){
return this.maxItemUseDuration;
}
public void setMaxItemUseDuration(int duration){
this.maxItemUseDuration = duration;
saveItemData();
}
public void setRotation(float rotationX, float rotationY, float rotationZ){
this.rotationX = rotationX;
this.rotationY = rotationY;
this.rotationZ = rotationZ;
saveItemData();
}
public void setScale(float scaleX, float scaleY, float scaleZ){
this.scaleX = scaleX;
this.scaleY = scaleY;
this.scaleZ = scaleZ;
saveItemData();
}
public void setTranslate(float translateX, float translateY, float translateZ){
this.translateX = translateX;
this.translateY = translateY;
this.translateZ = translateZ;
saveItemData();
}
public void setRotationX(float rotationX) {
this.rotationX = rotationX;
saveItemData();
}
public void setRotationY(float rotationY) {
this.rotationY = rotationY;
saveItemData();
}
public void setRotationZ(float rotationZ) {
this.rotationZ = rotationZ;
saveItemData();
}
public void setScaleX(float scaleX) {
this.scaleX = scaleX;
saveItemData();
}
public void setScaleY(float scaleY) {
this.scaleY = scaleY;
saveItemData();
}
public void setScaleZ(float scaleZ) {
this.scaleZ = scaleZ;
saveItemData();
}
public void setTranslateX(float translateX) {
this.translateX = translateX;
saveItemData();
}
public void setTranslateY(float translateY) {
this.translateY = translateY;
saveItemData();
}
public void setTranslateZ(float translateZ) {
this.translateZ = translateZ;
saveItemData();
}
public float getRotationX() {
return rotationX;
}
public float getRotationY() {
return rotationY;
}
public float getRotationZ() {
return rotationZ;
}
public float getScaleX() {
return scaleX;
}
public float getScaleY() {
return scaleY;
}
public float getScaleZ() {
return scaleZ;
}
public float getTranslateX() {
return translateX;
}
public float getTranslateY() {
return translateY;
}
public float getTranslateZ() {
return translateZ;
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = super.getMCNbt();
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
compound.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
return compound;
}
public void setMCNbt(NBTTagCompound compound) {
setScriptNBT(compound.getCompoundTag("ScriptedData"));
setItemNBT(compound.getCompoundTag("ItemData"));
}
public NBTTagCompound getItemNBT(NBTTagCompound compound) {
compound.setBoolean("DurabilityShow",this.durabilityShow);
compound.setDouble("DurabilityValue",this.durabilityValue);
compound.setInteger("DurabilityColor",this.durabilityColor );
compound.setInteger("ItemColor",this.itemColor);
compound.setInteger("MaxStackSize",this.stackSize);
compound.setString("ItemTexture",this.texture);
compound.setFloat("RotationX",this.rotationX);
compound.setFloat("RotationY",this.rotationY);
compound.setFloat("RotationZ",this.rotationZ);
compound.setFloat("ScaleX",this.scaleX);
compound.setFloat("ScaleY",this.scaleY);
compound.setFloat("ScaleZ",this.scaleZ);
compound.setFloat("TranslateX",this.translateX);
compound.setFloat("TranslateY",this.translateY);
compound.setFloat("TranslateZ",this.translateZ);
compound.setInteger("Width", this.width);
compound.setInteger("Height", this.height);
return compound;
}
public void setItemNBT(NBTTagCompound compound) {
this.durabilityShow = compound.getBoolean("DurabilityShow");
this.durabilityValue = compound.getDouble("DurabilityValue");
if (compound.hasKey("DurabilityColor")) {
this.durabilityColor = compound.getInteger("DurabilityColor");
}
this.itemColor = compound.getInteger("ItemColor");
this.stackSize = compound.getInteger("MaxStackSize");
this.texture = compound.getString("ItemTexture");
this.rotationX = compound.getFloat("RotationX");
this.rotationY = compound.getFloat("RotationY");
this.rotationZ = compound.getFloat("RotationZ");
this.scaleX = compound.getFloat("ScaleX");
this.scaleY = compound.getFloat("ScaleY");
this.scaleZ = compound.getFloat("ScaleZ");
this.translateX = compound.getFloat("TranslateX");
this.translateY = compound.getFloat("TranslateY");
this.translateZ = compound.getFloat("TranslateZ");
this.width = compound.getInteger("Width");
this.height = compound.getInteger("Height");
}
public void saveScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c == null) {
this.item.setTagCompound(c = new NBTTagCompound());
}
c.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
}
public void loadScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null) {
this.setScriptNBT(c.getCompoundTag("ScriptedData"));
}
}
public void saveItemData() {
NBTTagCompound c = this.item.getTagCompound();
if (c == null) {
this.item.setTagCompound(c = new NBTTagCompound());
}
c.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
}
public void loadItemData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null){
this.setItemNBT(c.getCompoundTag("ItemData"));
}
}
}
@@ -1,4 +1,4 @@
package noppes.npcs.scripted;
package noppes.npcs.scripted.item;
import java.util.ArrayList;
import java.util.Iterator;
@@ -18,12 +18,16 @@ import net.minecraft.nbt.NBTBase.NBTPrimitive;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptNbt;
import noppes.npcs.scripted.interfaces.IItemStack;
import noppes.npcs.scripted.interfaces.INbt;
public class ScriptItemStack implements IItemStack {
public ItemStack item;
private NBTTagCompound storedData = new NBTTagCompound();
public ScriptItemStack(ItemStack item){
this.item = item;
}
@@ -69,7 +73,12 @@ public class ScriptItemStack implements IItemStack {
public String getItemName(){
return item.getItem().getItemStackDisplayName(item);
}
public int getMaxStackSize() {
return this.item.getMaxStackSize();
}
/**
* @param size The size of the itemstack. A number between 1 and 64
*/
@@ -136,7 +145,7 @@ public class ScriptItemStack implements IItemStack {
}
public INbt removeTags() {
ScriptNbt nbt = (ScriptNbt)NpcAPI.Instance().getINbt(item.stackTagCompound);
ScriptNbt nbt = (ScriptNbt) NpcAPI.Instance().getINbt(item.stackTagCompound);
item.stackTagCompound = null;
return nbt;
}
@@ -362,6 +371,14 @@ public class ScriptItemStack implements IItemStack {
return NpcAPI.Instance().getINbt(compound);
}
public NBTTagCompound getMCNbt() {
NBTTagCompound compound = new NBTTagCompound();
this.item.writeToNBT(compound);
return compound;
}
public void setMCNbt(NBTTagCompound compound) {}
/**
* No support is given for this method. Dont use if you dont know what you are doing.
* @return Minecraft ItemStack
@@ -2,7 +2,7 @@ package noppes.npcs.scripted.roles;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleTrader;
import noppes.npcs.scripted.ScriptItemStack;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.constants.RoleType;
import foxz.utils.Market;
@@ -32,6 +32,7 @@ import net.minecraft.world.WorldServer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.*;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.*;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.entity.EntityCustomNpc;
@@ -41,6 +42,8 @@ import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.handler.*;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.item.ScriptCustomItem;
import noppes.npcs.scripted.item.ScriptItemStack;
import noppes.npcs.scripted.overlay.ScriptOverlay;
import noppes.npcs.util.JsonException;
import noppes.npcs.util.LRUHashMap;
@@ -167,8 +170,11 @@ public class WrapperNpcAPI extends NpcAPI {
}
public IItemStack getIItemStack(ItemStack itemstack) {
return (IItemStack)(itemstack != null && itemstack.stackSize > 0 ? new ScriptItemStack(itemstack) : new ScriptItemStack(new ItemStack(Item.getItemById(0))));
if(itemstack.getItem() instanceof ItemScripted){
return (ICustomItem) (itemstack != null && itemstack.stackSize > 0 ? new ScriptCustomItem(itemstack) : new ScriptCustomItem(new ItemStack(Item.getItemById(0))));
} else {
return (IItemStack) (itemstack != null && itemstack.stackSize > 0 ? new ScriptItemStack(itemstack) : new ScriptItemStack(new ItemStack(Item.getItemById(0))));
}
}
public IWorld getIWorld(WorldServer world) {
@@ -258,11 +264,14 @@ public class WrapperNpcAPI extends NpcAPI {
return arr;
}
public ScriptItemStack createItem(String id, int damage, int size){
public IItemStack createItem(String id, int damage, int size){
Item item = (Item)Item.itemRegistry.getObject(id);
if(item == null)
return null;
return new ScriptItemStack(new ItemStack(item, size, damage));
if(item instanceof ItemScripted)
return new ScriptCustomItem(new ItemStack(item, size, damage));
else
return new ScriptItemStack(new ItemStack(item, size, damage));
}
public void playSoundAtEntity(ScriptEntity entity, String sound, float volume, float pitch){