So, from which class would I create this set? presumably the event handler for the block?
Edit: also, how would this set be stored per world?
Use World Saved Data or World Capabilities to store per-world data. Depending on which system you use, the set should either be stored in the class that extends WorldSavedData or the class that implements the interface you've registered the capability for.
You can read more about these systems at the links in post #12.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So I need to create a class that extends WorldSavedData, then what? I assume the class creates a hash set thing, then you keep track of blocks placed and broken and edit the list as neccesary.
So I need to create a class that extends WorldSavedData, then what? I assume the class creates a hash set thing, then you keep track of blocks placed and broken and edit the list as neccesary.
Yes. The WorldSavedData class stores the Set<BlockPos> and read it from/writes it to NBT.
Whenever a block is added/removed, get the WorldSavedData for the World and add/remove the BlockPos from the Set. Whenever an entity is spawned, get the WorldSavedData for the World and iterate through the Set and check if any of the blocks at those positions can prevent the spawn.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Another question: how do I prevent the creation of duplicate lists? for example, if someone leaves a world with scarecrows in it and then joins it again and places more scarecrows, how do I prevent the mod from making a duplicate set?
Another question: how do I prevent the creation of duplicate lists? for example, if someone leaves a world with scarecrows in it and then joins it again and places more scarecrows, how do I prevent the mod from making a duplicate set?
The World Saved Data and World Capability systems both ensure that there's only one instance of your WorldSavedData or ICapabilityProvider class (and thus one instance of your capability interface) per World (dimension). The data is saved to and loaded from the disk with the world.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
oh, so I just WorldSavedData linkedListThing = new WorldSavedData()? I apologize if I am not comprehending, I work best when I have an example to work from, but I know you don't like giving examples, so I have been trying the best I can without asking for one.
You need to create a class that extends WorldSavedData and has a Set<BlockPos> field containing a LinkedHashSet<BlockPos>. When you want to access the Set<BlockPos>, get the instance of your WorldSavedData class from the World's MapStorage or create and store the instance in the MapStorage if it doesn't exist.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I use Foo#bar to refer to an instance field/method of Foo called bar. I use Foo.bar to refer to a static field/method.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
uh, ok? sure... Anyways, as I understand it, I need a class that extends WorldSavedDAata. then, I need two event handlers to track the placement and breaking of scarecrows. is that right?
uh, ok? sure... Anyways, as I understand it, I need a class that extends WorldSavedDAata. then, I need two event handlers to track the placement and breaking of scarecrows. is that right?
You do need a class that extends WorldSavedData; but you don't need event handlers to track the placement and breaking, simply override Block#onBlockAdded and Block#breakBlock to add/remove the block's position from the World's position set.
Note that this is designed to have a single instance active per server because it needs to record positions in every dimension. This isn't necessary for your scarecrows, which presumably only prevent mob spawns in the same dimension that they're placed in.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
yep, no cross dimensional scarecrows here. So, do I override those methods in the scarecrow block class?
Yes.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Alright, things seem to be working pretty well so far. I just want to check and make sure I am doing everything correctly now so I don't do something stupid that will bite me in the butt later. How does this look so far:
Remove the instance field and any references to it, as well as the clearInstance and save methods. They're not needed here, they were part of ensuring that there was only one instance per server.
Change the value of the NAME field to something descriptive that includes your mod ID, e.g. "sandbox:scarecrows". I also recommend renaming the class itself to something like ScarecrowTracking or ScarecrowPositions.
Make the scarecrowLocations field and the addScarecrow and removeScarecrow methods non-static. Each World will have an instance of Tracking, each instance needs its own set of locations.
As shown in the last code block of the documentation, you need to use World#getPerWorldStorage instead of World#loadItemData/World#getMapStorage. Your get method should look very similar to this example.
You can use NBTUtil.getPosFromTag and NBTUtil.createPosTag to easily read/write a BlockPos to/from a compound tag.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
In the example, what does IS_GLOBAL mean? The comments seem to suggest its a stand in for something. Is it used for identifying if the world is on the client or server?
In the example, what does IS_GLOBAL mean? The comments seem to suggest its a stand in for something. Is it used for identifying if the world is on the client or server?
IS_GLOBAL is whether you want the data to be saved per-map (true) or per-dimension (false). You want it saved per-dimension, so simplify the statement to only call world.getPerWorldStorage().
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
MapStorage#loadData was renamed to MapStorage#getOrLoadData.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Use World Saved Data or World Capabilities to store per-world data. Depending on which system you use, the set should either be stored in the class that extends WorldSavedData or the class that implements the interface you've registered the capability for.
You can read more about these systems at the links in post #12.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So I need to create a class that extends WorldSavedData, then what? I assume the class creates a hash set thing, then you keep track of blocks placed and broken and edit the list as neccesary.
My first mod =D
Yes. The WorldSavedData class stores the Set<BlockPos> and read it from/writes it to NBT.
Whenever a block is added/removed, get the WorldSavedData for the World and add/remove the BlockPos from the Set. Whenever an entity is spawned, get the WorldSavedData for the World and iterate through the Set and check if any of the blocks at those positions can prevent the spawn.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Another question: how do I prevent the creation of duplicate lists? for example, if someone leaves a world with scarecrows in it and then joins it again and places more scarecrows, how do I prevent the mod from making a duplicate set?
My first mod =D
The World Saved Data and World Capability systems both ensure that there's only one instance of your WorldSavedData or ICapabilityProvider class (and thus one instance of your capability interface) per World (dimension). The data is saved to and loaded from the disk with the world.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
oh, so I just WorldSavedData linkedListThing = new WorldSavedData()? I apologize if I am not comprehending, I work best when I have an example to work from, but I know you don't like giving examples, so I have been trying the best I can without asking for one.
My first mod =D
You need to create a class that extends WorldSavedData and has a Set<BlockPos> field containing a LinkedHashSet<BlockPos>. When you want to access the Set<BlockPos>, get the instance of your WorldSavedData class from the World's MapStorage or create and store the instance in the MapStorage if it doesn't exist.
The documentation has an example of this.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
does # mean . ?
My first mod =D
I use Foo#bar to refer to an instance field/method of Foo called bar. I use Foo.bar to refer to a static field/method.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
uh, ok? sure... Anyways, as I understand it, I need a class that extends WorldSavedDAata. then, I need two event handlers to track the placement and breaking of scarecrows. is that right?
My first mod =D
ooh, this looks useful! I'll need time to study it, but it looks like almost just what I need.
My first mod =D
You do need a class that extends WorldSavedData; but you don't need event handlers to track the placement and breaking, simply override Block#onBlockAdded and Block#breakBlock to add/remove the block's position from the World's position set.
Note that this is designed to have a single instance active per server because it needs to record positions in every dimension. This isn't necessary for your scarecrows, which presumably only prevent mob spawns in the same dimension that they're placed in.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
yep, no cross dimensional scarecrows here. So, do I override those methods in the scarecrow block class?
My first mod =D
Yes.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Alright, things seem to be working pretty well so far. I just want to check and make sure I am doing everything correctly now so I don't do something stupid that will bite me in the butt later. How does this look so far:
The tracking class:
http://pastebin.com/kM9XmsAQ
The block class:
http://pastebin.com/g39PT39v
No event handler yet, I wanted to get the world data thing right first. Baby steps!
My first mod =D
Remove the instance field and any references to it, as well as the clearInstance and save methods. They're not needed here, they were part of ensuring that there was only one instance per server.
Change the value of the NAME field to something descriptive that includes your mod ID, e.g. "sandbox:scarecrows". I also recommend renaming the class itself to something like ScarecrowTracking or ScarecrowPositions.
Make the scarecrowLocations field and the addScarecrow and removeScarecrow methods non-static. Each World will have an instance of Tracking, each instance needs its own set of locations.
As shown in the last code block of the documentation, you need to use World#getPerWorldStorage instead of World#loadItemData/World#getMapStorage. Your get method should look very similar to this example.
You can use NBTUtil.getPosFromTag and NBTUtil.createPosTag to easily read/write a BlockPos to/from a compound tag.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
In the example, what does IS_GLOBAL mean? The comments seem to suggest its a stand in for something. Is it used for identifying if the world is on the client or server?
Also, this line wont compile:
ScarecrowTracking instance = (ScarecrowTracking)storage.loadData(ScarecrowTracking.class, NAME);
My first mod =D
IS_GLOBAL is whether you want the data to be saved per-map (true) or per-dimension (false). You want it saved per-dimension, so simplify the statement to only call world.getPerWorldStorage().
What's the error?
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Eclipse underlines loadData in red and says this about it:
The method loadData(Class<ScarecrowTracking>, String) is undefined for the type MapStorage
My first mod =D
MapStorage#loadData was renamed to MapStorage#getOrLoadData.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.