Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

KGS

Members
  • Joined

  • Last visited

Everything posted by KGS

  1. diesieben07: My ChunkLocation has both hashCode and equals properly implemented. I don't have the code at hand at the moment, but hashCode implementation is based on the one used in Effective Java. The Multiset looks interesting. This is probably going to be my approach. Stopper doesn't have a tile entity, but your solution proposal is interesting.
  2. So I have a block called a Stopper that whenever it is placed registers its own position within some datastructure called the Tracker. The tracker itself keeps track of the number of stoppers in a chunk. When a Stopper is placed, the Stopper tells the Tracker where the Stopper was placed. The Tracker takes the block coordinates AND the worldID and converts them to chunk coordinates, and then sticks the chunk coordinates and the world id in a custom class (ChunkLocation) which is used as a key in a hash table. The key is used to identify an integer in the Tracker's hash table representing how many stoppers are currently in a particular chunk in a particular dimension. The reason for this is I want some way to quickly look up whether or not there is a stopper in any particular chunk. I suspect this is not the ideal way to keep track of this. // This code is in the Stopper public void onBlockAdded(World world, int x, int y, int z) { KGBlocks.tracker.addStopper(x, y, z, world.provider.dimensionId); } // This is the code in the Tracker public void addStopper(int x, int y, int z, int w) { ChunkLocation t = getLocation(x, y, z, w); // This creates a new ChunkLocation from the given coordinates. if (chunk.containsKey(t)) { int counter = chunk.get(t); counter++; chunk.put(t, counter); } else{ chunk.put(t, 1); } this.markDirty(); } The bug that occurs is that if I place multiple blocks in quick succession, it seems to register more Stoppers than I place. I get duplicate updates to the hash table. The integer sometimes updates twice instead of once. I currently don't have code to remove stoppers from the tracker, but that will be added when I have this code working. Edit: Maybe it would be safer to store lists instead of integers, and then make the lists contain coordinates for stoppers within a chunk. Checking whether or not there is a stopper within a chunk would then only require checking whether or not that list exists within the tracker OR if the list length is zero.
  3. You were correct! The multiple triggers caused the event to overwrite the instance. I added a null check in the method that creates it, so that if the instance is already created, it doesn't make a new one, it just returns the old one. Now the save/load trigger properly. They're just dummy methods now, though. All they do is println a message indicating it's being called. I'll see if I can make it write a list of coordinates to the NBT properly, and then read that list.
  4. I can't get this to work. I have an event listener now that listens to WorldEvent.Load In it, I call a static method in the Tracker class which creates a new Tracker: public static Tracker forWorld(World world) { MapStorage storage = world.mapStorage; Tracker result = (Tracker)storage.loadData(Tracker.class, key); if (result == null) { result = new Tracker(key); storage.setData(key, result); } instance = result; return result; } The tracker also has a read from nbt and write to nbt method, but they seem to never get called (I don't get any output from them, i have println() calls inside them for "debug" purposes. I use setDirty() inside the tracker whenever I add anything to it. The curious thing too, which makes very little sense, is that the event triggers four times when starting up. If it did it twice I'd guess server and client side. But four times? That makes no sense whatsoever.
  5. This might be helpful: http://stackoverflow.com/questions/9600801/evenly-distributing-n-points-on-a-sphere
  6. Thanks. I'll try using WorldEvent.Load and see how it works.
  7. How's that possible? How does it even know my class exists if I have not referenced it anywhere? Every other mod related thing I've written so far has required manual registration somewhere, with the exception of the mod itself which is detected with the @ tag things and reflection. Right now I have a tracker class extending WorldSavedData. It has NBT read and write methods but it's not doing anything, because it's not registered anywhere. Registering it using the method I mentioned in the first post does not work because it requires a world. I tried a "hack" where I got a world from a world provider from DimensionManager or something like that, but got an NPE.
  8. So have a datastructure that I need to access from events. This datastructure needs to be persistent. It will be saved to the nbt when minecraft is shut down, and it will be loaded from the nbt when minecraft starts. I have found instructions as how to make it persistent: I make it extend WorldSavedData and "register" it as follows: world.mapStorage.loadData(Datastructure.class, "mydatastructure"); (obviously doing a null check and otherwise generating a fresh entry) The problem is that I don't know where I should do this call, because I don't have access to a world from within my mod's init function.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.