Jump to content

Thaliviel

Forge Modder
  • Posts

    33
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Location
    Germany
  • Personal Text
    Mellow role-playing Minecrafter

Thaliviel's Achievements

Tree Puncher

Tree Puncher (2/8)

-1

Reputation

  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)
×
×
  • Create New...

Important Information

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