Jump to content

Creating a tick modifier AoE 1.12.2


Temps Pi

Recommended Posts

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 by Temps Pi
Link to comment
Share on other sites

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.

 



 

  • Thanks 1
Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by jaminv
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

    @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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;
    }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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