Jump to content

clowcadia

Members
  • Posts

    458
  • Joined

  • Last visited

Everything posted by clowcadia

  1. Where is the best place to get the entityId , in process interact, or in the gui handler?
  2. Hows this GuiHandler @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){ return new ContainerBasic(player.inventory, ID, world); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){ return new GuiBasic(player.inventory, ID, world); } return null; } Container Basic public ContainerBasic(IInventory playerInv, int ID, World world) { //World world; Entity basic = world.getEntityByID(ID); IItemHandler handler = basic.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); //Gets the inventory from our tile entity Gui Basic public class GuiBasic extends GuiContainer{ private IInventory playerInv; public GuiBasic(IInventory playerInv, int ID, World world) { super(new ContainerBasic(playerInv, ID, world)); still doesnt work with errors
  3. Is this not passing it player.openGui(TestModHandler.instance, GuiHandler.BASIC, this.world, (int) player.posX, (int)player.posY, (int)player.posZ); and getting the it public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){
  4. Still the issue is using a tile entity, where i have none, what do i replace with if (tileEntity instanceof Basic) {
  5. Has anyone figured out a way to add a container to entityLiving, for the purposes to use it for gui container and and such.
  6. IS there an example how i can use it? I dont understand the ray trace concept
  7. How do i use raytracing exactly ?
  8. package com.clowcadia.test.containers; import com.clowcadia.test.npc.Basic; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; public class ContainerBasic extends Container{ private Basic te; public ContainerBasic(IInventory playerInv, Basic te) { this.te=te; IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); //Gets the inventory from our tile entity //Our tile entity slots this.addSlotToContainer(new SlotItemHandler(handler, 0, 62, 17)); this.addSlotToContainer(new SlotItemHandler(handler, 1, 80, 17)); this.addSlotToContainer(new SlotItemHandler(handler, 2, 98, 17)); this.addSlotToContainer(new SlotItemHandler(handler, 3, 62, 35)); this.addSlotToContainer(new SlotItemHandler(handler, 4, 80, 35)); this.addSlotToContainer(new SlotItemHandler(handler, 5, 98, 35)); this.addSlotToContainer(new SlotItemHandler(handler, 6, 62, 53)); this.addSlotToContainer(new SlotItemHandler(handler, 7, 80, 53)); this.addSlotToContainer(new SlotItemHandler(handler, 8, 98, 53)); //The player's inventory slots int xPos = 8; //The x position of the top left player inventory slot on our texture int yPos = 84; //The y position of the top left player inventory slot on our texture //Player slots for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18)); } } for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58)); } } @Override public boolean canInteractWith(EntityPlayer player) { return !player.isSpectator(); } } package com.clowcadia.test; import java.security.PublicKey; import com.clowcadia.test.containers.ContainerBasic; import com.clowcadia.test.gui.GuiBasic; import com.clowcadia.test.npc.Basic; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler{ public static final int BASIC = 0; private Basic te; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){ return new ContainerBasic(player.inventory, te); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){ return new GuiBasic(player.inventory, te); } return null; } }
  9. Ok still nothing, I dissabled the tile entity that i created extra and moved some code and get this error [23:09:58] [Server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_121] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_121] at net.minecraft.util.Util.runTask(Util.java:27) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:753) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_121] Caused by: java.lang.NullPointerException at com.clowcadia.test.containers.ContainerBasic.<init>(ContainerBasic.java:20) ~[ContainerBasic.class:?] at com.clowcadia.test.GuiHandler.getServerGuiElement(GuiHandler.java:22) ~[GuiHandler.class:?] at net.minecraftforge.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:254) ~[NetworkRegistry.class:?] at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:89) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2733) ~[EntityPlayer.class:?] at com.clowcadia.test.npc.Basic.processInteract(Basic.java:83) ~[Basic.class:?] at net.minecraft.entity.EntityLiving.processInitialInteract(EntityLiving.java:1337) ~[EntityLiving.class:?] at net.minecraft.entity.player.EntityPlayer.interactOn(EntityPlayer.java:1273) ~[EntityPlayer.class:?] at net.minecraft.network.NetHandlerPlayServer.processUseEntity(NetHandlerPlayServer.java:1067) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketUseEntity.processPacket(CPacketUseEntity.java:94) ~[CPacketUseEntity.class:?] at net.minecraft.network.play.client.CPacketUseEntity.processPacket(CPacketUseEntity.java:15) ~[CPacketUseEntity.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_121] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_121] at net.minecraft.util.Util.runTask(Util.java:26) ~[Util.class:?] ... 5 more The updated Basic package com.clowcadia.test.npc; import com.clowcadia.test.GuiHandler; import com.clowcadia.test.TestModHandler; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraft.block.ITileEntityProvider; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class Basic extends EntityLiving implements ICapabilityProvider{ private ItemStackHandler handler; public Basic(World world) { super(world); this.handler = new ItemStackHandler(9); } @Override public void readFromNBT(NBTTagCompound compound) { this.handler.deserializeNBT(compound.getCompoundTag("ItemStackHandler")); super.readFromNBT(compound); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("ItemStackHandler", this.handler.serializeNBT()); return super.writeToNBT(compound); } public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); } public NBTTagCompound getUpdateTag() { NBTTagCompound compound = new NBTTagCompound(); this.writeToNBT(compound); return compound; } public void handleUpdateTag(NBTTagCompound tag) { this.readFromNBT(tag); } public NBTTagCompound getTileData() { NBTTagCompound compound = new NBTTagCompound(); this.writeToNBT(compound); return compound; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) this.handler; return super.getCapability(capability, facing); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; return super.hasCapability(capability, facing); } @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { if (!this.world.isRemote) { System.out.println("Player has interacted with the mob"); player.openGui(TestModHandler.instance, GuiHandler.BASIC, this.world, (int) player.posX, (int)player.posY, (int)player.posZ); } else { //player.openGui(ClowcadiaMod.modInstance, 0, this.world, (int) player.posX, (int)player.posY, (int)player.posZ); } return true; } }
  10. So are you saying put tileentitybasic code inside basic?
  11. i did and took the suggestion this is the result
  12. I tried this but nothing Main Class package com.clowcadia.test; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @Mod(modid = TestModHandler.modId, name = TestModHandler.name, version = TestModHandler.version) public class TestModHandler { public static final String modId = "testmod"; public static final String name = "Test Mod"; public static final String version = "1.0.0"; @Mod.Instance(modId) public static TestModHandler instance; @SidedProxy(serverSide = "com.clowcadia.test.CommonProxy", clientSide = "com.clowcadia.test.ClientProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event){ NPCHandler.registerNPCs(); proxy.registerTileEntities(); } @EventHandler public void init(FMLInitializationEvent event){ proxy.init(); } @EventHandler public void postInit(FMLPostInitializationEvent event){ } } CommonProxy package com.clowcadia.test; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; public class CommonProxy { public void registerTileEntities(){ GameRegistry.registerTileEntity(TileEntityBasic.class, TestModHandler.modId+"basic"); } public void init() { NetworkRegistry.INSTANCE.registerGuiHandler(TestModHandler.instance, new GuiHandler()); } } ClientProxy package com.clowcadia.test; import com.clowcadia.test.NPCHandler; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraftforge.event.terraingen.WorldTypeEvent.InitBiomeGens; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; public class ClientProxy extends CommonProxy{ @Override public void init(){ NetworkRegistry.INSTANCE.registerGuiHandler(TestModHandler.instance, new GuiHandler()); } } NPCHandler package com.clowcadia.test; import com.clowcadia.test.npc.Basic; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.EntityRegistry; public class NPCHandler { public static void registerNPCs(){ EntityRegistry.registerModEntity(new ResourceLocation(TestModHandler.modId,"basicNPC"), Basic.class, "BasicNPC", 0, TestModHandler.instance, 64, 1, true, 0x4286f4, 0x606e84); } } NPC Basic package com.clowcadia.test.npc; import com.clowcadia.test.GuiHandler; import com.clowcadia.test.TestModHandler; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraft.block.ITileEntityProvider; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumHand; import net.minecraft.world.World; public class Basic extends EntityLiving implements ITileEntityProvider{ public Basic(World world) { super(world); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityBasic(); } @Override public boolean processInteract(EntityPlayer player, EnumHand hand) { if (!this.world.isRemote) { System.out.println("Player has interacted with the mob"); player.openGui(TestModHandler.instance, GuiHandler.BASIC, world, (int) player.posX, (int)player.posY, (int)player.posZ); } else { //player.openGui(ClowcadiaMod.modInstance, 0, this.world, (int) player.posX, (int)player.posY, (int)player.posZ); } return true; } } TileEntityBasic package com.clowcadia.test.tileentities; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class TileEntityBasic extends TileEntity implements ICapabilityProvider{ private ItemStackHandler handler; public TileEntityBasic(){ this.handler = new ItemStackHandler(9); } @Override public void readFromNBT(NBTTagCompound compound) { this.handler.deserializeNBT(compound.getCompoundTag("ItemStackHandler")); super.readFromNBT(compound); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("ItemStackHandler", this.handler.serializeNBT()); return super.writeToNBT(compound); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); this.writeToNBT(compound); int metadata = getBlockMetadata(); return new SPacketUpdateTileEntity(this.pos, metadata, compound); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound compound = new NBTTagCompound(); this.writeToNBT(compound); return compound; } @Override public void handleUpdateTag(NBTTagCompound tag) { this.readFromNBT(tag); } @Override public NBTTagCompound getTileData() { NBTTagCompound compound = new NBTTagCompound(); this.writeToNBT(compound); return compound; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) this.handler; return super.getCapability(capability, facing); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; return super.hasCapability(capability, facing); } @Override public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) { return false; } } ContainerBasic package com.clowcadia.test.containers; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.SlotItemHandler; public class ContainerBasic extends Container{ private TileEntityBasic te; public ContainerBasic(IInventory playerInv, TileEntityBasic te) { this.te=te; IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); //Gets the inventory from our tile entity //Our tile entity slots this.addSlotToContainer(new SlotItemHandler(handler, 0, 62, 17)); this.addSlotToContainer(new SlotItemHandler(handler, 1, 80, 17)); this.addSlotToContainer(new SlotItemHandler(handler, 2, 98, 17)); this.addSlotToContainer(new SlotItemHandler(handler, 3, 62, 35)); this.addSlotToContainer(new SlotItemHandler(handler, 4, 80, 35)); this.addSlotToContainer(new SlotItemHandler(handler, 5, 98, 35)); this.addSlotToContainer(new SlotItemHandler(handler, 6, 62, 53)); this.addSlotToContainer(new SlotItemHandler(handler, 7, 80, 53)); this.addSlotToContainer(new SlotItemHandler(handler, 8, 98, 53)); //The player's inventory slots int xPos = 8; //The x position of the top left player inventory slot on our texture int yPos = 84; //The y position of the top left player inventory slot on our texture //Player slots for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18)); } } for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58)); } } @Override public boolean canInteractWith(EntityPlayer player) { return !player.isSpectator(); } } GuiHandler package com.clowcadia.test; import java.security.PublicKey; import com.clowcadia.test.containers.ContainerBasic; import com.clowcadia.test.gui.GuiBasic; import com.clowcadia.test.tileentities.TileEntityBasic; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler{ public static final int BASIC = 0; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){ return new ContainerBasic(player.inventory, (TileEntityBasic) world.getTileEntity(new BlockPos(x,y,z))); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID==BASIC){ return new GuiBasic(player.inventory, (TileEntityBasic) world.getTileEntity(new BlockPos(x,y,z))); } return null; } } GuiBasic package com.clowcadia.test.gui; import java.util.ArrayList; import java.util.List; import com.clowcadia.test.containers.ContainerBasic; import com.clowcadia.test.tileentities.TileEntityBasic; import com.clowcadia.tutorial3.Reference; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.items.CapabilityItemHandler; public class GuiBasic extends GuiContainer{ private TileEntityBasic te; private IInventory playerInv; public GuiBasic(IInventory playerInv, TileEntityBasic te) { super(new ContainerBasic(playerInv, te)); this.xSize=176; this.ySize=166; this.playerInv = playerInv; this.te = te; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0F, 1.0F, 1.0F,1.0F); this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/container/basic.png")); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize,this.ySize); } /** * Draws the text that is an overlay, i.e where it says Block Breaker in the gui on the top */ @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = I18n.format("container.basic"); //Gets the formatted name for the block breaker from the language file this.mc.fontRendererObj.drawString(s, this.xSize / 2 - this.mc.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //Draws the block breaker name in the center on the top of the gui this.mc.fontRendererObj.drawString(this.playerInv.getDisplayName().getFormattedText(), 8, 72, 4210752); //The player's inventory name int actualMouseX = mouseX - ((this.width - this.xSize) / 2); int actualMouseY = mouseY - ((this.height - this.ySize) / 2); if(actualMouseX >= 134 && actualMouseX <= 149 && actualMouseY >= 17 && actualMouseY <= 32 && te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(9) == ItemStack.EMPTY) { List<String> text = new ArrayList<String>(); text.add(TextFormatting.GRAY + I18n.format("gui.basic.enchanted_book.tooltip")); this.drawHoveringText(text, actualMouseX, actualMouseY); } } } Error report
  13. But how do i attach the tileentity to the class that is extended to entity livng
  14. Also not concearned about opening the gui, i am concerned about the data saving of the entityliving slots and the container is required for all of this to work i am also guessing u meant 250
  15. My entity horse only goes to 300 something what do u mean
  16. Wow, now i dont know where to start... reading the abstract horse class i learned that it has a container class that it calls to it but no entity class, or is it a entity class all on its own
  17. Say if i wanted my own entity class that extends Entityliving class could i use it as an entity living class and can i use its methods by overriding?
  18. Seems like horse class is a class that extending other classes that extend others. is that sometimes what is required for using methods from multiple of classes>
  19. So i am trying to make living entity to have a container and a way to access that with a gui, i been able to attach a gui before but not a container. I learned how to add a tile entity to a black and container and a gui doing so, but now i am trying to apply what i learned to a living entity or a living entity base. I notice in base code it already has the NBT stuff that one would usually apply to a block entity so i think i should use that. but i am not sure what i am doing. as as far as I learned i still need a tile entity to use with a container. can any one offer some advice or some help with this matter
  20. What to extend it to?
  21. ok....if i am how can i allow it to spawn in peaceful mode
  22. In my previous setup for this, i had no render it showered up like a white box, all on the same forge. i even had a gui available to it just no container(that's the goal now remaster it) so it doesn't need one. it shows up like it should but disappears..
  23. Just after its spawned from egg, immidiately, no error shown in the console
  24. It almost works by my npc keeps desapearing after its creation
×
×
  • Create New...

Important Information

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