Posted August 4, 20196 yr Hi everyone, So i'm trying to start some minecraft modding, one of the things i'd like to create is a block capable of increasing or decreasing amount of ticks in a determinated range. I made some research but I did'nt find anything about it, any help ? I also added a staff capable of throwing an entity which applies a potion effect (wither) on the hited target but sadly the thrower also takes wither effects (black hearts) but this wither effect doesn't harm him and I can't figure out how to avoid giving this effect to the thrower. Thanks for reading ! Edited August 4, 20196 yr by Temps Pi
August 4, 20196 yr One way you could speed up ticks would be to scan the AOE for TileEntities that implement ITickable and then manually call update(). Since update() is also being called by the game tick clock, any additional time you called it would speed up any machines in the area. Obviously, this is basically the definition of a lag machine, so make sure any loop code you add is as lean as possible. I have no idea how you'd slow down tick clocks. You could easily do it for TileEntities that you control by simply skipping update() ticks based on a state. I don't know if there's a way to do it in a general-purpose fashion. I know that there are items in mods that speed up ticks. If their code is public, you could certainly scan through their code and see how they do it. I don't know if there's any objects the slow down ticks. If you know of one, see if you can find code for it. If not, it may not be possible.
August 5, 20196 yr Author Thanks for answer ! I managed to scan for normal blocks and so speeding up those that implements IGrowable / Iplantable which is nice ! But I can't figure how to scan for entities, tried to find some exemples online but didn't found much, do you have any ?
August 5, 20196 yr Well, Industrial Foregoing is open source: https://github.com/Buuz135/Industrial-Foregoing. I'm sure that mod does a lot of block/entity scanning. It seems like it'd be a pretty good reference. After just a quick glance, it looks like they're using world.getEntitiesWithinAABB(): https://github.com/Buuz135/Industrial-Foregoing/blob/master/src/main/java/com/buuz135/industrial/tile/mob/MobDetectorTile.java
August 5, 20196 yr Author I don't uderstand how to use getEntitiesWithinAABB(), the industrial forgegoing part you sent to me is about living entities which seems to be quite different to scan, i'd like to get TileEntities
August 5, 20196 yr Oh, you said "entities", so I thought that's what you meant. Scanning for tile entities is easy. Just loop through every possible x, y, z coordinate in range and call world.getTileEntity(BlockPos(x, y, z)), which will just return NULL if there isn't a tile entity for that block. Here's the loop that Industrial Foregoing uses: (https://github.com/Buuz135/Industrial-Foregoing/blob/master/src/main/java/com/buuz135/industrial/utils/BlockUtils.java) public static List<BlockPos> getBlockPosInAABB(AxisAlignedBB axisAlignedBB) { List<BlockPos> blocks = new ArrayList<BlockPos>(); for (double y = axisAlignedBB.minY; y < axisAlignedBB.maxY; ++y) { for (double x = axisAlignedBB.minX; x < axisAlignedBB.maxX; ++x) { for (double z = axisAlignedBB.minZ; z < axisAlignedBB.maxZ; ++z) { blocks.add(new BlockPos(x, y, z)); } } } return blocks; } This method just builds a List of BlockPos for every possible (x,y,z) coordinate in range, but you could easily alter it to something like this: public static List<TileEntity> getTileEntityInAABB(World world, int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { List<TileEntity> telist = new ArrayList<TileEntity>(); for (double y = minY; y < maxY; ++y) { for (double x = minX; x < maxX; ++x) { for (double z = minZ; z < maxZ; ++z) { TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te != null) { telist.add(te); } } } } return telist; } I've simplified the parameters to minX, maxX, etc, but you'd probably want to use some sort of bounding box data structure like IF does. I also free-handed this code, so there may be syntax errors, but the premise is all there. Edited August 5, 20196 yr by jaminv
August 5, 20196 yr Author Yes sorry. Minecraft furnace are tile entities right ? Cause I tried what you sent and all I get is an empty list so I probably miss implemented it..
August 5, 20196 yr Yes. Anything that has an inventory has to be a tile entity. Make sure you've got your range right. Make sure minX is less than maxX, minY is less than maxY, and minZ is less than maxZ, otherwise one of the loops will end without actually ever starting. That's the advantage of having a bounding box class. You can just feed it two BlockPos objects and have it sort out which of the X values is min or max, etc.
August 5, 20196 yr Author @Override public void updateTick(World world, BlockPos pos, IBlockState state, Random rand){ if(!world.isRemote){ this.growthBoost(world, pos, state); this.getTileEntityInAABB(world, -10,10,-10,10,-10,10); } } public static List<TileEntity> getTileEntityInAABB(World world, int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { List<TileEntity> telist = new ArrayList<TileEntity>(); for (double y = minY; y < maxY; ++y) { for (double x = minX; x < maxX; ++x) { for (double z = minZ; z < maxZ; ++z) { TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te != null) { telist.add(te); } } } } System.out.println("test---"+telist); return telist; } So that's what i have so far, tried some printing but it seems that i get an empty list
August 5, 20196 yr Change the for() loops to "y <= maxY", "x <= maxX", "z <= maxZ". I'm not sure why IF has it exclude the max values. If your furnace was at X=10, Y=10, or Z=10, it would have been excluded. Besides that, I don't see anything wrong there. Maybe narrow it down to the exact block coordinates of the furnace and trace through it?
August 5, 20196 yr Author I changed for "<= " but still nothing even by surrounding the block with furnace ?
August 5, 20196 yr Are you sure your Y value is between -10 and 10? Y=-10 doesn't actually make any sense. If you're still having trouble, open the F3 screen and point at your furnace and post a screenshot.
August 5, 20196 yr I think you might be thinking in relative coordinates, but world.getTileEntity() is in absolute coordinate. If you wanted relative coordinates, you'd need to feed in a reference BlockPos into the function: public static List<TileEntity> getTileEntityInAABB(World world, BlockPos relativeTo, int rangeX, int rangeY, int rangeZ) { List<TileEntity> telist = new ArrayList<TileEntity>(); for (double y = relativeTo.getY() - rangeY; y <= relativeTo.getY() + rangeY; ++y) { for (double x = relativeTo.getX() - rangeX; x <= relativeTo.getX() + rangeX; ++x) { for (double z = relativeTo.getZ() - rangeZ; z < relativeTo.getZ() + rangeZ; ++z) { TileEntity te = world.getTileEntity(new BlockPos(x, y, z)); if (te != null) { telist.add(te); } } } } return telist; }
August 5, 20196 yr Where it says "Looking at:" (third line of text from the bottom), those are the coordinates for your furnace. X=168, Y=69, Z=239. That is not within the range X=[-10,10], Y=[-10,10], Z=[-10,10]. You probably want to use the code I posted that deals in relative coordinates, but I can't hold your hand through explaining how the MC coordinate system works.
August 6, 20196 yr Author Oh wow .. that was really dumb .. Some other things I tried might have worked if I knew what kind of coordinates I was using. Sorry for that and once again thanks, my block is doing exactly what I wanted thanks to you.
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.