Posted April 4, 20196 yr I am trying to keep a hashmap in my TileEntity of all the neighbors which have the power capability. I can get and store the neighbors, but for some reason every tick the hashmap clears. Code: Update method: @Override public void update() { if (lastConsume == 0) { if (fuel > 0 && power < max-production) { lastConsume = type.isFuel(getStack()); power += production; ITEMHANDLER.extractItem(0, 1, false); fuel -= 1; onConsume(); markDirty(); } else { getWorld().setBlockState(pos, getWorld().getBlockState(getPos()).cycleProperty(MachineBlock.LIT)); lastConsume -= 1; markDirty(); } } else if (lastConsume == -1) { if (fuel > 0 && power < max-production) { power += production; lastConsume = type.isFuel(getStack()); getWorld().setBlockState(pos, getWorld().getBlockState(getPos()).cycleProperty(MachineBlock.LIT)); ITEMHANDLER.extractItem(0, 1, false); fuel -= 1; onConsume(); markDirty(); } } else if(power < max-production){ lastConsume -= 1; power += production; } if(power > exportSpeed) { if (power > exportSpeed*neighbors.size()) { System.out.println(neighbors.size()); for(EnumFacing face : neighbors.keySet()) System.out.println("Power at " + face.getName()); for (IEnergyStorage storage : neighbors.values()) { power -= storage.receiveEnergy(exportSpeed, false); } } else { for (IEnergyStorage storage : neighbors.values()) { power -= storage.receiveEnergy(exportSpeed, false); if (power < exportSpeed) return; } } } } Neighbor finding method (Called in the block neighborUpdated method): public void onNeighborUpdated(BlockPos pos, World world, EnumFacing face, BlockPos fromPos) { if(world.getBlockState(fromPos).getBlock() == Blocks.AIR) { System.out.println("Removing neighbor!"); neighbors.remove(face); } TileEntity neighbor = world.getTileEntity(fromPos); if(neighbor == null) return; if(neighbor.hasCapability(CapabilityEnergy.ENERGY, face)) { System.out.println("Added neighbor at " + face.getName()); neighbors.put(face, neighbor.getCapability(CapabilityEnergy.ENERGY, face)); System.out.println(neighbors.size()); } } Removing neighbor! is not printed unless the block is removed, but every tick the hashmap is cleared. Whenever I add a neighbor, the hashmap length is the correct length. So basically: In update(), the hashmap is the empty, in onNeighborUpdated(), the hashmap is correct. Edited April 5, 20196 yr by diesieben07 syntax highlighting
April 5, 20196 yr Author I just posted it to GitHub as that is easier I tried to mimic EnderIO's multiple TEs/blocks one class system. The only other things there is the Creative tab. Im an idiot, https://github.com/BigBadE/AutoMechanica/ Edited April 5, 20196 yr by Big_Bad_E Forgot link...
April 6, 20196 yr Author It seems there are two instances of the TileEntity in the same position. By printing "this", I see two different TE instances, one gotten through world.getTileEntity, and never has the update method called, and one that has update called, but is not returned by the getTileEntity method. I am guessing this is because one is being run on client and the other is server side. I have my proxy setup, but I have two questions: 1. Which side should is the update method called on, and which side is neighborChanged() in the class Block called in? 2. How should I set the side? (Through proxy or through the annotation?)
April 7, 20196 yr 1. The server. Because the server has authority over the world. 2. You don't have to do anything. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 7, 20196 yr Author 9 hours ago, Draco18s said: 1. The server. Because the server has authority over the world. 2. You don't have to do anything. Then how do I get the correct instance that update is being called on? world.getTileEntity is giving me the wrong one.
April 7, 20196 yr You don't want to set anything here, what you have to do is query the side. Check if world#isRemote is false. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 7, 20196 yr Author 2 hours ago, Draco18s said: You don't want to set anything here, what you have to do is query the side. Check if world#isRemote is false. That was it, thanks!
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.