Jump to content

Recommended Posts

Posted

Hey there, so I'm trying to find a way to detect 2 quartz blocks and a gold block on top, on each side.. However, I don't know how to get started. I could do EnumFacing.Horizontals , however finding the two blocks above the block that is detected by the forloop is where I'm stuck..

 

What would be the best way for the TE to detect if there is a 3 high structure (with the top of them being gold blocks) on each side.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

pos.offset(facing).up()?

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.

Posted

Loop over the EnumFacing horizontal values.  That's the "facing" in my code above.

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.

Posted

Would something like this work?

public void lookForBlocks(){
        for(EnumFacing facing : EnumFacing.HORIZONTALS) {
            BlockPos quartzPos = pos.offset(facing, 5);
            BlockPos quartzPosUp = pos.offset(facing, 5).up();
            BlockPos goldPos = pos.offset(facing, 5).up(2);

            IBlockState quartz = world.getBlockState(quartzPos);
            IBlockState quartzTop = world.getBlockState(quartzPosUp);
            IBlockState gold = world.getBlockState(goldPos);

            if((quartz.getBlock()) == Blocks.QUARTZ_BLOCK && quartzTop.getBlock() == Blocks.QUARTZ_BLOCK){
                if(gold.getBlock() == Blocks.GOLD_BLOCK) {

                }
            }
        }
    }

 

Now how would I make sure all four sides are present?

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

That if statement will detect if that side is properly constructed.

 

Check if one doesn't exist rather than if they all exist.

 

You'll need a boolean and set the boolean to false if a side fails.

 

Or you can use a counter to count successes and check if successes == 4.

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.

Posted

If i use a counter, then everytime the forloop runs, which is every tick, the counter will increase by one again and again even if one side is there.

Think Local not global.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

i do something like this but was because i do some complicated things whit mi mod in that time

 

all mi structures was designed to occupy only one chunk and set the block whit the tile entity at the center of the chunk at y=0

 

so just check if at the center of the chunk is one of mi structure blocks and then also have the facing for the structure

 

but this obviously wont works for vanilla or other mods structures

 

Posted

It will still increment every tick

public void update() {
    structureCheck();
}

public int structureCheck() {
    int structureCount = 0;
    for (int i = 0; i < 10; i++) {
        structureCount++;
    }
    return structureCount;
}

What is the value of structureCheck every time it is called?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted


    public void lookForBlocks(){
        int count = 0;
        System.out.println(count);
        for(EnumFacing facing : EnumFacing.HORIZONTALS) {
            BlockPos quartzPos = pos.offset(facing, 5);
            BlockPos quartzPosUp = pos.offset(facing, 5).up();
            BlockPos goldPos = pos.offset(facing, 5).up(2);

            IBlockState quartz = world.getBlockState(quartzPos);
            IBlockState quartzTop = world.getBlockState(quartzPosUp);
            IBlockState gold = world.getBlockState(goldPos);

            if((quartz.getBlock()) == Blocks.QUARTZ_BLOCK && quartzTop.getBlock() == Blocks.QUARTZ_BLOCK){
                System.out.println(facing);
                if(gold.getBlock() == Blocks.GOLD_BLOCK) {
                    System.out.println("structure on: " + facing + " is complete"); 
                    count++;
                }
            }
        }
    }

 

well your example will always make count = 0, because your setting it to 0 every time the update is called. like in my, the count never increases, even it the println prints.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

Is there a better way than this to iterate though nearby chunks than this?

 

    public List<Chunk> nearbyChunks(World world) {
        List<Chunk> list = new ArrayList<>();
        list.add(world.getChunkFromChunkCoords(world.getChunkFromBlockCoords(pos).getPos().chunkXPos, world.getChunkFromBlockCoords(pos).getPos().chunkZPos));
        list.add(world.getChunkFromChunkCoords(world.getChunkFromBlockCoords(pos).getPos().chunkXPos+1, world.getChunkFromBlockCoords(pos).getPos().chunkZPos+1));
        list.add(world.getChunkFromChunkCoords(world.getChunkFromBlockCoords(pos).getPos().chunkXPos-1, world.getChunkFromBlockCoords(pos).getPos().chunkZPos-1));
        list.add(world.getChunkFromChunkCoords(world.getChunkFromBlockCoords(pos).getPos().chunkXPos+1, world.getChunkFromBlockCoords(pos).getPos().chunkZPos-1));
        list.add(world.getChunkFromChunkCoords(world.getChunkFromBlockCoords(pos).getPos().chunkXPos-1, world.getChunkFromBlockCoords(pos).getPos().chunkZPos+1));

        return list;
    }

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

Why are you using World#getChunkFromChunkCoords and then to get the chunk coords you get the chunk from the block coords... Just use World#getChunkFromBlockCoords(BlockPos).

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Well because I'm getting the ones one next to, because ChunkPos are like: 0,1 1,0, correct? So adding one the the chunkpos will just shift over / up / down instead of adding 16.. atleast that was my thought process

Not quite adding 16, it is a bit shift. Tou are doing more processes the way you are doing it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

So what should I change it to?

int xCoord = (getPos().getX() >> 4) + 1;
int zCoord = (getPos().getZ() >> 4) + 1;
worldObj.getChunkFromChunkCoords(xCoord, zCoord);

This will get a chunk that is offset by one in the x and z (chunk)position.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.

Announcements



×
×
  • Create New...

Important Information

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