Jump to content

NotoriusAnimeDude

Members
  • Posts

    15
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

NotoriusAnimeDude's Achievements

Tree Puncher

Tree Puncher (2/8)

3

Reputation

  1. Thanks for your help. Now, the NBT won't get initialized unless the user actually uses the item which is more efficient.
  2. I think ItemStack joining the world would do the trick. I need to initialize custom NBT data for the item when it is first created and I was able to do that with onCreated but that only includes crafting and smelting. If the item is spawned from creative mode and used, it crashes the game.
  3. Is there anyway I can detect if an item is spawned from either a creative tab or /give command? I know that there's an onUpdate function for each item but I only need to call my code once when the item enters the player inventory.
  4. After some debugging I figured it out. I somehow missed that some of the AI tasks are added in the targetTasks instead of tasks. Adding another loop for targetTasks fixed the issue. I apologize for the inconvenience
  5. I kind of assumed this so I edited the code like this but it's still not working. public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getTagCompound().getInteger("MobCounter") > 0 && !worldIn.isRemote) { int mobCounter = itemStackIn.getTagCompound().getInteger("MobCounter"); final int spawnRange = 4; --mobCounter; EntityMob entity = (EntityMob) EntityList.createEntityByName(itemStackIn.getTagCompound().getString("Mob"+Integer.toString(mobCounter)), worldIn); entity.setPosition((double)playerIn.getPosition().getX() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D, (double)(playerIn.getPosition().getY() + worldIn.rand.nextInt(2)), (double)playerIn.getPosition().getZ() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D); if(entity instanceof EntityZombie) { for(Object task : entity.tasks.taskEntries.toArray()) { EntityAIBase ai = ((EntityAITaskEntry) task).action; if(ai instanceof EntityAIMoveThroughVillage || ai instanceof EntityAIHurtByTarget || ai instanceof EntityAINearestAttackableTarget) entity.tasks.removeTask(ai); } entity.tasks.addTask(5, new EntityMobAiFollow(entity, playerIn, 1.0D,10.0F,2.0F)); } worldIn.spawnEntityInWorld(entity); itemStackIn.getTagCompound().setInteger("MobCounter", mobCounter); }
  6. I kind of assumed this so I edited the code like this but it's still not working. public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getTagCompound().getInteger("MobCounter") > 0 && !worldIn.isRemote) { int mobCounter = itemStackIn.getTagCompound().getInteger("MobCounter"); final int spawnRange = 4; --mobCounter; EntityMob entity = (EntityMob) EntityList.createEntityByName(itemStackIn.getTagCompound().getString("Mob"+Integer.toString(mobCounter)), worldIn); entity.setPosition((double)playerIn.getPosition().getX() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D, (double)(playerIn.getPosition().getY() + worldIn.rand.nextInt(2)), (double)playerIn.getPosition().getZ() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D); if(entity instanceof EntityZombie) { for(Object task : entity.tasks.taskEntries.toArray()) { EntityAIBase ai = ((EntityAITaskEntry) task).action; if(ai instanceof EntityAIMoveThroughVillage || ai instanceof EntityAIHurtByTarget || ai instanceof EntityAINearestAttackableTarget) entity.tasks.removeTask(ai); } entity.tasks.addTask(5, new EntityMobAiFollow(entity, playerIn, 1.0D,10.0F,2.0F)); } worldIn.spawnEntityInWorld(entity); itemStackIn.getTagCompound().setInteger("MobCounter", mobCounter); }
  7. I have an item that when right clicked spawns a mob with my custom AI in a radius around the player. It's working perfectly except that it spawns the mob with its default AI. I've been testing on Zombies only, I debugged the code and it does step into the condition and execute all the removeTask code. I'm not really sure what do from here so any help would be appreciated. @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getTagCompound().getInteger("MobCounter") > 0 && !worldIn.isRemote) { int mobCounter = itemStackIn.getTagCompound().getInteger("MobCounter"); final int spawnRange = 4; --mobCounter; EntityMob entity = (EntityMob) EntityList.createEntityByName(itemStackIn.getTagCompound().getString("Mob"+Integer.toString(mobCounter)), worldIn); entity.setPosition((double)playerIn.getPosition().getX() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D, (double)(playerIn.getPosition().getY() + worldIn.rand.nextInt(2)), (double)playerIn.getPosition().getZ() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D); if(entity instanceof EntityZombie) { entity.tasks.removeTask(new EntityAIMoveThroughVillage(entity, 1.0D, false)); entity.tasks.removeTask(new EntityAIHurtByTarget(entity, true, new Class[] {EntityPigZombie.class})); entity.tasks.removeTask(new EntityAINearestAttackableTarget(entity, EntityPlayer.class, true)); entity.tasks.removeTask(new EntityAINearestAttackableTarget(entity, EntityVillager.class, false)); entity.tasks.removeTask(new EntityAINearestAttackableTarget(entity, EntityIronGolem.class, true)); entity.tasks.addTask(5, new EntityMobAiFollow(entity, playerIn, 1.0D,10.0F,2.0F)); //Custom AI Class } worldIn.spawnEntityInWorld(entity); itemStackIn.getTagCompound().setInteger("MobCounter", mobCounter); } return new ActionResult(EnumActionResult.PASS, itemStackIn); }
  8. I have an item that when right clicked spawns a mob with my custom AI in a radius around the player. It's working perfectly except that it spawns the mob with its default AI. I've been testing on Zombies only, I debugged the code and it does step into the condition and execute all the removeTask code. I'm not really sure what do from here so any help would be appreciated. @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getTagCompound().getInteger("MobCounter") > 0 && !worldIn.isRemote) { int mobCounter = itemStackIn.getTagCompound().getInteger("MobCounter"); final int spawnRange = 4; --mobCounter; EntityMob entity = (EntityMob) EntityList.createEntityByName(itemStackIn.getTagCompound().getString("Mob"+Integer.toString(mobCounter)), worldIn); entity.setPosition((double)playerIn.getPosition().getX() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D, (double)(playerIn.getPosition().getY() + worldIn.rand.nextInt(2)), (double)playerIn.getPosition().getZ() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D); if(entity instanceof EntityZombie) { entity.tasks.removeTask(new EntityAIMoveThroughVillage(entity, 1.0D, false)); entity.tasks.removeTask(new EntityAIHurtByTarget(entity, true, new Class[] {EntityPigZombie.class})); entity.tasks.removeTask(new EntityAINearestAttackableTarget(entity, EntityPlayer.class, true)); entity.tasks.removeTask(new EntityAINearestAttackableTarget(entity, EntityVillager.class, false)); entity.tasks.removeTask(new EntityAINearestAttackableTarget(entity, EntityIronGolem.class, true)); entity.tasks.addTask(5, new EntityMobAiFollow(entity, playerIn, 1.0D,10.0F,2.0F)); //Custom AI Class } worldIn.spawnEntityInWorld(entity); itemStackIn.getTagCompound().setInteger("MobCounter", mobCounter); } return new ActionResult(EnumActionResult.PASS, itemStackIn); }
  9. Look for the file and check if it is in the proper location and named correctly.
  10. Look for the file and check if it is in the proper location and named correctly.
  11. As Ernio noted, do not use null in NBT values as it will crash your game. I personally tested this when I was creating my own item.
  12. As Ernio noted, do not use null in NBT values as it will crash your game. I personally tested this when I was creating my own item.
  13. I am just going to give you a warning that I'm a complete beginner when it comes to modding but I've dug into minecraft code a lot and I did find kind of a hacky solution that I was hoping you could test. Here's the code and I'll explain below: import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import net.minecraft.entity.passive.EntityVillager; import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; import net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class TestClass { public static boolean guiOpened; public static int selectedMerchantRecipe; private int totalRecipes; @SubscribeEvent public void getEvent(EntityInteract e) { if(e != null && e.getTarget() instanceof EntityVillager) { EntityVillager interactedWith = (EntityVillager)e.getTarget(); totalRecipes = interactedWith.getRecipes(e.getEntityPlayer()).size(); guiOpened = true; //We know that the gui is open because the player interacted with a villager System.out.println("Merchant GUI Opened!" ); } } @SubscribeEvent public void buttonClicked(ActionPerformedEvent.Pre e) { final int nextButtonID = 1; //Button IDs from GuiMerchant class final int prevButtonID = 2; if(guiOpened) { if(e.getButton() != null && e.getButton().id == nextButtonID) { ++selectedMerchantRecipe; if(selectedMerchantRecipe >= totalRecipes) selectedMerchantRecipe = totalRecipes - 1; System.out.println(selectedMerchantRecipe); } else if(e.getButton() != null && e.getButton().id == prevButtonID) { --selectedMerchantRecipe; if(selectedMerchantRecipe < 0) selectedMerchantRecipe = 0; System.out.println(selectedMerchantRecipe); } } } @SubscribeEvent public void keyboardButtonPushed(KeyboardInputEvent.Pre e) { if(Keyboard.getEventKey() == 1 && guiOpened) //if escape is pushed guiOpened = false; } } Basically what I did was that I hooked up into three events EntityInteract, ActionPeformedEvent.Pre and KeyboardInputEvent.Pre. When the EntityInteract event fires with a villager, we know for sure that the gui is now open for the player. ActionPerformedEvent and KeyboardInputEvent are generic GUI events that fire whenever a mouse or a keyboard is used in a GUI. Combine that with the guiOpened boolean variable and restricting the mouse event to buttons only, you get yourself a simulated GuiMerchant class with a selectedMerchentRecipe variable. If you're going to use this class, don't forget to do MinecraftForge.EVENT_BUS.register(new TestClass()); in your init method.
  14. I am just going to give you a warning that I'm a complete beginner when it comes to modding but I've dug into minecraft code a lot and I did find kind of a hacky solution that I was hoping you could test. Here's the code and I'll explain below: import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import net.minecraft.entity.passive.EntityVillager; import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; import net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class TestClass { public static boolean guiOpened; public static int selectedMerchantRecipe; private int totalRecipes; @SubscribeEvent public void getEvent(EntityInteract e) { if(e != null && e.getTarget() instanceof EntityVillager) { EntityVillager interactedWith = (EntityVillager)e.getTarget(); totalRecipes = interactedWith.getRecipes(e.getEntityPlayer()).size(); guiOpened = true; //We know that the gui is open because the player interacted with a villager System.out.println("Merchant GUI Opened!" ); } } @SubscribeEvent public void buttonClicked(ActionPerformedEvent.Pre e) { final int nextButtonID = 1; //Button IDs from GuiMerchant class final int prevButtonID = 2; if(guiOpened) { if(e.getButton() != null && e.getButton().id == nextButtonID) { ++selectedMerchantRecipe; if(selectedMerchantRecipe >= totalRecipes) selectedMerchantRecipe = totalRecipes - 1; System.out.println(selectedMerchantRecipe); } else if(e.getButton() != null && e.getButton().id == prevButtonID) { --selectedMerchantRecipe; if(selectedMerchantRecipe < 0) selectedMerchantRecipe = 0; System.out.println(selectedMerchantRecipe); } } } @SubscribeEvent public void keyboardButtonPushed(KeyboardInputEvent.Pre e) { if(Keyboard.getEventKey() == 1 && guiOpened) //if escape is pushed guiOpened = false; } } Basically what I did was that I hooked up into three events EntityInteract, ActionPeformedEvent.Pre and KeyboardInputEvent.Pre. When the EntityInteract event fires with a villager, we know for sure that the gui is now open for the player. ActionPerformedEvent and KeyboardInputEvent are generic GUI events that fire whenever a mouse or a keyboard is used in a GUI. Combine that with the guiOpened boolean variable and restricting the mouse event to buttons only, you get yourself a simulated GuiMerchant class with a selectedMerchentRecipe variable. If you're going to use this class, don't forget to do MinecraftForge.EVENT_BUS.register(new TestClass()); in your init method.
  15. Hello everyone, I've just started modding minecraft today so I apologize if this question sounds a bit silly. I've finished the basic tutorials and started coding my own item. The idea is that when you kill mobs their souls get stored in the item and when you right click, you can respawn them back into the world. I managed to successfully get it to work except for two things. One, the function is getting called twice or at least I think it is. Two, one of the mobs spawned just freezes there not doing anything. Wand Code: public class ReAniWand extends Item{ public ReAniWand() { setRegistryName("reAnimationWand"); setUnlocalizedName("reAnimationWand"); GameRegistry.register(this); } @SideOnly(Side.CLIENT) public void initModel() { ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory")); } @Override public void onCreated(ItemStack itemStack, World world,EntityPlayer player) { itemStack.setTagCompound(new NBTTagCompound()); itemStack.getTagCompound().setInteger("MobCounter", 0); itemStack.getTagCompound().setString("Mob0", "h"); itemStack.getTagCompound().setString("Mob1", "h"); itemStack.getTagCompound().setString("Mob2", "h"); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(itemStackIn.getTagCompound().getInteger("MobCounter") > 0) { int mobCounter = itemStackIn.getTagCompound().getInteger("MobCounter"); final int spawnRange = 4; --mobCounter; EntityLiving entity = null; entity = (EntityLiving)EntityList.createEntityByName(itemStackIn.getTagCompound().getString ("Mob"+Integer.toString(mobCounter)), worldIn); entity.setLocationAndAngles((double)playerIn.getPosition().getX() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D, (double)(playerIn.getPosition().getY() + worldIn.rand.nextInt(3)), (double)playerIn.getPosition().getZ() + (worldIn.rand.nextDouble() - worldIn.rand.nextDouble()) * (double)spawnRange + 0.5D, MathHelper.wrapAngleTo180_float(worldIn.rand.nextFloat() * 360.0F), 0.0F); entity.rotationYawHead = entity.rotationYaw; entity.renderYawOffset = entity.rotationYaw; worldIn.spawnEntityInWorld(entity); entity.playLivingSound(); itemStackIn.getTagCompound().setInteger("MobCounter", mobCounter); } return new ActionResult(EnumActionResult.PASS, itemStackIn); } } Tracking Event Code: public class EventTrackMob { @SubscribeEvent public void myEvent(LivingDeathEvent e) { if(e.getEntity().isCreatureType(EnumCreatureType.MONSTER, false) && e.getSource().getEntity() != null && e.getSource().getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)e.getSource().getEntity(); for(int i=0;i<9;i++) if(player.inventory.mainInventory[i] != null && player.inventory.mainInventory[i].getItem() instanceof ReAniWand) { if(player.inventory.mainInventory[i].getTagCompound().getInteger("MobCounter") < 3) { int mobCounter = player.inventory.mainInventory[i].getTagCompound().getInteger("MobCounter"); String whichMob = "Mob"+Integer.toString(mobCounter++); player.inventory.mainInventory[i].getTagCompound().setString (whichMob, e.getEntity().getClass().getSimpleName().substring(6)); player.inventory.mainInventory[i].getTagCompound().setInteger("MobCounter",mobCounter); break; } } } } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.