Jump to content

Emonadeo

Members
  • Posts

    10
  • Joined

  • Last visited

Everything posted by Emonadeo

  1. The API doesnt provide that.
  2. Yes. TileEntity handles everything that your Block contains. Like Chest contains items your block contains Energy. EDIT: And don't forget to save the energy in the writeto and readfrom NBT methods, otherwise it's gone on a world reload.
  3. You have literally overwritten the slotClick method. Do super.slotClick() before you do anything else i, so it's like this:'s like this: //I believe this is the problem. I don't understand the new set of arguments of this method. @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { super.slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player); Slot slot; if(slotId > 0) { slot = (Slot) this.inventorySlots.get(slotId); } else { slot = null; } if (slot instanceof SlotFake) { return slotClickFake(slot, dragType, clickTypeIn, player); } return super.slotClick(slotId, dragType, clickTypeIn, player); }
  4. Let your TileEntity implement IEnergyHandler. Not the block.
  5. Facepalm. Take a closer look at this line playerIn.openGui(ModularStorage.instance, Data.GUI_ASSEMBLER, worldIn, pos.getX(), pos.getY(), pos.getY());
  6. I give it a try but I dont know if that will fix it. Usually when I use IInventory I still contain a field in my tileentity and use IInventory just as a bridge. Also I was not planning on making it compatible with hoppers because it will be some sort of crafting table. Even if I could still use canConnect a field felt easier to use.
  7. Stacks? If you mean slots it has ten.
  8. So basically every time when I try to open the GUI of my block called "Storage Assembler" I am receiving a NullPointerException which refers to this line in the Container class: this.addSlotToContainer(new Slot(tile.inventory, 1, 44, 21)); I have made a working gui before in another mod and I compared the two source codes but I cant find the mistake. (Probably an obvious one) Full Crash Log: [22:20:29] [server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_77] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_77] at net.minecraft.util.Util.runTask(Util.java:26) [util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:742) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_77] Caused by: java.lang.NullPointerException at container.ContainerStorageAssembler.<init>(ContainerStorageAssembler.java:17) ~[ContainerStorageAssembler.class:?] at gui.GuiHandler.getServerGuiElement(GuiHandler.java:18) ~[GuiHandler.class:?] at net.minecraftforge.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:251) ~[NetworkRegistry.class:?] at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:87) ~[FMLNetworkHandler.class:?] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2723) ~[EntityPlayer.class:?] at blocks.BlockStorageAssembler.onBlockActivated(BlockStorageAssembler.java:47) ~[blockStorageAssembler.class:?] at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:477) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processRightClickBlock(NetHandlerPlayServer.java:706) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.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_77] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_77] at net.minecraft.util.Util.runTask(Util.java:25) ~[util.class:?] ... 5 more Container: package container; public class ContainerStorageAssembler extends Container { TileEntityStorageAssembler tile; public ContainerStorageAssembler(IInventory inv, TileEntityStorageAssembler tile) { this.tile = tile; int j; int k; this.addSlotToContainer(new Slot(tile.inventory, 1, 44, 21)); //If I erase this line everything will work fine. int i = -18; for(j = 0; j < 3; j++) { for (k = 0; k < 9; k++) { this.addSlotToContainer(new Slot(inv, k + j * 9 + 9, 8 + k * 18, 102 + j * 18 + i)); } } for(j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(inv, j, 8 + j * 18, 160 + i)); } } @Override public boolean canInteractWith(EntityPlayer playerIn) { return true; } } Tile Entity: package tileentity; public class TileEntityStorageAssembler extends TileEntity { public InventoryBasic inventory; public TileEntityStorageAssembler() { inventory = new InventoryBasic("StorageAssemblerInventory", false, 10); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagList list = new NBTTagList(); for(int i = 0; i < inventory.getSizeInventory(); i++) { if(inventory.getStackInSlot(i) != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("slot", (byte) i); inventory.getStackInSlot(i).writeToNBT(tag); } } compound.setTag("items", list); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); NBTTagList list = compound.getTagList("items", 10); inventory = new InventoryBasic("StorageAssemblerInventory", false, 10); for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound tag = list.getCompoundTagAt(i); byte b = tag.getByte("slot"); if(b >= 0 && b < inventory.getSizeInventory()) { inventory.setInventorySlotContents(b, ItemStack.loadItemStackFromNBT(tag)); } } } } Gui Handler: package gui; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case Data.GUI_ASSEMBLER: return new ContainerStorageAssembler(player.inventory, (TileEntityStorageAssembler) world.getTileEntity(new BlockPos(x, y, z))); default: return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case Data.GUI_ASSEMBLER: return new GuiStorageAssembler(new ContainerStorageAssembler(player.inventory, (TileEntityStorageAssembler) world.getTileEntity(new BlockPos(x, y, z)))); default: return null; } } } Gui: package gui; public class GuiStorageAssembler extends GuiContainer { public static final ResourceLocation GUILOC = new ResourceLocation(Data.MODID + ":textures/gui/assembler.png"); public GuiStorageAssembler(Container container) { super(container); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { mc.renderEngine.bindTexture(GUILOC); int px = (this.width - this.xSize) / 2; int py = (this.height - this.ySize) / 2; drawTexturedModalRect(px, py, 0, 0, xSize, ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { int px = this.xSize / 2; String title = I18n.format("container.storageassembler"); fontRendererObj.drawString(title, px - (fontRendererObj.getStringWidth(title) / 2), 5, 4210752); } } Block: package blocks; public class BlockStorageAssembler extends BlockContainer { public BlockStorageAssembler() { super(Material.IRON); setUnlocalizedName("storage_assembler"); setRegistryName("storage_assembler"); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityStorageAssembler(); } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if(!worldIn.isRemote) { TileEntity te = worldIn.getTileEntity(pos); if(te instanceof TileEntityStorageAssembler) { playerIn.openGui(ModularStorage.instance, Data.GUI_ASSEMBLER, worldIn, pos.getX(), pos.getY(), pos.getY()); } } return true; } } Main: package main; @Mod(modid=Data.MODID, version=Data.VERSION, name=Data.NAME) public class ModularStorage { @SidedProxy(serverSide="proxy.ServerProxy", clientSide="proxy.ClientProxy") public static ServerProxy proxy; @Instance public static ModularStorage instance; public static CreativeTabs tabModularStorage = new CreativeTabs("modularStorage") { @Override public Item getTabIconItem() { return itemModuleItems; } }; public static ItemModuleItems itemModuleItems = new ItemModuleItems(); public static ItemModuleFluids itemModuleFluids = new ItemModuleFluids(); public static ItemModuleEnergy itemModuleEnergy = new ItemModuleEnergy(); public static BlockStorageAssembler blockStorageAssembler = new BlockStorageAssembler(); @EventHandler public void preInit(FMLPreInitializationEvent e) { GameRegistry.registerTileEntity(TileEntityStorageAssembler.class, "TileEntityStorageAssembler"); GameRegistry.register(itemModuleItems); GameRegistry.register(itemModuleFluids); GameRegistry.register(itemModuleEnergy); registerBlock(blockStorageAssembler); } @EventHandler public void init(FMLInitializationEvent e) { proxy.registerClient(); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); } @EventHandler public void postInit(FMLPostInitializationEvent e) { } public void registerBlock(Block block) { GameRegistry.register(block); GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName())); } } #Edit: Removed Import lines
  9. That did work! And I can't get why. But thank you so much For anyone who runs into the same problem - it would look something like this: @SideOnly(Side.CLIENT) @Override public void registerBlockIcons(IIconRegister reg) { stillIcon = reg.registerIcon(Data.MODID + ":fluids/Oil_Still"); flowingIcon = reg.registerIcon(Data.MODID + ":fluids/Oil_Flow"); Block_Engineering.fluidOil.setIcons(stillIcon, flowingIcon); }
  10. I amde a custom fluid (oil) and everything is working but the textures in the gui. I looked up in the source code from CoFHLib that the method drawFluid (to draw the Fluid inside an gui) uses the IIcon from the Fluid and not the BlockFluidClassic. Couldn't find anything on the internet or in other source codes. Source Code (excluding package anmes and imports): Main Class: @Mod(modid=Data.MODID, name=Data.NAME, version=Data.VERSION, dependencies="required-after:CoFHLib") public class Block_Engineering { @Instance public static Block_Engineering instance; @SidedProxy(clientSide="com.emonadeo." + Data.MODID + ".proxy.ClientProxy", serverSide="com.emonadeo." + Data.MODID + "proxy.ServerProxy") public static ServerProxy proxy; public static Block blockRepository; public static Block blockFluidOil; public static Fluid fluidOil; public static Item itemBucketOil; @EventHandler public void preInit(FMLPreInitializationEvent e) { //Fluids fluidOil = new Fluid("Oil"); FluidRegistry.registerFluid(fluidOil); //Blocks blockRepository = new Block_Repository(); blockFluidOil = new Block_Fluid_Oil(); //Items itemBucketOil = new Item_Bucket_Oil(blockFluidOil); //TileEntities GameRegistry.registerTileEntity(TileEntity_Repository.class, "TileEntity_Repository"); } @EventHandler public void init(FMLInitializationEvent e) { //Blocks GameRegistry.registerBlock(blockRepository, Item_Repository.class, "Repository"); GameRegistry.registerBlock(blockFluidOil, "Oil"); //Items GameRegistry.registerItem(itemBucketOil, "Bucket_Oil"); FluidContainerRegistry.registerFluidContainer(fluidOil, new ItemStack(itemBucketOil), new ItemStack(Items.bucket)); //Fluids fluidOil.setUnlocalizedName(blockFluidOil.getUnlocalizedName()); //Gui NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); //Register Renderer proxy.registerRenderer(); //Ore Dictionary OreDictionary.registerOre("blockOil", blockFluidOil); } @EventHandler public void postInit(FMLPostInitializationEvent e) { } } Block_Fluid_Oil: public class Block_Fluid_Oil extends BlockFluidClassic { @SideOnly(Side.CLIENT) protected IIcon stillIcon; @SideOnly(Side.CLIENT) protected IIcon flowingIcon; public static final Material materialFluidOil = new MaterialLiquid(MapColor.blackColor); public Block_Fluid_Oil() { super(Block_Engineering.fluidOil, materialFluidOil); setBlockName("Oil"); } @Override public IIcon getIcon(int side, int meta) { return (side == 0 || side == 1) ? stillIcon : flowingIcon; } @SideOnly(Side.CLIENT) @Override public void registerBlockIcons(IIconRegister reg) { stillIcon = reg.registerIcon(Data.MODID + ":fluids/Oil_Still"); flowingIcon = reg.registerIcon(Data.MODID + ":fluids/Oil_Flow"); } @Override public boolean canDisplace(IBlockAccess world, int x, int y, int z) { if (world.getBlock(x, y, z).getMaterial().isLiquid()) { return false; } return super.canDisplace(world, x, y, z); } @Override public boolean displaceIfPossible(World world, int x, int y, int z) { if (world.getBlock(x, y, z).getMaterial().isLiquid()) { return false; } return super.displaceIfPossible(world, x, y, z); } }
×
×
  • Create New...

Important Information

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