Jump to content

Recommended Posts

Posted

Hi everyone

 

So i have started to try adding some interfaces/inventories to my items and I have hit an issue trying to apply it to my item.

The item is an egg launcher that I want the player to be able toshoot eggs for guaranteed hatching if the invenory has an egg in it.

 

However there is a problem, as when I open the inventory and place an item in a slot it duplicates it by adding it to the slot and keeping the item in my selected item  and when left clicking to take the item from the slot the items simply disappear. Any advice?

(if it helps I am following VSWEs tutorial series for 1.6 and trying to bring it over for 1.7)

 

 

Item class

package items;

import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import entities.FunEgg;
import entities.PotatoGrenade;
import keystuff.myMod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSnowball;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class BlasterThingy extends ItemSnowball implements IInventory
{
   public BlasterThingy()
   {
      super();
      setCreativeTab(myMod.daftcraft);
      setUnlocalizedName("blaster thingy");
      setMaxDamage(300);


   }

   @Override
   public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
   {

      String checkName="ForgeDevName";
      String name=player.getDisplayName();

      if(player.isSneaking())
      {
         FMLNetworkHandler.openGui(player, myMod.modInstance, 0, world, (int) player.posX, (int) player.posY, (int) player.posZ);
      }


      if (!player.capabilities.isCreativeMode)
      {
         if(getStackInSlot(0)!= null)
         {
            if(doesInventoryContain(Items.egg) && !player.isSneaking())
            {
            world.spawnEntityInWorld(new FunEgg(world, player));
            this.decrStackSize(0,1);
            //player.inventory.consumeInventoryItem(Items.egg);

            itemStack.setItemDamage(itemStack.getItemDamage()+1);
            return itemStack;
            }
         }

         System.out.println(this.getStackInSlot(0));


      }
      else
      {
         if(!player.isSneaking())
         {
            world.spawnEntityInWorld(new FunEgg(world, player));
         }

      }






      world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));



      return itemStack;
   }


                                 //begining of Inventory Code
   ItemStack[] items=new ItemStack[3];

   @Override
   public int getSizeInventory() {
      return items.length;
   }

   @Override
   public ItemStack getStackInSlot(int slot)
   {
      return items[slot];
   }

   public boolean doesInventoryContain(Item item)
   {
      for(int count=0;count < items.length;count++)
      {
         if(items[count].getItem()==item)
         {
            return true;
         }
      }

      return false;
   }

   @Override
   public ItemStack decrStackSize(int slot, int count)
   {
      ItemStack itemstack=getStackInSlot(slot);

      if(itemstack !=null)
      {
         if(itemstack.stackSize <= count)
         {
            setInventorySlotContents(slot,null);
         }
         else
         {
            itemstack =itemstack.splitStack(count);

         }
      }

      return itemstack;
   }

   @Override
   public ItemStack getStackInSlotOnClosing(int slot)
   {
      ItemStack itemstack=getStackInSlot(slot);
      setInventorySlotContents(slot,null);
      return itemstack;
   }

   @Override
   public void setInventorySlotContents(int slot, ItemStack itemStack)
   {
      items[slot]=itemStack;

      if(itemStack !=null && itemStack.stackSize > getInventoryStackLimit())
      {
         itemStack.stackSize=getInventoryStackLimit();
      }
   }

   @Override
   public String getInventoryName() {
      return null;
   }

   @Override
   public boolean hasCustomInventoryName() {
      return false;  //To change body of implemented methods use File | Settings | File Templates.
   }

   @Override
   public int getInventoryStackLimit() {
      return 64;  //To change body of implemented methods use File | Settings | File Templates.
   }

   @Override
   public void markDirty()
   {

   }

   @Override
   public boolean isUseableByPlayer(EntityPlayer player) {
      return true;
   }

   @Override
   public void openInventory() {}

   @Override
   public void closeInventory() {}

   @Override
   public boolean isItemValidForSlot(int slot, ItemStack itemStack)
   {
      return itemStack.getItem()== Items.egg;

   }

   }

 

GUI class

@SideOnly(Side.CLIENT)
public class GUIBow extends GuiContainer
{

   public GUIBow(InventoryPlayer inventoryPlayer, ItemStack bow)
   {
      super(new BowContainer(inventoryPlayer,bow));
      xSize=176;
      ySize=154;
   }

   private static final ResourceLocation texture=new ResourceLocation(myMod.MODID, "textures/gui/machine.png");

   @Override
   protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int x, int y)
   {
      GL11.glColor4f(1,1,1,1);
      Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
      drawTexturedModalRect(guiLeft,guiTop,0,0,xSize,ySize);

   }

   @Override
   protected void drawGuiContainerForegroundLayer(int x, int y)
   {
      fontRendererObj.drawString("blaster container",8,6,0x40404040);
   }

   @Override
   public void initGui()
   {
      super.initGui();
      buttonList.clear();

      buttonList.add(new GuiButton(0,guiLeft+100,guiTop+14,60,20,"disable"));
   }

  
}//class

 

GUI handler class

package GUIStuff;

import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import items.BlasterThingy;
import items.TestBow;
import items.daftcraftItems;
import keystuff.myMod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;


public class GUIHandler implements IGuiHandler
{

   public GUIHandler()
   {
      NetworkRegistry.INSTANCE.registerGuiHandler(myMod.modInstance,this);
   }

   @Override
   public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
   {
      switch(ID)
      {

         case 0:
            ItemStack bow=player.getHeldItem();
            if(bow !=null && bow.getItem()instanceof BlasterThingy)
            {
               return new BowContainer(player.inventory,bow);
            }
            break;
      }
      return null;
   }

