
Viperdream
Members-
Posts
9 -
Joined
-
Last visited
Everything posted by Viperdream
-
I've changed those things, it still isn't working. The valueOf method still says it cannot resolve the method: public static class Storage implements Capability.IStorage<IRunicPower> { @Nullable @Override public INBT writeNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side) { return FloatNBT.valueOf(instance.getPower()); } @Override public void readNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side, INBT nbt) { instance.set(((FloatNBT) nbt).getFloat()); } }
-
I've been trying to create my own capability. However, when I try to write the storage class I'm getting an error. Whenever I use the writeNBT funciton and try to write my own float value to the FloatNBT object, it gives the error that FloatNBT has private access. I understand that this prevents me from writing my own value on the FloatNBT, but I haven't found a way around it. I've checked various tutorials and other people's code (that's also from 1.15.2). Using "FloatNBT.valueOf(instance.getPower());" doesn't work either (yet I've seen it working in other mods), since it can't resolve the symbol. This is my instance class: package com.github.viperdream.vnecro.capability.instances; import com.github.viperdream.vnecro.capability.interfaces.IRunicPower; import net.minecraft.nbt.FloatNBT; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import javax.annotation.Nullable; public class RunicPower implements IRunicPower { private float rp = 0.0F; public void consume(float points) { this.rp -= points; if(this.rp < 0.0F) this.rp = 0.0F; } public void fill(float points) { this.rp += points; } public void set(float points) { this.rp = points; } public float getPower() { return this.rp; } public static class Storage implements Capability.IStorage<IRunicPower> { @Nullable @Override public INBT writeNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side) { return new FloatNBT.valueOf(instance.getPower()); } @Override public void readNBT(Capability<IRunicPower> capability, IRunicPower instance, Direction side, INBT nbt) { instance.set(((FloatNBT) nbt).getInt()); } } } Could someone please point me in the right direction? I have the feeling I'm missing something obvious, but I can't see it at the moment. Thanks in advance!
-
This works like a charm, thanks a ton. If anyone is wondering how my code looks like, here it is /**This saves the ChunkEcoValues object to the NBTTagCompound to its corresponding chunk */ @SubscribeEvent public void onChunkDataSave(ChunkDataEvent.Save e){ NBTTagCompound nbt = e.getData(); Chunk c = e.getChunk(); ChunkEcoValues cv = Pollution.pollutedChunks.get(c); if(cv.getPassiveFactor() == null){ cv.initDefault(c); } nbt.setDouble(passiveFactor, cv.getPassiveFactor()); nbt.setDouble(originalPassive, cv.getActivePollution()); nbt.setDouble(activePollution, cv.getActivePollution()); nbt.setDouble(activeEco, cv.getActiveEco()); } /**This loads the ChunkEcoValues from the NBTTagCompound from the chunk */ @SubscribeEvent public void onChunkDataLoad(ChunkDataEvent.Load e){ if(!Pollution.pollutedChunks.containsKey(e.getChunk())){ Chunk c = e.getChunk(); NBTTagCompound nbt = e.getData(); ChunkEcoValues cv = new ChunkEcoValues(); cv.setChunk(c); cv.setPassiveFactor(nbt.getDouble(passiveFactor)); cv.setOriginalPassive(nbt.getDouble(originalPassive)); cv.setActivePollution(nbt.getDouble(activePollution)); cv.setActiveEco(nbt.getDouble(activeEco)); Pollution.pollutedChunks.put(c, cv); }else{ Chunk c = e.getChunk(); ChunkEcoValues cv; cv.initDefault(c); Pollution.pollutedChunks.put(c, cv); } }
-
Ok, if I understand this right. Should something like this work? @SubscribeEvent public void onChunkSave(ChunkDataEvent.Save e){ NBTTagCompound nbt = e.getData(); nbt.setDouble("value1", 1); nbt.setDouble("val2", 1); } So once the event launches I can get the NBTTagCompound from the chunk and then I simply add my values to the NBT tag? Will it save automatically with the chunk without me having to do anything else? And to get the values I simply use the ChunkDataEvent.Load and call upon the NBTTagCompound to find my values? Sorry for all the questions, you've been a great help so far. I've been at this for a day now trying out various methods.
-
Ok, that should work. Just a few questions. How do I make the ChunkPos the key of the NBTTag? Since it requires a string? Or do I somehow use the hashcode I can generate with that? Also, I tried out a different method which seems to be working partly. But for some reason the NBT data doesn't persist when I restart Minecraft. I've based myself on your Questology mod for the WorldSavedData extension class (thanks for that). public class ChunkEcoValuesData extends WorldSavedData{ private static final String IDENTIFIER = EcoBalance.MODID; private static String coords; private String jsonCv; public ChunkEcoValuesData(){ super(IDENTIFIER); } public ChunkEcoValuesData(String id){ super(id); } @Override public void readFromNBT(NBTTagCompound nbt) { jsonCv = nbt.getString(coords); } @Override public void writeToNBT(NBTTagCompound nbt) { System.out.println("[EcoBalance]: Saving to NBT..."); nbt.setString(coords, jsonCv); } public String getJson(){ System.out.println("Getting this json string: " + jsonCv); return jsonCv; } public void setJson(String json){ this.jsonCv = json; System.out.println("Setting this json string: " + jsonCv); markDirty(); } public void setCoords(String nCoords){ coords = nCoords; } public static ChunkEcoValuesData get (World w, String chunkCoords){ coords = chunkCoords; System.out.println("[EcoBalance] Getting data with coords: " + coords); ChunkEcoValuesData data = (ChunkEcoValuesData)w.perWorldStorage.loadData(ChunkEcoValuesData.class, IDENTIFIER); if(data == null){ System.out.println("[EcoBalance] Data is null "); data = new ChunkEcoValuesData(coords); w.perWorldStorage.setData(IDENTIFIER, data); } return data; } } I'm a bit clueless here, because every time I set the value I mark it dirty. Shouldn't it save it then? I can see in the console that it passes the correct variable through, but yet it returns null when I restart Minecraft.
-
Hi I'm trying to save a custom object, holding only primitive values, to a chunk. It adds more information to the chunk that I need for my mod. The values are simple numbers that show the amount of player made pollution. What I did was putting all the chunks into a hashmap (the chunk's coordinates converted to a string and my custom object as a value), then convert that hashmap to json and save it with NBT on the world map. I soon found out that the string is simply too long to store and it won't load the objects. I also think this way is a bit too devious and that there must be an easier way. I'm looking for a way so I can add a value to a chunk, this would be the best manner ,I think, and also save it to the chunk in the same way chunks are saved. Or is there an easier way to save the hashmap I have to NBT? I'm just not entirely sure how to go at this. If anyone could point me in the right direction, that'd be great. Thanks
-
[1.7.10] How to see what sort of block I placed?
Viperdream replied to Viperdream's topic in Modder Support
Does that work on 1.7.10? Because I can't find that method. I did find out how to get an ID though, but it also returns an array after the ID (61[15:56:56]), these aren't coördinates I checked it. Anyone knows what that means? EDIT: I'm an idiot, it's the time -
[1.7.10] How to see what sort of block I placed?
Viperdream replied to Viperdream's topic in Modder Support
Ah that's a shame, any place I can find the answer for this? The mods I want to combine with my mod aren't updated to 1.8+ sadly. -
Hi I've just started modding with Forge. I have experience with Bukkit, but this seems a lot different to me. I'm trying to find out how to see which block I just placed with the event 'BlockEvent.PlaceEvent'. I want this so I can check which block I placed so I have to log it or not. Furnaces in this case. I've been searching everywhere, but I can't find a clear answer. Can I get an ID from the block event? Or can I find it out with the metadata from the block? But I'm a bit confused with the metadata, because if I do e.blockMetaData it just returns an Integer. And I have no reference to what this means. A bit of a follow up question for this. Can I get the tile entity from this block? I want to check later on whether the furnace is burning (with isBurning()). Sorry if this has been asked before, but I couldn't find any answers. If anyone could help me out, that'd be great. Thanks!