Jump to content

SamTebbs33

Forge Modder
  • Posts

    79
  • Joined

  • Last visited

Everything posted by SamTebbs33

  1. Hi, I'd like to make an item that shows a GUI when right-clicked. The GUI should have on slot which you can place one item in, if it is the right kind of item, it will be deleted and some text should be displayed in the GUI specific to the item. However, I've been having a lot of trouble with this. As I'm using an item, I can't use an Tile Entity for the update method and inventory. How would I go about doing this? Thanks in advance!
  2. If you're using Eclipse, make sure that you refresh Eclipse after changing anything to-do with textures, that's what fixed it for me. You do this by selecting the project and using F5 (or right click->Refresh). If you're using 'the Pahimar set-up', make sure that you create a folder called resources in your project, that's where you put the assets folder and make the resources folder a source folder, that fixes it.
  3. I would like to add support for multiple languages (I believe they're called localisations), how would I go about doing that? Thanks
  4. I have set-up my Eclipse modding environment according to this tutorial: And I was wondering where to put my mod textures. I tried making a resource folder then adding mods/myrmecology (the mod name)/textures/blocks and then adding my texture there but it won't show up in-game. I have confirmed that I'm registering an icon with the correct name and directory. Where do my textures go with this non-standard modding environment?
  5. I like Java, but prefer PHP for its simplicity. For some reason I can't register names for each metadata variant for my antHill block. Each metadata variant appears in the creative menu but has the name "Snow Ant Hill" which is the last value of the hillNames array. I haven't been able to figure out why I event tried adding the names manually with several LanguageRegistry.addName(block variable, metadata name) but I got the same result. Adding names in main class: blockAntHill = new BlockAntHill(blockAntHillID); for (int k = 0; k < Variables.getLastInt(BlockAntHill.hillMeta); k++){ ItemStack ant = new ItemStack(blockAntHill, 1, k); LanguageRegistry.addName(ant, BlockAntHill.hillNames[k]); } The BlockAntHill class: package vivadaylight3.myrmecology.common.block; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import vivadaylight3.myrmecology.common.Myrmecology; import vivadaylight3.myrmecology.common.item.ItemAnt; import vivadaylight3.myrmecology.common.item.ItemExtractor; import vivadaylight3.myrmecology.common.lib.Variables; 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.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.world.World; public class BlockAntHill extends Block { public static final int[] hillMeta = {0, 1, 2, 3, 4, 5, 6}; private static final String NAME = "Ant Hill"; public static final String[] hillNames = {"Forest "+NAME, "Hillside "+NAME, "Desert "+NAME, "Swamp "+NAME, "Plains "+NAME, "Jungle "+NAME, "Snowy "+NAME}; private static Icon[] icons; private final String[] iconNames = {Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME, Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Forest", Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Hills", Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Desert", Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Swamp", Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Plains", Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Jungle", Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Snow"}; public BlockAntHill(int par1) { super(par1, Material.ground); setUnlocalizedName("antHill"); setCreativeTab(Myrmecology.tabMyrmecology); setStepSound(Block.soundGrassFootstep); setHardness(1.0F); setResistance(1.0F); } @Override public void registerIcons(IconRegister iconRegister){ icons = Variables.iconsToArray(iconRegister, iconNames); } @Override public Icon getIcon(int side, int metadata){ return icons[metadata]; } public String getUnlocalizedName(ItemStack itemStack) { return this.getUnlocalizedName() + hillNames[itemStack.getItemDamage()]; } @Override @SideOnly(Side.CLIENT) public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) { for (int k = 0; k < hillMeta.length + 1; k++){ par3List.add(new ItemStack(this, 1, k)); } } @Override public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){ return true; } public void harvestBlock(World world, EntityPlayer entity, int x, int y, int z){ if(!world.isRemote){ ItemStack tool = entity.getCurrentEquippedItem(); ItemStack extractor = new ItemStack(Myrmecology.itemExtractor); if(tool != null && tool == extractor){ int meta = world.getBlockMetadata(x, y, z); for(int k = 0; k < hillMeta.length * 5 + 1; k++){ if(meta == k){ ItemStack drone = new ItemStack(Myrmecology.itemAnt, k + ItemAnt.typeMeta[1], 1); ItemStack queen = new ItemStack(Myrmecology.itemAnt, k + ItemAnt.typeMeta[0], 1); entity.dropPlayerItem(drone); entity.dropPlayerItem(queen); } } } } } } Does anyone have any idea why?
  6. The reason why I have the getLastInt() method is because I often forget how to do several things in Java, so I make methods so that I don't forget If you mean native 'speaking' language, I was born in England and it's English. If you mean native programming language, I come from a PHP, Css and HTML background.
  7. What is it you don't want to ask me about? I would like to optimise my code if that's the thing. I solved it by registering the block prior to adding then name, that was the very obvious problem (noob moment) Thanks for the help!
  8. I've made a block which has many versions of itself using metadata. I used a for loop in my main mod class to add metadata-specific names to each block version, but I'm getting a null pointer error, for no apparent reason (There's obviously a reason ) Adding names (the first for loop works but isn't for the relevant block, the second for loop is the one that doesn't work): for (int k = 0; k < Variables.getLastInt(ItemAnt.antMeta) + Variables.getLastInt(ItemAnt.typeMeta); k++){ ItemStack ant = new ItemStack(itemAnt, 1, k); String name = ItemAnt.names[k]; LanguageRegistry.addName(ant, name); } for (int i = 0; i < Variables.getLastInt(BlockAntHill.hillMeta); i++){ ItemStack hill = new ItemStack(blockAntHill, 1, i); String name2 = BlockAntHill.hillNames[i]; /* Line 168 --->*/ LanguageRegistry.addName(hill, BlockAntHill.hillNames[i]); } The getLastInt method: public static int getLastInt(int[] array){ int a; a = array[array.length - 1]; return a; } The hillMeta variable in BlockAntHill: public static final int[] hillMeta = {0, 1, 2, 3, 4, 5, 6}; The hillNames variable in BlockAntHill: private static final String NAME = "Ant Hill"; public static final String[] hillNames = {"Forest "+NAME, "Hillside "+NAME, "Desert "+NAME, "Swamp "+NAME, "Plains "+NAME, "Jungle "+NAME, "Snowy "+NAME}; The blockAntHill object: public static Block blockAntHill; blockAntHill = new BlockAntHill(blockAntHillID); The error: ---- Minecraft Crash Report ---- // Daisy, daisy... Time: 6/10/13 10:09 PM Description: Failed to start game java.lang.NullPointerException at cpw.mods.fml.common.registry.LanguageRegistry.addNameForObject(LanguageRegistry.java:110) at cpw.mods.fml.common.registry.LanguageRegistry.addName(LanguageRegistry.java:120) at vivadaylight3.myrmecology.common.Myrmecology.mainInit(Myrmecology.java:168) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:494) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98) at cpw.mods.fml.common.Loader.initializeMods(Loader.java:696) at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:213) at net.minecraft.client.Minecraft.startGame(Minecraft.java:448) at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44) at net.minecraft.client.Minecraft.run(Minecraft.java:733) at java.lang.Thread.run(Thread.java:680) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details: Minecraft Version: 1.5.2 Operating System: Mac OS X (x86_64) version 10.8.3 Java Version: 1.6.0_45, Apple Inc. Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Apple Inc. Memory: 36162168 bytes (34 MB) / 85000192 bytes (81 MB) up to 2138767360 bytes (2039 MB) JVM Flags: 1 total; -Xmx2g AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Suspicious classes: FML and Forge are installed IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v7.51 FML v5.2.17.716 Minecraft Forge 7.8.0.716 4 mods loaded, 4 mods active mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized FML{5.2.17.716} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized Forge{7.8.0.716} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized Myrmecology{0.0.1} [Myrmecology] (bin) Unloaded->Constructed->Pre-initialized->Errored LWJGL: 2.4.2 OpenGL: Intel HD Graphics 3000 OpenGL Engine GL version 2.1 INTEL-8.10.44, Intel Inc. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Texture Pack: Default Profiler Position: N/A (disabled) Vec3 Pool Size: ~~ERROR~~ NullPointerException: null I appreciate any help, thanks in advance!
  9. I fixed it by using -Xmx2g in my run configuration VM arguments.
  10. Changing the proxy variable fixed the problem, but I now get this error: ---- Minecraft Crash Report ---- // I bet Cylons wouldn't have this problem. Time: 6/10/13 3:39 PM Description: Exception generating new chunk java.lang.OutOfMemoryError: Java heap space at net.minecraft.world.chunk.NibbleArray.<init>(NibbleArray.java:23) at net.minecraft.world.chunk.storage.ExtendedBlockStorage.<init>(ExtendedBlockStorage.java:52) at net.minecraft.world.gen.ChunkProviderFlat.provideChunk(ChunkProviderFlat.java:126) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:131) at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:166) at net.minecraft.world.World.getChunkFromChunkCoords(World.java:528) at net.minecraft.world.World.getBlockId(World.java:413) at net.minecraft.world.World.isAirBlock(World.java:437) at net.minecraft.world.World.getFirstUncoveredBlock(World.java:384) at net.minecraft.world.WorldProvider.canCoordinateBeSpawn(WorldProvider.java:100) at net.minecraft.world.WorldServer.createSpawnPosition(WorldServer.java:837) at net.minecraft.world.WorldServer.initialize(WorldServer.java:801) at net.minecraft.world.World.<init>(World.java:297) at net.minecraft.world.WorldServer.<init>(WorldServer.java:107) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:72) at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:105) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:430) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.world.chunk.NibbleArray.<init>(NibbleArray.java:23) at net.minecraft.world.chunk.storage.ExtendedBlockStorage.<init>(ExtendedBlockStorage.java:52) at net.minecraft.world.gen.ChunkProviderFlat.provideChunk(ChunkProviderFlat.java:126) -- Chunk to be generated -- Details: Location: 7,-47 Position hash: -201863462905 Generator: FlatLevelSource Stacktrace: at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:131) at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:166) at net.minecraft.world.World.getChunkFromChunkCoords(World.java:528) -- Requested block coordinates -- Details: Found chunk: true Location: World: (115,64,-746), Chunk: (at 3,4,6 in 7,-47; contains blocks 112,0,-752 to 127,255,-737), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513) Stacktrace: at net.minecraft.world.World.getBlockId(World.java:413) at net.minecraft.world.World.isAirBlock(World.java:437) at net.minecraft.world.World.getFirstUncoveredBlock(World.java:384) at net.minecraft.world.WorldProvider.canCoordinateBeSpawn(WorldProvider.java:100) at net.minecraft.world.WorldServer.createSpawnPosition(WorldServer.java:837) at net.minecraft.world.WorldServer.initialize(WorldServer.java:801) -- Affected level -- Details: Level name: New World All players: 0 total; [] Chunk stats: ServerChunkCache: 503 Drop: 0 Level seed: 7629715024821178320 Level generator: ID 01 - flat, ver 0. Features enabled: false Level generator options: Level spawn location: World: (0,0,0), Chunk: (at 0,0,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 0 game time, 0 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.world.World.<init>(World.java:297) at net.minecraft.world.WorldServer.<init>(WorldServer.java:107) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:72) at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:105) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:430) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) -- System Details -- Details: Minecraft Version: 1.5.2 Operating System: Mac OS X (x86_64) version 10.8.3 Java Version: 1.6.0_45, Apple Inc. Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Apple Inc. Memory: 96 bytes (0 MB) / 129957888 bytes (123 MB) up to 129957888 bytes (123 MB) JVM Flags: 0 total; AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Suspicious classes: FML and Forge are installed IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v7.51 FML v5.2.17.716 Minecraft Forge 7.8.0.716 4 mods loaded, 4 mods active mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available FML{5.2.17.716} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available Forge{7.8.0.716} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available Myrmecology{0.0.1} [Myrmecology] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available Profiler Position: N/A (disabled) Player Count: 0 / 8; [] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' I tried to solve it on my own but I always get a java heap space error. I looked around for ways to fix it but I had no luck. The main class is the same except for proxy being public and static.
  11. Thanks guys, I'll try that. That is the full crash log that I got.
  12. Hi guys. I'm getting the following error when running Minecraft with my mod: Error log: ---- Minecraft Crash Report ---- // Would you like a cupcake? Time: 6/9/13 3:12 PM Description: Failed to start game cpw.mods.fml.common.LoaderException: cpw.mods.fml.common.LoaderException at cpw.mods.fml.common.ProxyInjector.inject(ProxyInjector.java:67) at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:471) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) at com.google.common.eventbus.EventBus.post(EventBus.java:267) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98) at cpw.mods.fml.common.Loader.loadMods(Loader.java:509) at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:163) at net.minecraft.client.Minecraft.startGame(Minecraft.java:411) at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44) at net.minecraft.client.Minecraft.run(Minecraft.java:733) at java.lang.Thread.run(Thread.java:680) Caused by: cpw.mods.fml.common.LoaderException at cpw.mods.fml.common.ProxyInjector.inject(ProxyInjector.java:60) ... 27 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details: Minecraft Version: 1.5.2 Operating System: Mac OS X (x86_64) version 10.8.3 Java Version: 1.6.0_45, Apple Inc. Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Apple Inc. Memory: 23677136 bytes (22 MB) / 85000192 bytes (81 MB) up to 129957888 bytes (123 MB) JVM Flags: 0 total; AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Suspicious classes: FML and Forge are installed IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v7.51 FML v5.2.17.716 Minecraft Forge 7.8.0.716 4 mods loaded, 4 mods active mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed FML{5.2.17.716} [Forge Mod Loader] (coremods) Unloaded->Constructed Forge{7.8.0.716} [Minecraft Forge] (coremods) Unloaded->Constructed Myrmecology{0.0.1} [Myrmecology] (bin) Unloaded->Errored LWJGL: 2.4.2 OpenGL: Intel HD Graphics 3000 OpenGL Engine GL version 2.1 INTEL-8.10.44, Intel Inc. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Texture Pack: Default Profiler Position: N/A (disabled) Vec3 Pool Size: ~~ERROR~~ NullPointerException: null Here's my main class file: package vivadaylight3.myrmecology.common; import java.io.File; import java.util.Arrays; import java.util.Random; import vivadaylight3.myrmecology.common.block.BlockAntFarm; import vivadaylight3.myrmecology.common.block.BlockAntHill; import vivadaylight3.myrmecology.common.item.ItemAnt; import vivadaylight3.myrmecology.common.item.ItemExtractor; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.Configuration; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.Metadata; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.ModMetadata; 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; /** * Myrmecology main class * @author VivaDaylight3 */ @Mod(modid=Myrmecology.MOD_ID, name=Myrmecology.MOD_NAME, version=Myrmecology.MOD_VERSION, dependencies = Myrmecology.MOD_DEPENDENCIES) @NetworkMod(channels = "Myrmecology", clientSideRequired=true, serverSideRequired=false, packetHandler = MyrmecologyPacketHandler.class) public class Myrmecology { public static final String MOD_CHANNEL = "Myrmecology"; public static final String MOD_ID = "Myrmecology"; public static final String MOD_ID_LOWER = "myrmecology"; public static final String MOD_NAME = "Myrmecology"; public static final String MOD_VERSION = "0.0.1"; public static final String MOD_DEPENDENCIES = ""; @SidedProxy(clientSide = "vivadaylight3.myrmecology.client.ClientProxy", serverSide = "vivadaylight3.myrmecology.common.CommonProxy") private CommonProxy proxy; public static final int ID_BLOCK = 1551; public static final int ID_ITEM = 3853; //public static ModMetadata meta; public static final String RESOURCE_PATH = "/mods/" + Myrmecology.MOD_ID_LOWER + "/"; public static final String TEXTURE_PATH = RESOURCE_PATH + "textures/"; public static final String BLOCK_PATH = TEXTURE_PATH + "blocks/"; public static final String ITEM_PATH = TEXTURE_PATH + "items/"; public static final String GUI_PATH = TEXTURE_PATH + "gui/"; public static final String LANG_PATH = RESOURCE_PATH + "langauges/"; public static final String TEXTURE_PREFIX = Myrmecology.MOD_ID_LOWER + ":"; private static Configuration config = new Configuration(new File(Loader.instance().getConfigDir(), MOD_ID + ".cfg")); @Instance(MOD_NAME) public static Myrmecology instance; @PreInit public void preInit(FMLPreInitializationEvent event){ // Config config.load(); itemExtractorID = config.get(config.CATEGORY_ITEM, ITEM_EXTRACTOR_NAME, ID_ITEM).getInt(); config.save(); itemExtractor = new ItemExtractor(itemExtractorID, ITEM_EXTRACTOR_NAME); } public static CreativeTabs tabMyrmecology = new CreativeTabs("tab" + MOD_ID){ public ItemStack getIconItemStack() { return new ItemStack(Item.paper, 1, 0); } }; @Init public void mainInit(FMLInitializationEvent event){ /* meta.modId = Myrmecology.MOD_ID; meta.name = Myrmecology.MOD_NAME; meta.description = "Allows you to breed and cultivate ants."; meta.url = "https://github.com/VivaDaylight3/myrmecology"; meta.logoFile = Myrmecology.TEXTURE_PATH + "Myrmecology_Banner.png"; meta.version = Myrmecology.MOD_VERSION; meta.authorList = Arrays.asList(new String[] {"VivaDaylight3"}); meta.credits = "The Minecraft Forge team and community for their fantastic work."; meta.autogenerated = false; */ proxy.registerRenderers(); LanguageRegistry.instance().addStringLocalization("itemGroup.tab" + MOD_ID, "en_GB", MOD_NAME); LanguageRegistry.addName(itemExtractor, ITEM_EXTRACTOR_NAME_HUMAN); GameRegistry.registerItem(itemExtractor, ITEM_EXTRACTOR_NAME_HUMAN); } public static BiomeGenBase getBiome(World world, int x, int z){ BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(x, z); return biome; } public static Icon[] iconsToArray(IconRegister iconRegister, String ... icons){ Icon[] iconArray = null; for(int k = 0; k < icons.length + 1; k++){ iconArray[k] = iconRegister.registerIcon(icons[k]); } return iconArray; } } Some irrelevant code has been omitted. Does anyone know what's causing this error? I've tried multiple things but none solved the issue. Thanks in advance.
  13. So how exactly would you tell the server to send the info?
  14. God, this is confusing Anyway, I've re-done some of my code, so that the readFromNBT and writeFromNBT methods are in my tile entity class (I saw this in the TileEntityFurnace class). When the method is calles, they should set the block's code to the code variable in the TileEntityNumpad class. When are the readFromNBT and writeToNBT methods called? I'm wondering this as I would like them to be called when the player sets the block's code via its GUI. My TileEntityNumpadBlock class package vivadaylight3.interlock.tileentities.numpadblock; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileEntityNumpadBlock extends TileEntity { public static String code; public static String codeSet; public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); nbt.setString("Code", code); } public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); codeSet = nbt.getString("Code"); } public static String getCode(){ return codeSet; } } Changed codeIsSet method public static boolean codeIsSet(NBTTagCompound nbt, String world, int x, int y, int z){ String codeIf = TileEntityNumpadBlock.getCode(); if(codeIf == null || codeIf == ""){ return false; }else if(codeIf != null){ return true; }else{ return false; } } Code which sets the code variable in the tile entity class if(codeSize == 4){ // I'm setting the TileEntityNumpadBlock code variable here, so it can be written to NBT. TileEntityNumpadBlock numpad = new TileEntityNumpadBlock(); numpad.code = code; // Code holds the user-entered code, numpad.code is the code to be written to NBT. code = null; codeSize = 0; mc.displayGuiScreen((GuiScreen)null); }else{ System.out.println("Code size is not 4"); } Code that checks if the user-entered code is the one that has been written to NBT TileEntityNumpadBlock numpad = new TileEntityNumpadBlock(); String codeSet = numpad.getCode(); if(codeSet==code){ // Open door code here. } I'm sorry if I'm not being clear, it's just that this is all very confusing. I'd really appreciate a quick summary of how NBT works and how one reads, creates .dat files and writes to it. Anyway, what I really need to know is how I can set it so that each code is specific to each placed numpad and when the readFromNBT and writeToNBT methods are called.
  15. How would I get the appropriate NBTTag? I looked through some of the vanilla classes and found a method called getNBTTagCompound which returned a tag for the player, how would I do this for a tile entity so that I can pass it into the writeToNBT methods? I'm really lost when it comes to what an NBT tag is et.c
  16. Ah, that's the problem then, I'm just setting nbt to an object of the NBTTagCompound class. To what do I set nbt to? Thanks a lot for the help so far.
  17. 31000 is too great a number for an ID, it needs to be less than 5000 as far as I know. Please show us your main mod class, you might not have set the shovel as a tool.
  18. Yep, using this method public static void setNBTCode(NBTTagCompound nbt, String world, int x, int y, int z, String value) { nbt.setString(world+"-"+x+","+y+","+z, value); } I can confirm that the code is being set by using getNBTCode after setting it, I print the returned value and it's correct. I just don't get why my codeIsSet method always returns false, even if the key has a value and is set (as confirmed vie the getNBTCode method and printing the returned value).
  19. Thanks for the help and replies everyone, I just have one last question. Do you have any idea why the following method always returns false, even if the given NBT key is set and has a value? codeIsSet method public static boolean codeIsSet(NBTTagCompound nbt, String world, int x, int y, int z){ String codeIf = getNBTCode(nbt, world, x, y, z); if(codeIf == null || codeIf == ""){ return false; }else if(codeIf != null){ return true; }else{ return false; } } getNBTCode method public static String getNBTCode(NBTTagCompound nbt, String world, int x, int y, int z) { String code = nbt.getString(world+"-"+x+","+y+","+z); return code; } If the key is set, the value can be fetched, as shown by the below method in another class String codeSet = Interlock.getNBTCode(nbt, world, x, y, z); System.out.println("Set code is: "+codeSet); (The print output is the correct code)
  20. Thanks for the reply. I found those, I just have no idea what to put in the method parameters as the NBTTagCompound. Any ideas?
  21. Hi, I've made a block which allows you to set a combination code (specific to the block's location), the code needs to be stored somewhere so that I can then be retrieved and checked later on. At first I used config (.properties extension) files for this, but they proved to be less than reliable (at least with my set-up) so I turned to NBT. I looked up the tutorial on the wiki, but it was less than helpful. It did give some code, but it failed to explain how it worked and what the parameters of the given methods needed to be. I understand that you have to use something called a tag compound, but using these in the method parameters gave an invalid data type error. I would like to be able to create a file called (codes.dat) on mod load and then set values to the given code with the block's world name an coordinates as its key. This is how I did it with the properties extension. Getting and setting a code: public static String getCode(String world, int x, int y, int z, String path, String filename) throws IOException{ Config config = new Config(); String code = config.getStringKey(world+"-"+x+","+y+","+z, path, filename); return code; } public static void setCode(String world2, int x, int y, int z, String value, String path, String filename) throws IOException{ Config config = new Config(); config.setStringKey(world2+"-"+x+","+y+","+z, value, path, filename); } The setStringKey and getStringKey methods, as referenced to above: public void setStringKey(String par1key, String par2value, String par3path, String par4filename) throws IOException{ try{ Properties prop = new Properties(); FileInputStream in = new FileInputStream(par3path+par4filename); FileOutputStream out = new FileOutputStream(par3path+par4filename); prop.load(in); prop.setProperty(par1key, par2value); prop.store(out, null); in.close(); }catch(IOException e){ e.printStackTrace(); } } public String getStringKey(String par1key, String par2path, String par3filename) throws IOException{ try{ Properties properties = new Properties(); FileInputStream in = new FileInputStream(par2path+par3filename); FileOutputStream out = new FileOutputStream(par2path+par3filename); properties.load(new FileInputStream(par2path+par3filename)); String value = properties.getProperty(par1key); properties.store(out, null); in.close(); return value; }catch(IOException e){ e.printStackTrace(); return "error"; } Using this way only allowed for there to be one entry in the codes.properties file, it was always overridden when setting another blocks code, even if it had different coordinates. How would I be able to solve this, either with NBT or .properties? Thanks in advance!
  22. If you want to make a GUI and a tile entity without an inventory, you'll be needing the following classes. A block A GUI handler A GUI class for the block A tile entity class A packet handler Here are those 4 classes from one of my mods (the block is called NumpadBlock): NumpadBlock class: GuiNumpad My packet handler My GUI Handler The tile entity class (Shouldn't need any content if it doesn't have an inventory) My GUI handler If you have experience with forge modding, you'll probably understand what's going on in each file, if not, just ask
  23. Hi. I'm making a combination lock, for which I've made a gui which displays the numbers 0-9. The only problem that I've run into so far is that I can't seem to change the width of the actual buttons. from trial and error, I realised that the width and height parameters of the GuiButton method are the positions of the button in the GUI. Does anyone know how to change the width of the button itself? Here's the relevant GUI code: package vivadaylight3.interlock.tileentities.numpadblock; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.util.StringTranslate; import org.lwjgl.input.Keyboard; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiNumpadBlock extends GuiScreen { /** Combination and set/clear buttons. */ private final TileEntityNumpadBlock numpadBlock; private GuiButton button1; private GuiButton button2; private GuiButton button3; private GuiButton button4; private GuiButton button5; private GuiButton button6; private GuiButton button7; private GuiButton button8; private GuiButton button9; private GuiButton button0; private GuiButton buttonClear; private GuiButton buttonSet; // private EntityPlayer player; public GuiNumpadBlock(TileEntityNumpadBlock par1) { this.numpadBlock = par1; //this.player = par2Player; // this.player.addChatMessage("GuiNUmpad: constructor"); } /** * Called from the main game loop to update the screen. */ public void updateScreen() { //this.enteredCodeField.updateCursorCounter(); // this.player.addChatMessage("GuiNUmpad: updateScreen"); } /** * Adds the buttons (and other controls) to the screen in question. */ public void initGui() { StringTranslate stringtranslate = StringTranslate.getInstance(); Keyboard.enableRepeatEvents(true); this.buttonList.clear(); this.buttonList.add(this.button1 = new GuiButton(1, this.width / 2 - 150, 47, "1")); this.buttonList.add(this.button2 = new GuiButton(2, this.width / 2 - 150, 70, "2")); this.buttonList.add(this.button3 = new GuiButton(3, this.width / 2 - 150, 93, "3")); this.buttonList.add(this.button4 = new GuiButton(4, this.width / 2 - 150, 116, "4")); this.buttonList.add(this.button5 = new GuiButton(5, this.width / 2 - 150, 139, "5")); this.buttonList.add(this.button6 = new GuiButton(6, this.width / 2 - 150, 162, "6")); this.buttonList.add(this.button7 = new GuiButton(7, this.width / 2 - 150, 185, "7")); // this.player.addChatMessage("GuiNUmpad: initGui"); } A screenshot of how it is now, I'd like to be able to create 3 rows of 3 buttons each + an additional button under 9 for the number 0. http://i1059.photobucket.com/albums/t425/CascadeRP/2013-05-18_210731_zps3af34c36.png[/img]
  24. The rotation when placing it as a tile entity, didn't work, but I can get back to that later The problem I have no is the following error when right-clicking on the new numpad tile entity: Description: Ticking memory connection java.lang.ClassCastException: vivadaylight3.interlock.handlers.numpad.ScreenNumpad cannot be cast to net.minecraft.inventory.Container at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308) at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:347) at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2396) at vivadaylight3.interlock.blocks.NumpadBlock.onBlockActivated(NumpadBlock.java:110) at net.minecraft.item.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:412) at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:553) at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79) at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:134) at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:53) at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:675) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:571) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:127) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:469) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) As I would like to show a GUI, I copied my PolisherMachine container and modified the code so that the NumpadBlock doesn't have an inventory, so it becomes a screen and not a container (I read about screens somewhere, tile entities without inventories). I copied the classes used from my PolisherMachine tile entity (which works properly) and as said, I modified the code so that it uses GuiScreen and not GuiContainer. I made sure that I'm not importing GuiContainer or using container code anywhere, but it still says that it can't cast to net.minecraft.inventory.Container GuiNumpad (equivalent to GuiFurnace) InterlockGuiHandler NumpadBlock (block class) ScreenNumpad It manages to get to the ScreenNumpad constructor, as shown by the chat message. Any help in this issue would be very much appreciated!
×
×
  • Create New...

Important Information

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