   @Override
   public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
   {
      switch(ID)
      {

         case 0:
            ItemStack bow=player.getHeldItem();
            if(bow !=null && bow.getItem()instanceof BlasterThingy)
            {
               return new GUIBow(player.inventory,bow);
            }
            break;
      }
      return null;
   }
}//class

 

GUI container class

public class BowContainer extends Container
{
   private ItemStack bow;
   private BlasterThingy blaster;


   public BowContainer(InventoryPlayer inventoryPlayer, ItemStack bow)
   {
      this.bow=bow;

      if(inventoryPlayer.player.getHeldItem().getItem()==daftcraftItems.blasterThingy)
      {
         blaster=(BlasterThingy)inventoryPlayer.player.getHeldItem().getItem();
      }

      for(int x=0;x<9;x++)
      {
         addSlotToContainer(new Slot(inventoryPlayer,x,8+18*x,130));
      }

      for(int y=0;y<3;y++)
      {
         for(int x=0;x<9;x++)
         {
            addSlotToContainer(new Slot(inventoryPlayer,x+y*9+9,8+18*x,72+y*18));
         }
      }

      for(int x=0;x<3;x++)
      {
         addSlotToContainer(new ProjectileSlot(blaster,x,8+18*x,17));
      }
   }

   @Override
   public boolean canInteractWith(EntityPlayer player)
   {
      return true;
   }

   @Override
   public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
   {
      return null;
   }
}//class

 

Any help is appreciated

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • wait, i just did that. why didn't it work? also it's the same. help me!!!!
    • Culprit has been located! It was Tough As Nails + (plus) which was among one of the mods *added* before re-entering, in an attempt to improve compatibility. It, for some reason or another, did not want to work!
    • "You can either try to load it with only the vanilla data pack ("safe mode"), or go back to the title screen and fix it manually." Hello! I encountered this error just now while attempting to re-enter my world for the first time. Notably, no mods were removed before encountering this error and, while being able to find this error elsewhere on the internet, in my scenario it is seemingly caused by a specific mod, of which I cannot isolate. Things I have tried: - Enter "Safe Mode" (fails) - Remove datapacks (no change) - Reverted to old save data (no change) Here is the server log: https://mclo.gs/9vJQEfN I use Modrinth mod loader so please let me know how to share my mod list, and if it is needed.
    • So, i'm hosting (or attempting to host) a port-forwarded modded server for 1.12.2. There's quite a few mods in this pack, but they all run and have no compatibility issues (besides something causing the game to crash if you go fullscreen, a problem ive given up trying to identify or fix). It can run on 6gb of ram or less, and works fine in singleplayer. All of my friends that want to join have the exact same mod/config/game setup as I do (I personally helped them set everything up). Just to be safe, we've all allocated 12 gigabytes of RAM to the installation, and I've also allocated 12GB to the server itself. I am able to join with no issue and it runs fine. However, when they try to join, it gets stuck in the 'logging in' screen before their game becomes unresponsive. When they close it, it gives them the exit code 805306369, which usually means not enough RAM, but this cant be the case. On my screen, in the server, it shows them joining, and then disconnecting, so I dont think its a port-forwarding issue. They can all run it just fine in singleplayer as well. The annoying bit about this particular issue is that it generates no crash log. Does anyone have any suggestions? Thanks! Here is my debug log, and his, starting from the same place. MINE: [132647] [Netty Client IO #5INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132653.817 [132653] [Client threadINFO] [minecraftGuiConnecting] Connecting to 0, 25565 132654.682 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.common.core.transformer.ClassNodeTransformertransform29] Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 132654.684 [132654] [Netty Client IO #9INFO] [STDOUT] [xaero.map.core.transformer.ClassNodeTransformertransform29] Transforming class net.minecraft.client.network.NetHandlerPlayClient 132654.764 [132654] [Netty Client IO #9INFO] [FML] Server protocol version 2 132654.777 [132654] [Netty Client IO #9INFO] [FML] Attempting connection with missing mods [ctm, fusion] at SERVER 132656.193 [132656] [Client threadINFO] [FML] Injecting existing registry data into this client instance 132659.081 [132659] [Client threadINFO] [FML] Applying holder lookups 132659.082 [132659] [Client threadINFO] [FML] Holder lookups applied 132659.092 [132659] [Netty Client IO #9INFO] [FML] [Netty Client IO #9] Client side modded connection established HIS: [13:12:16] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:25.597 [13:12:25] [Client thread/INFO] [minecraft/GuiConnecting]: Connecting to (my IP address and the server port 25565) 13:12:26.805 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.common.core.transformer.ClassNodeTransformer:transform:29]: Transforming class brz net.minecraft.client.network.NetHandlerPlayClient 13:12:26.808 [13:12:26] [Netty Client IO #1/INFO] [STDOUT]: [xaero.map.core.transformer.ClassNodeTransformer:transform:29]: Transforming class net.minecraft.client.network.NetHandlerPlayClient 13:12:26.936 [13:12:26] [Netty Client IO #1/INFO] [FML]: Server protocol version 2 13:12:27.114 [13:12:27] [Netty Client IO #1/INFO] [FML]: Attempting connection with missing mods [ctm, fusion] at SERVER 13:12:27.480 [13:12:27] [Client thread/INFO] [FML]: Injecting existing registry data into this client instance 13:12:30.669 [13:12:30] [Client thread/INFO] [FML]: Applying holder lookups 13:12:30.671 [13:12:30] [Client thread/INFO] [FML]: Holder lookups applied 13:13:04.700 Process crashed with exit code -805306369 P.S - Both mods "CTM" and "FUSION" are present in both our folders so idk what that's about.
    • Please read the FAQ (link is orange banner at top of page), and post logs as described there, to an external site such as https://mclo.gs  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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