Jump to content

tommyte

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by tommyte

  1. You are, like the error report is saying, referencing a field that doesn't exist in your this class : at mcjty.theoneprobe.network.PacketGetInfo$Handler.handle(PacketGetInfo.java:110) ~[PacketGetInfo$Handler.class:?] Maybe you can solve it yourself now. Otherwise I'll need to see that class to help you further (:
  2. You could, of course, just check if the returned itemstack is empty or not, and then check if it is a glass bottle. I'm not exactly sure what it is you want to do here though. So maybe you could give us a little more information about that (:
  3. player.getEntityWorld(); (or something like that) you can use this: PacketDispatcher.sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, x, y, z, range)); Just set the range to a value that would make sure no one outside it can hover over the block.
  4. You can get the singleplayer player by calling Minecraft.getMinecraft().player.
  5. I usually do it like this: data.setIntArray("ints", new int[]{pos.getX(), pos.getY(), pos.getZ(), amount}); Here I set an array of integers with the three coords of the tile entity and the number i'd like to transfer. int[] values = message.data.getIntArray("ints"); final String name = message.data.getString("string"); final BlockPos pos = new BlockPos(values[0], values[1], values[2]); final int amount = values[3]; Then in the messagehandler I read these values like this. TileEntity entity = theplayer.getEntityWorld().getTileEntity(pos); if(entity != null && entity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) { //here do something like entity.getCapability(etc., etc.).setEnergy(amount); } You'd put something like this into your run method.
  6. There you go This method, as the name implies detects and sends changes (on server side) and sends them to the client. This then only occurs when the container is activated, aka when the player open the gui. You should set up your own networking to sync properly between server and client. Here is an article about in on the docs: https://mcforge.readthedocs.io/en/latest/networking/ Read all the articles there about networking and then you should be good to go
  7. I can't find any networking here. I'd really like to see where you are syncing up your client side with your server side. You are, logically, only changing the amount of energy stored on server side, so the client side, what waila is displaying (I think), doesn't know of any changes in the amount of energy stored until you send a packet there
  8. If I were to guess I'd say it's a syncing issue. Are you by chance syncing up your server and client tileentity the moment you open the gui / right click the block? In any case I would like to see the block and tileentity classes (:
  9. This is an example with the energy capability: public NBTBase serializeNBT() { NBTTagCompound nbt = new NBTTagCompound(); nbt.setInteger("energy", energy.getEnergyStored()); return nbt; } public void deserializeNBT(NBTBase nbt) { if(((NBTTagCompound) nbt).hasKey("energy")) { energy.setEnergy(((NBTTagCompound) nbt).getInteger("energy")); } } Notice that you can only store the info from the capability here. So in your case you'd save the items in the inventory of your item here. If, however, you want to store more info on the nbt of the itemstack, you should use ItemStack::getTagCompound() to retrieve and alter the nbt tag compound of your item. Call this where ever you find it useful. Maybe you want to update the nbt every tick? Then call it in the update method. If you want to update it every time the item is right-clicked? Use the onItemRightClick method.
  10. capacidaddealmacenamiento xt = (capacidaddealmacenamiento) itemstack.getCapability(capacidaddealmacenamiento, EnumFacing.UP); should be: capacidaddealmacenamiento xt = (capacidaddealmacenamiento) itemstack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); Furthermore, you'd need a capabilityprovider for this item: public static class ExampleProvider implements ICapabilityProvider, ICapabilitySerializable { @Override public NBTBase serializeNBT() { //Retrieve data here return null; } @Override public void deserializeNBT(NBTBase nbt) { //Do your saving here } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return false; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) new ItemStackHandler(2/**the amount of slots you want*/); //This is the default implementation by forge, but you'll likely want to make your own by overriding. } return null; } } Serialize and deserialize nbt will be called for you when the world respectively starts or closes. You can save your stored items here using the ItemStackHelper class. I don't quite get the purpose of this either: playerIn.setActiveHand(handIn); But, if you'd try explaining us a little more what exactly it is you want to achieve, I'm sure we could help you out a little better (:
  11. False alarm, I figured it out already. My 'getCoreEntity()' method didn't work properly. I wonder why it didn't spit out an error, but o well. Thanks anyways!
  12. Hello everyone, I'm working on a multiblock structure with a core tile entity that should store all the data, like items. I got another tile entity in the multiblock that should be able to in- and output items to and from the inventory of that core tile entity. I tried to achieve this by returning the instance of the ItemStackHandler of the core tile entity in the getCapability method in the other tile entity. It looks like this: //The class that should in and output to the core tile entity public class TileEntityMultiblockItemHandler extends TileEntity implements IMultiblockTileEntity{ private TSMultiblock block; public TileEntityMultiblockItemHandler() { } @Override public TSMultiblock getMultiblock() { return ((IMultiblockBlock)world.getBlockState(pos).getBlock()).getMultiblock(world, pos); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return super.hasCapability(capability, facing); } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) getMultiblock().getCoreEntity().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing); } return super.getCapability(capability, facing); } @Override public void onMultiblockLoad() { } } And //The core tile entity public class TileEntityFabricator extends TileEntityMachineBasic implements ITickable, IInteractionObject, ITileEntityInterface{ private int currentFormTime; private int totalFormTime; private int energyConsumption; private TSEnergyStorage energy; private TSItemStorage inventory; public TileEntityFabricator() { totalFormTime = TSConfigHandler.runtimeFabricator; currentFormTime = 0; energyConsumption = TSConfigHandler.fabricatorConsumption; energy = new TSEnergyStorage(10000, 0, 0); inventory = new TSItemStorage(10); } //I left a bunch of methods out here @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) { return true; } if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return super.hasCapability(capability, facing); } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) { return (T) energy; } if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) inventory; } return super.getCapability(capability, facing); } } The problem: when I attach a hopper to the itemhandler tile entity, it inputs items, but I can't see them on the gui. Furthermore, I can get the items I put in out again with a hopper, but the items inside that I can see and access through the gui stay put. What have I done wrong?
  13. private void setMultiblockAndRotate() { Hashtable<BlockPos, Block> blocks = new Hashtable<BlockPos, Block>(); Hashtable<BlockPos, TileEntity> entities = new Hashtable<BlockPos, TileEntity>(); int offset = getFacingOffset(facing); for(int x = bx; x <= ex; x++) { for(int y = by; y <= ey; y++) { for(int z = bz; z <= ez; z++) { BlockPos oldpos = new BlockPos(x,y,z); //this puts the blockpos in a 2d vector and rotates it, so it will face correctly Vector2d vec = new Vector2d(oldpos.getX(), oldpos.getZ()); vec = Util.getNormalVector(vec, offset); BlockPos newpos = new BlockPos(vec.x, oldpos.getY(), vec.y); if(newpos.equals(BlockPos.ORIGIN)) { blocks.put(newpos, BlockRegistry.basicmachine); } else //'blocks' is a hashtable simelar to blocks in this method. But, that table already has values that I set earlier. if(this.blocks.containsKey(oldpos)) { blocks.put(newpos, this.blocks.get(oldpos)); } else { blocks.put(newpos, fillerBlock); //fillerBlock is a block that I also defined earlier. Its just there so that I dont have to put those blocks at a position. This code just assumes that everything that isnt defined should be this block } if(this.tileentities.containsKey(oldpos)) { entities.put(newpos, this.tileentities.get(oldpos)); } } } } frame = blocks; tileentities = entities; } This is how I've done it. It works by indexing blocks by their relative blockpositions (relative to the controller). Later you'd check if all the blocks defined in 'frame' are actually in the world, and if so, it'll form the multiblock. This way you could also add new tileEntities to handle things like in- and outputting liquids.
  14. You will have to ready and write to nbt yourself, in your capability provider class. For what you made, you don't have to inject an existing capability, and you should instead extends the ItemStackHandler class there. It seems like you did a great job of making your own implementation. You don't have to register that class. You can instantiate it in your item class. Like below. Mind you, this class I made very quickly and without much experience with capabilities for items. It seems quite different from tile entities but still. I hope i'll give you a rough idea of what you should do. public class ItemExample extends Item{ ItemStackHandler inventory; public ItemExample() { } public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack stackToSaveTo = playerIn.getHeldItem(handIn); //Do add a check to see if this really is your item. //You probably wont need the capability until you open the inventory for the first time. So.. if(inventory == null) { inventory = (ItemStackHandler) initCapabilities(stackToSaveTo, null).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); } //Then here you can open the inventory and things, and, load data from nbt. NBTTagCompound nbt = new NBTTagCompound(); inventory.deserializeNBT(nbt); //Now the nbt has all the information you need. Granted you gave what you wanted in the method below. //Now you can open inventory and things, and let the player do stuff. return new ActionResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); } public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) { //This should do what it says, so now you can save the data that has changed. inventory.serializeNBT(); } @Override public ICapabilityProvider initCapabilities(ItemStack item, NBTTagCompound nbt) { if(item.getItem() instanceof ItemExample) { return new ExampleProvider(); } return null; } public static class ExampleProvider implements ICapabilityProvider, ICapabilitySerializable { @Override public NBTBase serializeNBT() { //Retrieve data here return null; } @Override public void deserializeNBT(NBTBase nbt) { //Do your saving here } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return false; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) new ItemStackHandler(2/**the amount of slots you want*/); //This is the default implementation by forge, but you'll likely want to make your own by overriding. } return null; } } } Just try without and see what happens. If there is information missing on the client side, you can send packages to sync up. But only when needed.
  15. Alright, your code seems pretty messy, so you might want to try to clean it up a bit. It really makes things easier Regarding the capabilities. You should override getCapability and hasCapability in your item class. (Might be itemstack, ill look it up for you later). You can initialize an instance of the itemstackhandler capability and return that instance in getcapability. You can look it up in the documentation. Good luck, and let me know if you need more help.
  16. Alright I fixed it! So it turned out my packet didn't quite work, so the client side didn't update what tile entity was there, so it couldn't open the right gui's... Thanks for your help! (:
  17. So, I guess you could do that... I'll give it a try, thx!
  18. Alright, it seems that it only resets the tile entity on server side, even though the method is called on both sides.
  19. I'm trying to make a block that has multiple functionalities. Like a furnace and a chest and a battery or something. I'd like to be able to dynamically add more tile entities to this list, so, the block should be able to iterate through this list. I got it to the point where setTileEntity seems to set the new tile entity, but when I try to access it later, it changed back to the original tile entity.
  20. Hello everyone, I'm trying to create a block that is able to switch between several tile entities, each time it's activated. However, world.removeTileEntity(blockpos) and world.setTileEntity(blockpos, tileentity) don't seem to work. Is that because my block only returns one tile entity in the createNewTileEntity(world, meta) method? What should I use to do what I want to do? Thanks in advance (:
  21. Then I guess I'll keep doing it the way I'm doing it now. Thanks for your time guys!
  22. Hello there, I'm trying to create a block that can replace other blocks, and keep the properties (and material) of that block. This way I can assign some extra functionality. Right now I create a new instance of that block each time it's placed. This way I can give the material to the super and imitate it that way. This is not a very nice way of doing it though, so I'd like to ask if there's another way. Thx!
  23. I got it! Turns out I was saving to and loading from a different tag. Thx!
×
×
  • Create New...

Important Information

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