Jump to content

Thaliviel

Forge Modder
  • Posts

    33
  • Joined

  • Last visited

Everything posted by Thaliviel

  1. My old get method was this: public static MBSave get(World world) { MBSave handler = (MBSave) world.loadItemData(MBSave.class, DATA_NAME); if(handler==null) { handler = new MBSave(); world.setItemData(DATA_NAME, handler); } return handler; } And in World.class there is public WorldSavedData loadItemData(Class par1Class, String par2Str) { return this.mapStorage.loadData(par1Class, par2Str); } But instead of mapStorage (global) I need perWorldStorage. So my new get method is: public static MBSave get(World world) { MBSave handler = (MBSave) world.perWorldStorage.loadData(MBSave.class, DATA_NAME); if(handler==null) { handler = new MBSave(); world.perWorldStorage.setData(DATA_NAME, handler); } return handler; } Is that right? If it is, then I'm a bit proud that I'm understanding Java and Minecraft and Forge a little more than when I started this thread At least it is working when I test it with these changes.
  2. Wait, something's not right. public void LSECheckSpawn(LivingSpawnEvent.CheckSpawn event) { List<Position> mbBlockList = new ArrayList(); MBSave mbdata = get(event.world); mbBlockList = mbdata.getList(); I'm retrieving the mbdata from a certain world (dimension). So it SHOULD be right the way it is now? I'm confused...
  3. Thank you!! An instance of "world" is a dimension, like overworld, or nether, right? Or is it the whole world containing all dimensions? So right now my BlockList is global, which means spawns will be denied in all dimensions. So when I put a MonsterBlocker-Block in the overworld, spawns will be denied in same area of the nether, too, although there is no MB-Block in the nether. Did I understand this right? If that's the case, I somehow need to use World#perWorldStorage(), and I think that I'll be able to do that on my own - so please just confirm if I'm right, or correct me if I'm wrong.
  4. I've been googling for some time how to set the map generator, but I didn't really find anything useful. Could someone give me a slight hint how to get the map generator of Minecraft 1.6.4 and how to apply that map generator to the overworld (so that even when I update Minecraft to the newest version, the default overworld will use the old map generator) Adding the new dimension can wait, I'm not in a hurry to add that.
  5. There is still one thing bothering me: In the documentation http://mcforge.readthedocs.org/en/latest/datastorage/worldsaveddata/ it says: However, I didn't use getMapStorage or getPerWorldStorage... So is my BlockList stored per dimension or globally?
  6. Okay, nevermind. I was dumb to assume that setLightValue(2F) would be brighter than setLightValue(1F). The difference was like this: and So now that I use 1F, the problem is fixed. Sorry for my noobishness
  7. Okay, so adding a glow/brightness is quite difficult, right? There's no method similar to setLightValue(), where you can just set a value. There is getBlockBrightness(), but that doesn't seem to help... So I have to create a renderer and set the brightness with a tesselator, if I'm not mistaken? Or is there an easier method? ____ Basically, I just want to make the block look like it recieves light from a torch on every side. Or something like that.
  8. One quick question: My block gives off light, but the block itself is rather dull, even if I use a bright texture. How can I add a glowing effect to the block?
  9. I played one year from 2013 to 2014. Now I'm restarting... or at least I'm trying to restart Anyway, it's working!! Holy mackerel I fixed the breakBlock() method and switched y/z in LSECheckSpawn(). I'll do some more testing, but I think it works perfectly.
  10. WAIT y is height? x and z is lateral movement? That is... unexpected. You'd think intuitionally that z is height... grmbl
  11. Well, that works. No big surprise. When I deny every spawn, then no mobs are spawning at all. Furthermore, when I load a world where I placed my MB-Block, the system print "Spawn Denied" works. So I guess saving/loading is working correctly, too. Could there be a problem when I compare Int and Float? posBlock.x - RANGE_SIDE < event.x Int - Int < Float Or could there be a problem when getting the BlockList, so that sometimes it won't fetch the list correctly? I'll try to figure that out by using system messages. Right now I detected the first problem: When I remove a MB-Block, it isn't removed from the list.
  12. Interesting, so that's why a zombie pigman managed to come into my overworld two days ago Anyway, I'm almost done. The mod is running and System.out.println("Spawn Denied"); is printing, so theoretically it should work. However, there are still monsters that spawn next to these blocks, and I tried to debug it for several hours without success... EventHandler package com.monsterBlocker; import java.util.ArrayList; import java.util.List; import net.minecraft.world.World; import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.event.world.WorldEvent; public class MBEventHandler { //public List<Position> mbBlockList = new ArrayList(); public static final String DATA_NAME = MonsterBlocker.MODID + "_BlockList"; private static final int RANGE_SIDE = 50; private static final int RANGE_UP = 50; private static final int RANGE_DOWN = 10; public static MBSave get(World world) { MBSave handler = (MBSave) world.loadItemData(MBSave.class, DATA_NAME); if(handler==null) { handler = new MBSave(); world.setItemData(DATA_NAME, handler); } return handler; } @ForgeSubscribe //1.6.4 public void LSECheckSpawn(LivingSpawnEvent.CheckSpawn event) { List<Position> mbBlockList = new ArrayList(); MBSave mbdata = get(event.world); mbBlockList = mbdata.getList(); for (int i=0; i < mbBlockList.size(); ++i) { Position posBlock = mbBlockList.get(i); //Position posMonster = new Position((int) event.x, (int) event.y, (int) event.z); if ( (posBlock.x - RANGE_SIDE < event.x) && (event.x < posBlock.x + RANGE_SIDE) && (posBlock.y - RANGE_SIDE < event.y) && (event.y < posBlock.y + RANGE_SIDE) && (posBlock.z - RANGE_DOWN < event.z) && (event.z < posBlock.z + RANGE_UP) ) { event.setResult(Result.DENY); System.out.println("Spawn Denied"); return; } } } } SavedData package com.monsterBlocker; import java.util.ArrayList; import java.util.List; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; public class MBSave extends WorldSavedData { private static final String DATA_NAME = MonsterBlocker.MODID + "_BlockList"; public List<Position> mbBlockList = new ArrayList(); public MBSave() { super(DATA_NAME); } public MBSave(String s) { super(s); } public List<Position> getList() { return mbBlockList; } /*public static List<Position> get(World world) { List<Position> handler = (List<Position>) world.loadItemData(List.class, "MonsterBlocker_BlockList"); if(handler==null) { handler = new ArrayList(); world.setItemData("MonsterBlocker_BlockList", handler); } return handler; }*/ public void onMBBlockChange(List<Position> newMBBlockList) { mbBlockList = newMBBlockList; markDirty(); } public void addBlock(Position pos) { mbBlockList.add(pos); } @Override public void readFromNBT(NBTTagCompound nbt) { mbBlockList.clear(); NBTTagList nbttaglist = nbt.getTagList("mbBlockList"); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound posCompound = (NBTTagCompound) nbttaglist.tagAt(i); Position pos = new Position(posCompound.getInteger("x"), posCompound.getInteger("y"), posCompound.getInteger("z")); mbBlockList.add(pos); } } @Override public void writeToNBT(NBTTagCompound nbt) { NBTTagList nbttaglist = new NBTTagList(); nbt.setTag("mbBlockList", nbttaglist); for(int i = 0; i < mbBlockList.size(); i++) { NBTTagCompound compound = new NBTTagCompound(); Position pos = mbBlockList.get(i); compound.setInteger("x", pos.x); compound.setInteger("y", pos.y); compound.setInteger("z", pos.z); nbttaglist.appendTag(compound); } } } Block package com.monsterBlocker; import java.util.ArrayList; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class MBBlock extends Block { public MBBlock (int id) { super(id, Material.iron); this.setUnlocalizedName(MonsterBlocker.mbBlock_unlocalizedName); this.setCreativeTab(CreativeTabs.tabBlock); this.setHardness(5F); this.setResistance(15F); this.setStepSound(Block.soundMetalFootstep); this.setLightValue(2F); } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister icon) { blockIcon = icon.registerIcon(MonsterBlocker.AID + ":" + "monsterBlocker"); } @Override public void onBlockAdded(World world, int x, int y, int z) { Position pos = new Position(x, y, z); List<Position> mbBlockList = new ArrayList(); MBSave mbdata = MBEventHandler.get(world); mbBlockList = mbdata.getList(); mbBlockList.add(pos); mbdata.onMBBlockChange(mbBlockList); //System.out.println("I Added"); } @Override public void breakBlock(World world, int x, int y, int z, int oldBlockID, int oldMetadata) { Position pos = new Position(x, y, z); List<Position> mbBlockList = new ArrayList(); MBSave mbdata = MBEventHandler.get(world); mbBlockList = mbdata.getList(); mbBlockList.remove(pos); mbdata.onMBBlockChange(mbBlockList); } } And main file package com.monsterBlocker; import java.util.ArrayList; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = MonsterBlocker.MODID, name = MonsterBlocker.NAME, version = MonsterBlocker.VERSION) @NetworkMod( channels = {"MB"}, clientSideRequired = true, serverSideRequired = true ) public class MonsterBlocker { public static final String MODID = "MonsterBlocker"; public final static String AID = MODID.toLowerCase(); public final static String NAME = "Monster Blocker"; public static final String VERSION = "0.1"; public static final String DATA_NAME = MonsterBlocker.MODID + "_BlockList"; public static final String mbBlock_unlocalizedName = "monsterBlocker"; public static final String mbBlock_name = "Monster Blocker"; @SidedProxy( clientSide = "com.monsterBlocker.ClientProxy", serverSide = "com.monsterBlocker.CommonProxy" ) public static CommonProxy proxy; public static Block monsterBlocker; // The instance of your mod that Forge uses. @Instance(value = MonsterBlocker.MODID) public static MonsterBlocker instance; @EventHandler public static void preInit(FMLPreInitializationEvent event) { proxy.initRenderers(); proxy.initSounds(); monsterBlocker = new MBBlock(3009); GameRegistry.registerBlock(monsterBlocker, MonsterBlocker.mbBlock_name); LanguageRegistry.addName(monsterBlocker, MonsterBlocker.mbBlock_name); GameRegistry.addRecipe(new ItemStack(MonsterBlocker.monsterBlocker, 1), new Object[] { "BIB", "IGI", "BIB", 'G', Block.glowStone, 'I', Item.ingotGold, 'B', Item.blazePowder }); } @EventHandler public static void init ( FMLInitializationEvent event ) { MinecraftForge.EVENT_BUS.register(new MBEventHandler()); } } So if you could please help me one last time and get this mod running how it is supposed to, I'll be really grateful!
  13. Ah, that was my error in reasoning. So instead fetching the BlockList when a player joins a world, I have to fetch it every time I add/remove a MB-Block and every time the spawn is checked, because that depends on the world where the block is changed or the mob is spawning. And if I play in multiplayer, that may happen simultaneously in several dimensions. Okay, I will fix that issue. Thanks for the tip with the enhanced for loop. And I'm actually still using 1.6.4, that's my old setup when I stopped playing/modding in 2014. I'll update that when I'm ready for that.
  14. Okay, I'll break it up into several steps: 1) set the map generator for the overworld 2) create a new dimension that uses the map generator of Life in the Woods 3) create a portal
  15. Edit: Updated MBEventHandler (because I renamed MBBlockList to MBSave)
  16. I'm almost done. I have my EventHandler class, where I can set the range of the Monster Blocker, and which contains two methods for loading the data and one for checking whether the spawn should be denied or not. This class contains the mbBlockList which is used while playing. package com.monsterBlocker; import java.util.ArrayList; import java.util.List; import net.minecraft.world.World; import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.event.world.WorldEvent; public class MBEventHandler { public List<Position> mbBlockList = new ArrayList(); public static final String DATA_NAME = MonsterBlocker.MODID + "_BlockList"; private static final int RANGE_SIDE = 50; private static final int RANGE_UP = 50; private static final int RANGE_DOWN = 10; public static MBSave get(World world) { MBSave handler = (MBSave) world.loadItemData(MBSave.class, DATA_NAME); if(handler==null) { handler = new MBSave(); world.setItemData(DATA_NAME, handler); } return handler; } @ForgeSubscribe //1.6.4 public void onWorldEventLoad(WorldEvent.Load event) { MBBlockList mbdata = get(event.world); mbBlockList = mbdata.getList(); } @ForgeSubscribe public void LSECheckSpawn(LivingSpawnEvent.CheckSpawn event) { for (int i=0; i < mbBlockList.size(); ++i) { Position posBlock = mbBlockList.get(i); if ( (posBlock.x - RANGE_SIDE < event.x) && (event.x < posBlock.x + RANGE_SIDE) && (posBlock.y - RANGE_SIDE < event.y) && (event.y < posBlock.y + RANGE_SIDE) && (posBlock.z - RANGE_DOWN < event.z) && (event.z < posBlock.z + RANGE_UP) ) { event.setResult(Result.DENY); System.out.println("Spawn Denied"); return; } } } } So the next thing to do is when a player adds a MB-Block, the mbBlockList should be updated (in the MBEventHandler) and the new mbBlockList should be sent to MBSave (extends WorldSavedData) and marked dirty. However, when I write this: public class MBBlock extends Block { @Override public void onBlockAdded(World world, int x, int y, int z) { Position pos = new Position(x, y, z); MBEventHandler.mbBlockList.add(pos); MBSave.onMBBlockChange(MBEventHandler.mbBlockList); } an error occurs: "Cannot make a static reference to the non-static field MBEventHandler.mbBlockList" How can I solve this? I'm not sure what happens when I make that static...
  17. Okay, I'm finally getting close - thanks to your help! The identifier - is that the DATA_NAME of my extended WorldSavedData? public class MBBlockList extends WorldSavedData { private static final String DATA_NAME = MonsterBlocker.MODID + "_BlockList"; public List<Position> mbBlockList = new ArrayList(); public MBBlockList() { super(DATA_NAME); } The DATA_NAME is "MonsterBlocker_BlockList", so I added this method to my main mod file: public static MBBlockList get(World world) { MBBlockList handler = (MBBlockList) world.loadItemData(List.class, "MonsterBlocker_BlockList"); if(handler==null) { handler = new MBBlockList(); world.setItemData("MonsterBlocker_BlockList", handler); } return handler; } And I have a stub EventHandler: public class MBEventHandler { @ForgeSubscribe //1.6.4 public void onWorldEventLoad(WorldEvent.Load event) { MBBlockList test = MonsterBlocker.get(event.world); } } Is that okay so far? So I have to tell the EventHandler the world and it will return some... uh, Data of the type MBBlockList? Sorry, I'm having problems understanding these different concepts and I'm still learning. But I try my best!
  18. That depends on the range. If I set a range of 50 Blocks (in a cube-ish range around the block, not a sphere), each spawn will check 100*100*100 Blocks, which is 1 million blocks. And that is a bit too much... Storing the data to a small list and saving/loading the list is much more elegant, I think.
  19. Mmmmh... I think when the world is loading, right? If a player is changing dimensions, the new dimension will be loaded as world. And when a player logs into the game, the world will be loaded without triggering PlayerEvent.PlayerChangedDimensionEvent. So do I put WorldEvent.Load in my main mod file and use override? If the game automatically calls readFromNBT, how do I access the BlockList that was loaded?
  20. Do I use PlayerEvent.PlayerChangedDimensionEvent? Or WorldEvent.Load?
  21. Okay, the saving/loading starts looking good. The only thing missing is the initialization when a player spawns in a dimension. I try to call onMBInit() and return the ArrayList containing the loaded BlockList, but I'm not sure how to do that. Here is the full code: package com.monsterBlocker; import java.util.ArrayList; import java.util.List; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.WorldSavedData; public class MBBlockList extends WorldSavedData { private static final String DATA_NAME = MonsterBlocker.MODID + "_BlockList"; public List<Position> mbBlockList = new ArrayList(); public MBBlockList() { super(DATA_NAME); } public MBBlockList(String s) { super(s); } public List<Position> onMBInit() { readFromNBT(nbt); return mbBlockList; } public void onMBBlockChange(List<Position> newMBBlockList) { mbBlockList = newMBBlockList; markDirty(); } @Override public void readFromNBT(NBTTagCompound nbt) { mbBlockList.clear(); NBTTagList nbttaglist = nbt.getTagList("mbBlockList"); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound posCompound = (NBTTagCompound) nbttaglist.tagAt(i); Position pos = new Position(posCompound.getInteger("x"), posCompound.getInteger("y"), posCompound.getInteger("z")); mbBlockList.add(pos); } } @Override public void writeToNBT(NBTTagCompound nbt) { NBTTagList nbttaglist = new NBTTagList(); nbt.setTag("mbBlockList", nbttaglist); for(int i = 0; i < mbBlockList.size(); i++) { NBTTagCompound compound = new NBTTagCompound(); Position pos = mbBlockList.get(i); compound.setInteger("x", pos.x); compound.setInteger("y", pos.y); compound.setInteger("z", pos.z); nbttaglist.appendTag(compound); } } } Soo, first question: Do I call onMBInit() in preInit(FMLPreInitializationEvent event)? Second question: What do I write in onMBInit(), so that the BlockList is loaded, so that I can return it?
  22. Aaah - so that's how it works. Thank you!! public List<Position> mbBlockList = new ArrayList(); Now it works
  23. Hello! I'd like to ask if it is possible to add a new dimension that uses a new map generator (e.g. Life in the Woods), while the old map continues using the old map generator (e.g. Minecraft 1.6.4). Background (why I want to use such a mod):
  24. Great! So this is... @Override public void writeToNBT(NBTTagCompound nbt) { NBTTagList nbttaglist = new NBTTagList(); nbt.setTag("mbBlockList", nbttaglist); When I don't cast it to Position, Eclipse displays an error: "Type mismatch: cannot convert from Object to Position" Did I do something wrong?
  25. Okay, I think it is easier to store the data as a NBTTagList of NBTTagcompounds. So I have this class "Position" public class Position { public int x; public int y; public int z; public Position(int posx, int posy, int posz){ x = posx; y = posy; z = posz; } } And I use an ArrayList in order to store the list of blocks while playing public void onBlockAdded(World world, int x, int y, int z) { Position pos = new Position(x, y, z); mbBlockList.add(pos); } So when I want to save the data to the NBT, I think this should work, right? @Override public void writeToNBT(NBTTagCompound nbt) { NBTTagList nbttaglist = new NBTTagList(); for(int i = 0; i < mbBlockList.size(); i++) { NBTTagCompound compound = new NBTTagCompound(); Position pos = (Position) mbBlockList.get(i); compound.setInteger("x", pos.x); compound.setInteger("y", pos.y); compound.setInteger("z", pos.z); nbttaglist.appendTag(compound); } } Now I have a question about the NBTTagList: how do I set the key? Because when loading I obviously need to tell the program which NBTTagList I want to load... @Override public void readFromNBT(NBTTagCompound nbt) { NBTTagList mbBlockList = nbt.getTagList("mbBlockList");
×
×
  • Create New...

Important Information

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