Jump to content

effect blocks within a set range of another block?


jamiemac262

Recommended Posts

hi, i haven't got a clue how to do this so i wonder if somebody could help me out?

 

i'm creating a mod that's kind of a cross between factions and starcraft

 

i have a block called Creep Generator (which just now doesn't have anything to do with factions or clans etc..... i will probably have to ask about that as well later haha)

 

i'm going to refine this later (to stop it replacing ores) but for now

 

i need the creep generator to replace every block within a certain radius of the creep generator..... i want it to affect all the solid/liquid blocks from bedrock to world height within this radius. right now the block will affect the area immediately surrounding it and no further than 1 block away

 

 

can anybody help me out?

Link to comment
Share on other sites

This is a tad tricky.  But I think it can be done.

 

Step 1: the block that acts as the anchor is going to be a unique block.  One per effected zone.

Step 2: the anchor pillar.  These blocks will act like the anchor, but will only spread up/down as required.  Might need a second one that has Material.air.  Might be able to use the first block, but with metadata to get the effect, but sometimes its easier to just use a new block ID

Step 3: the infected blocks.  These will be ever block in the infected area, we will use metadata to figure out how far away from the anchors they are.  If we need to infect through air, we'd need a separate block unless your radius is <= 8

 

All blocks will receive random updates.

 

Step 4: Anchor block replaces the block above it and the block below it with Pillar blocks, depending on material type.  You've got this happening already, sort of.  Next replace all four horizonally adjacent blocks with Infected blocks, set metadata to maximum radius value.  It should do this on blockAddedToWorld.

Step 5: Pillar blocks will perform the above step as well, be sure to check that you're not replacing other Pillar or Anchor blocks!

Step 6: Infected blocks will check all adjacent blocks for self, and find hightest metadata.  It will then set itself to that value -1 and replace all not-self blocks with itself, at another -1 metadata.

 

If you want the anchor to be broken and let things heal back to "normal" then:

Step 6 is important, as if the Infected block's metadata is 0, then it should replace itself with stone/air.

For the anchor pillars, if during an update it is not adjacent to either a pillar or a anchor on BOTH top and bottom, replace itself with stone/air.

 

You'll probably have to experiment with stuff one step at a time until its behaving properly.

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.

Link to comment
Share on other sites

Block metadata is just a second value in addition to block ID.  It's passed to almost every block function.

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.

Link to comment
Share on other sites

Also, to better explain how I arrived at the 3-block solution:

 

1) You want a block to spread: ok, block replaces its neighbors with itself.

2) You want it to spread in a range: ok, so there's something special about the central block (think redstone torch vs. redstone wire).

3) You want the "center" to actually be a line from bedrock to world ceiling: ok, so now we need two types of central block: the one that starts everything and the 'infinite' vertical line blocks.  These can be the same block if it's a permanent effect, but in either case it's fundamentally different than the actual spreading block, as it provides the "power source" as it were.

4) You also want to spread through air in some manner in order to effect blocks in the sky.  This will likely end up being duplicating each of the block types that covers the former 3, but with a different material, collision hull, etc. etc. (normally you'd do this with metadata, but Material can't be altered, and if you want other mod blocks to treat these blocks as if they are air, then you'd need a separate block class).  That would leave you with 6 different blocks.

 

Now that we've split the effect down into specific block concepts we can work on each one individually.

 

Under the assumption that we don't want the effect to occur instantly, we should use the onUpdate() function, so that when an update occurs, spread advances 1 block.  The exception is our central axis that is not the origin anchor point: due to the fact that we can't use metadata to infer connection back to the anchor, we need to add all of them at once.  We can either do this when the anchor is placed (and just loop through all blocks at that XZ location) or use an "instant spread" of when each of these "pillar" blocks is added to the world.

 

That puts us in a position where we have a Finite State Machine for all of our blocks, where the state only changes in the onUpdate as defined by that function, based only on the block's surroundings and its current state.  And that's easy, provided that the number of states is less than our metadata limitation (16). :)

 

We can also get tricky, if we need 17-32 states, we can just use a second block, with the same texture, and switch from Block1(state 16) to Block2(state 1) and back (or any other state-to-state), as needed.  This gets complicated though, so for most effects, try to stick within the 16-state limitation.

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.

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.