Everything posted by memcallen
-
TileEntity inventory without using IInventory?
Please give me an example because obviously I'm incompetent for making for loops.
-
TileEntity inventory without using IInventory?
I don't even care anymore, I figured out for loops. I figured out GUIs I haven't figured out where to render it. I know how to render it. I've used GL11 and the tessellators before. Honestly, this topic isn't about for loops its about ItemStacks not saving in nbt, so please either answer my first question or don't answer at all.
-
TileEntity inventory without using IInventory?
I don't see any reason why I should change it, considering thats pretty much all my code. anyways, this idea was just a work around for a gui (I can't figure out for the life of me how to make it render in the right spot).
-
TileEntity inventory without using IInventory?
Good luck sorting through the onBlockActivated code... package com.example.gammacraft.blocks.Machines; import com.example.gammacraft.RandomFunctions; import com.example.gammacraft.gammacraft; import com.example.gammacraft.TileEntity.MultiToolModifierTileEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class MultiToolModifier extends BlockContainer { public MultiToolModifier() { super(Material.iron); this.setBlockBounds(0F, 0F, 0F, 1F, 0.25F, 1F); this.setBlockName("MultiToolModifier"); this.setCreativeTab(gammacraft.gammacraftcreativetab); } float pixel = 1F/16F; @Override public boolean onBlockActivated(World world,int x,int y,int z,EntityPlayer player,int side,float hx,float hy,float hz){ MultiToolModifierTileEntity te = (MultiToolModifierTileEntity)world.getTileEntity(x, y, z); if(side==1){ //slot 1 if(withinBounds(hx,pixel*2,pixel*4)&&withinBounds(hz,pixel*4,pixel*6)){ if(!world.isRemote) System.out.println("Button 1 is pressed"); if(te.inv[0]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[0]; te.inv[0]=null; }else{ te.inv[0]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 2 if(withinBounds(hx,pixel*2,pixel*4)&&withinBounds(hz,pixel*7,pixel*9)){ if(!world.isRemote) System.out.println("Button 2 is pressed"); if(te.inv[1]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[1]; te.inv[1]=null; }else{ te.inv[1]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 3 if(withinBounds(hx,pixel*2,pixel*4)&&withinBounds(hz,pixel*10,pixel*12)){ if(!world.isRemote) System.out.println("Button 3 is pressed"); if(te.inv[2]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[2]; te.inv[2]=null; }else{ te.inv[2]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 4 if(withinBounds(hx,pixel*5,pixel*7)&&withinBounds(hz,pixel*4,pixel*6)){ if(!world.isRemote) System.out.println("Button 4 is pressed"); if(te.inv[3]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[3]; te.inv[3]=null; }else{ te.inv[3]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 5 if(withinBounds(hx,pixel*5,pixel*7)&&withinBounds(hz,pixel*7,pixel*9)){ if(!world.isRemote) System.out.println("Button 5 is pressed"); if(te.inv[4]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[4]; te.inv[4]=null; }else{ te.inv[4]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 6 if(withinBounds(hx,pixel*5,pixel*7)&&withinBounds(hz,pixel*10,pixel*12)){ if(!world.isRemote) System.out.println("Button 6 is pressed"); if(te.inv[5]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[5]; te.inv[5]=null; }else{ te.inv[5]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 7 if(withinBounds(hx,pixel*8,pixel*10)&&withinBounds(hz,pixel*4,pixel*6)){ if(!world.isRemote) System.out.println("Button 7 is pressed"); if(te.inv[6]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[6]; te.inv[6]=null; }else{ te.inv[6]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 8 if(withinBounds(hx,pixel*8,pixel*10)&&withinBounds(hz,pixel*7,pixel*9)){ if(!world.isRemote) System.out.println("Button 8 is pressed"); if(te.inv[7]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[7]; te.inv[7]=null; }else{ te.inv[7]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 9 if(withinBounds(hx,pixel*8,pixel*10)&&withinBounds(hz,pixel*10,pixel*12)){ if(!world.isRemote) System.out.println("Button 9 is pressed"); if(te.inv[8]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[8]; te.inv[8]=null; }else{ te.inv[8]=player.inventory.mainInventory[player.inventory.currentItem]; player.inventory.mainInventory[player.inventory.currentItem]=null; } return true; } //slot 10 (output) if(withinBounds(hx,pixel*12,pixel*14)&&withinBounds(hz,pixel*7,pixel*9)){ if(!world.isRemote) System.out.println("Button 10 is pressed"); if(te.inv[9]!=null){ player.inventory.mainInventory[player.inventory.currentItem]=te.inv[9]; te.inv[9]=null; } return true; } } return false; } @Override public TileEntity createNewTileEntity(World var1, int var2) { return new MultiToolModifierTileEntity(); } @SideOnly(Side.CLIENT) public static IIcon sideIcon; @SideOnly(Side.CLIENT) public static IIcon bottom; @SideOnly(Side.CLIENT) public static IIcon top; public void registerBlockIcons(IIconRegister i){ sideIcon = i.registerIcon("gammacraft:FireJetSide"); top = i.registerIcon("gammacraft:MultiToolModifierTop"); } public IIcon getIcon(int side, int meta){ if(side==1)return top; else return sideIcon; } public boolean withinBounds(float x, float min,float max){ return x>min&&x<max; } } EDIT: you're lucky I decided to make a youtube video on how it works in the world. Should make it easier to figure out how it works.
-
TileEntity inventory without using IInventory?
...I know, those are all vanilla classes
-
TileEntity inventory without using IInventory?
ok I'm getting somewhere, I changed the for loops to for(int i = 0;i!=inv.length+1;i++){//do stuff}, and I added a try/catch around a line in the read func, but I'm getting an error with the function "func_150298_a" I googled it and I'm writing an nbt tag to itself, but I can't see where or how. btw there is no error showing me where the line is thats causing the error. stacktrace: java.lang.NullPointerException at net.minecraft.nbt.NBTTagCompound.func_150298_a(NBTTagCompound.java:309) at net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:23) at net.minecraft.nbt.NBTTagList.write(NBTTagList.java:35) at net.minecraft.nbt.NBTTagCompound.func_150298_a(NBTTagCompound.java:314) at net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:23) at net.minecraft.nbt.NBTTagCompound.func_150298_a(NBTTagCompound.java:314) at net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:23) at net.minecraft.nbt.CompressedStreamTools.func_150663_a(CompressedStreamTools.java:146) at net.minecraft.nbt.CompressedStreamTools.write(CompressedStreamTools.java:136) at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkNBTTags(AnvilChunkLoader.java:197) at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeNextIO(AnvilChunkLoader.java:183) at net.minecraft.world.storage.ThreadedFileIOBase.processQueue(ThreadedFileIOBase.java:30) at net.minecraft.world.storage.ThreadedFileIOBase.run(ThreadedFileIOBase.java:23) at java.lang.Thread.run(Unknown Source) This doesn't crash me but I have no idea how to fix it. EDIT: the error only gets thrown when I take the item out of my block.
-
TileEntity inventory without using IInventory?
I'm tired and can't find any issues right now please point them out.
-
TileEntity inventory without using IInventory?
whatever, I changed the code to this: package com.example.gammacraft.TileEntity; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class MultiToolModifierTileEntity extends TileEntity { public ItemStack[] inv; public MultiToolModifierTileEntity() { inv=new ItemStack[10]; } public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } public void writeToNBT(NBTTagCompound nbt){ for(int i =1;i==inv.length;i++){ NBTTagCompound NBT = new NBTTagCompound(); inv[i].writeToNBT(NBT); nbt.setTag("ItemStack"+i,NBT); nbt.setTag("ItemStackData"+i, inv[i].stackTagCompound); } } public void readFromNBT(NBTTagCompound nbt){ for(int i =1;i==inv.length;i++){ NBTTagCompound itemstack = nbt.getCompoundTag("ItemStack"+i); NBTTagCompound data = nbt.getCompoundTag("ItemStackData"+i); inv[i]=ItemStack.loadItemStackFromNBT(itemstack); inv[i].stackTagCompound=data; } } } but it still doesn't save the stack.
-
TileEntity inventory without using IInventory?
I know basic java, but I misunderstood for loops.
-
TileEntity inventory without using IInventory?
Oh, I though the i++ was optional0
-
TileEntity inventory without using IInventory?
I've never understood for loops and well yeah...it kinda sucks
-
TileEntity inventory without using IInventory?
yes but I'm not using a gui, and I'm not making it automatable. I see no reason to add extra functions to my TileEntity class. Anyways, do you know why my ItemStack isn't saving?
-
TileEntity inventory without using IInventory?
I don't want it to be automatable at all. Also when I close the world and reopen it the ItemStack that I put in doesn't get written or read properly from nbt and doesn't reload into the slot I put it in.
-
TileEntity inventory without using IInventory?
I don't know if this is the correct way to store items in nbt but heres my code: package com.example.gammacraft.TileEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; public class MultiToolModifierTileEntity extends TileEntity { public ItemStack[] inv; public MultiToolModifierTileEntity() { inv=new ItemStack[10]; } public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } public void writeToNBT(NBTTagCompound nbt){ for(int i =1;i==inv.length;){ NBTTagCompound NBT = new NBTTagCompound(); inv[i].writeToNBT(NBT); nbt.setTag("ItemStack"+i,NBT); nbt.setTag("ItemStackData"+i, inv[i].stackTagCompound); } } public void readFromNBT(NBTTagCompound nbt){ for(int i =1;i==inv.length;){ NBTTagCompound itemstack = nbt.getCompoundTag("ItemStack"+i); NBTTagCompound data = nbt.getCompoundTag("ItemStackData"+i); inv[i]=ItemStack.loadItemStackFromNBT(itemstack); inv[i].stackTagCompound=data; } } } I currently have it take the item in my hand and it puts the item in the ItemStack[] "inv"- thats the part that works. I can't make it save to NBT, for whatever reason. If you were wondering why I'm not using IInventory, it's because I don't want this block to be able to be automated-its my version of a crafting table.
-
How to detect if player is pressing shift
Thanks, it works.
-
How to detect if player is pressing shift
How can I detect if a player is pressing shift? Not sneaking but just pressing shift. I want to know because I'm trying to add lore that only shows up when you press shift, like Thermal Expansion's energy cells.
-
[1.7.2]Is it possible to save a World obj. in NBT?
Thanks.
-
[1.7.2]Is it possible to save a World obj. in NBT?
I have a class which essentially justs saves a block position to nbt and can load it from nbt, and I want to store either a TileEntity or a world obj. in the nbt as well heres my class if you need it: package com.example.gammacraft.Helpers; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class BlockPos { int x,y,z; World world; TileEntity te; public BlockPos(int x,int y,int z,World world,TileEntity te) { this.x=x; this.y=y; this.z=z; this.world=world; this.te=te; } public BlockPos(){ } public void writeToNBT(NBTTagCompound nbt){ nbt.setInteger("x", x); nbt.setInteger("y", y); nbt.setInteger("z", z); } public void readFromNBT(NBTTagCompound nbt){ this.x = nbt.getInteger("x"); this.y = nbt.getInteger("y"); this.z = nbt.getInteger("z"); } }
-
Entity Spawning Problem
In your Entity's onUpdate function do System.out.println("x:"+x+"y:"+"z:"+z) to make sure that it's coordinates are being inputed correctly.
-
Storing an ItemStack in NBT
I found loadItemStackFromNBT() but what is the other function to get an NBT tag from an ItemStack? I don't want to use IInventory mainly because I don't want my mod to be easily automatable with other mods because I will add my own kind of automation, I will probably add a single block to add compatibility instead of having to use autonomus activators (from Thermal Expansion) to interact with my blocks.
-
Storing an ItemStack in NBT
Does this allow for the ItemStack to be stored in the NBT of a TileEntity? It looks like you are just setting the NBT for the ItemStack.
-
Storing an ItemStack in NBT
how can I store an ItemStack in an NBT (it's for a tileEntity Inventory). The thing is, is that it's not with a GUI, so I don't want to implement IInventory. Can someone help?
-
Best way to consume item in inventory?
I don't have my code right now but this is what I think I have public void onItemRightClicked(ItemStack itemstack, World world, EntityPlayer player){ NBTTagCompound nbt = itemstack.stackTagCompound; if(nbt!=null){ if(player.isSneaking){ if(player.inventory.hasItem(gammacraft.Uran235)){ player.inventory.consumeInventoryItem(gammacraft.Uran235); nbt.setInteger("Energy",nbt.getInteger("Energy")+1); itemstack.stackTagCompound=nbt; } }else{ player.addChatMessage(new ChatComponentText("Energy: "+nbt.getInteger("Energy")); } } } it removes the item "Uran235" from the players inventory if they are sneaking and increments the Energy tag.
-
Best way to consume item in inventory?
It doesn't visually update, I have to right click the stack to make it update, also it's getting called in my item's right click method.
-
Best way to consume item in inventory?
I've been using player.inventory.consumeInventoryItem() but it doesn't update the stack properly, whats the best way to consume an item from the player's inventory?
IPS spam blocked by CleanTalk.