
HammyD
Members-
Posts
9 -
Joined
-
Last visited
Converted
-
Gender
Undisclosed
-
Personal Text
I am new!
HammyD's Achievements

Tree Puncher (2/8)
0
Reputation
-
Thanks Gents, will give that a go and let you know how I get on. Draco, appreciate your input. The posted code was my nth iteration while trying to work out what was going wrong. My first iteration was pretty much identical to your cleaned up version using a switch, I changed it just in-case the repeated use of the same itemstack was causing the issue (which I now know wasn't). Didn't want you to think I hadn't given it a crack and wanted spoon feeding. Ham.
-
Hi everyone, apologies if the answer to this is something simple but I have spent forever trying to resolve this and I'm getting nowhere so a nudge would be much appreciated. Basically I have a block that when you r-click it places an item (from a range of 10 possible items) in to the players' inventory (if they have space) and alerts them to the fact a certain item has been added. On the face of things everything works but for some reason the item and the alert don't match most of the time i.e. a piece of string would appear in your inventory and you would be told "You got a fish!". The following is my code which I have gradually degraded in to its current state having previously used switch statements, a single itemStack etc. all with the same result. public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) { if (!player.isSneaking()) { boolean hasSpace = false; int giftedVolume = 0; String giftedItem = ""; Random ran = new Random(); int randomNum = ran.nextInt(10); int maxStack = 64; ItemStack [] checkStack = new ItemStack[10]; checkStack[0] = new ItemStack(Items.coal,1); checkStack[1] = new ItemStack(Items.rotten_flesh,1); checkStack[2] = new ItemStack(Items.wheat_seeds,1); checkStack[3] = new ItemStack(Items.bone,1); checkStack[4] = new ItemStack(Items.flint,1); checkStack[5] = new ItemStack(Items.fish,1); checkStack[6] = new ItemStack(Items.bread,1); checkStack[7] = new ItemStack(Items.string,1); checkStack[8] = new ItemStack(Items.bowl,1); checkStack[9] = new ItemStack(Items.apple,1); giftedVolume = 1; if (player.inventory.getFirstEmptyStack() != -1) { hasSpace = true; } else { for (int slot = 0; slot < player.inventory.getSizeInventory(); ++slot) { ItemStack itemstack = player.inventory.getStackInSlot(slot); if (itemstack != null && itemstack.isItemEqual(checkStack[randomNum])) { int volume = itemstack.stackSize; if (volume < maxStack) { hasSpace = true; break; } } } } if (hasSpace == true) { player.inventory.addItemStackToInventory(checkStack[randomNum]); ItemStack whatWasAdded = checkStack[randomNum]; ItemStack test1 = new ItemStack(Items.coal,1); ItemStack test2 = new ItemStack(Items.rotten_flesh,1); ItemStack test3 = new ItemStack(Items.wheat_seeds,1); ItemStack test4 = new ItemStack(Items.bone,1); ItemStack test5 = new ItemStack(Items.flint,1); ItemStack test6 = new ItemStack(Items.fish,1); ItemStack test7 = new ItemStack(Items.bread,1); ItemStack test8 = new ItemStack(Items.string,1); ItemStack test9 = new ItemStack(Items.bowl,1); ItemStack test10 = new ItemStack(Items.apple,1); if (whatWasAdded.isItemEqual(test1)){ giftedItem = "Some Coal"; } else if (whatWasAdded.isItemEqual(test2)) { giftedItem = "Some Smelly Rotten Flesh"; } else if (whatWasAdded.isItemEqual(test3)) { giftedItem = "Some Seeds"; } else if (whatWasAdded.isItemEqual(test4)) { giftedItem = "A Human Bone"; } else if (whatWasAdded.isItemEqual(test5)) { giftedItem = "A Piece of Flint"; } else if (whatWasAdded.isItemEqual(test6)) { giftedItem = "A Fresh Fish"; } else if (whatWasAdded.isItemEqual(test7)) { giftedItem = "Some Tasty Bread"; } else if (whatWasAdded.isItemEqual(test8)) { giftedItem = "A Piece of String"; } else if (whatWasAdded.isItemEqual(test9)) { giftedItem = "A Wooden Bowl"; } else if (whatWasAdded.isItemEqual(test10)){ giftedItem = "A Definitely Not Poisened Apple"; } else { giftedItem = "Something went wrong!"; } String successMessage = EnumChatFormatting.YELLOW + ">You searched the crate and discovered... " + giftedItem; if(!world.isRemote) { player.addChatComponentMessage(new ChatComponentText(successMessage)); } this.func_150185_e(world, x, y, z); } if (hasSpace == false) { if(!world.isRemote) { player.addChatComponentMessage(new ChatComponentText("Searching this crate would be a waste as your inventory is full!")); } } return true; } else { return false; } } Thank you in advance for any help you can provide. Having been out of the programming loop for over 20 years I have an honest admiration for what you guys and girls can do. Malc aka HammyD
-
Hi All, just a quick one to get some opinions prior to me going off on one I am thinking of making a block that when you hit it does stuff then changes state so it cant be hit again for an hour. I have had a look at how furnaces work with regard to timing the baking process etc. and switching visual state and it basically looks like a counter that counts the ticks and when this gets to Y it triggers the functionality to reset the block to its original state. Before I crack on I wanted to check with you guys (who are way more experienced than I on such matters) what the impact of this might me when it scales. If in the hour 1000 blocks are set off, would these 1000 counters cause server performance issues? This may be me being overly paranoid but I'm throwing it out there just in case. Thanks as always, HammyD.
-
[SOLVED][1.7.10] Trying to get first 3D item rendering
HammyD replied to HammyD's topic in Modder Support
Hi deadrecon98, I have got it working ;D ;D I took all the complexity out of my mainRegistry file and migrated it in to the Item class. Here are all my final files just in case anyone else has a similar problem (loads of people just go "I fixed it" and don't show how). MainRegistry.java RefStrings.java LaserItem.java LaserRender.java ServerProxy.java ClientProxy.java Massive thanks to you deadrecon98 for your support during this. Between us we got it done -
[SOLVED][1.7.10] Trying to get first 3D item rendering
HammyD replied to HammyD's topic in Modder Support
For my modid I use a reference file called RefStrings.java which contains them all. My RefStrings.MODID is set to "hammytest" so is always consistent. I did find out one thing today. I was unsure as to whether forge was reading my .obj file so I made a new one using Blender. I forgot to triangulate the faces and when I ran MC is crashed telling me there were too many points in my object faces which means it is having a go at using my object. I fixed this by re-exporting. Alas though, I still get the default purple and black square -
[SOLVED][1.7.10] Trying to get first 3D item rendering
HammyD replied to HammyD's topic in Modder Support
Hi deadrecon98, Many thanks for this. I replaced my render class with the one you crafted and nothing seems to have changed. Your other query about whether the object actually renders / is being loaded got me thinking. I have read through the console outputs and there is some moaning about a missing texture but nothing else I can see as an issue. I have attached the .txt dump Regarding Java switch statements, how do you mean exactly? I'm pretty certain the stacking of cases is fine as it just groups them all so they all trigger the same functionality as the last in the grouping. Thanks again for your help with this, it really is greatly appreciated. Ham. -
[SOLVED][1.7.10] Trying to get first 3D item rendering
HammyD replied to HammyD's topic in Modder Support
Thanks for helping out deadrecon98. I have removed the second type definition but nothing has changed. -
[SOLVED][1.7.10] Trying to get first 3D item rendering
HammyD replied to HammyD's topic in Modder Support
Oh sorry, basically all I get is the default square (purple and black) when held, dropped and first person. Nothing seems to be different from when it was just an item with a standard texture on it. -
Hi first post so please excuse any glaring noobness. I have been trying to learn how to code mods mainly as a way of getting back in to Java (not done much since finishing my AI degree 10 years ago). I have purchased several books, watched loads of videos, read loads of your posts etc. and thus far I am really enjoying tinkering with Minecraft. I can genuinely see why you guys love it so much. So far I have done all the standard stuff in 1.7.10 (blocks, items, recipes, textures) and I would now like to do some work with .obj files and rendering a 3D item. I won't lie, I have tried so many random things I am a bit lost and really need someone to point me in the right direction. I fully appreciate you guys are not here to write my code etc. and I am not asking for that but if someone could have a look over my code and give me a nudge it would be very much appreciated. The issue is that although I have made a model, made a renderer etc. nothing different is happening. I still get the same black and purple square that I had before I started adding textures (which i edited out) Here is my MainRegistry.java arghh Spoiler isn't working sorry. package com.hammy.MainRegistry; import com.hammy.item.LaserItem; import com.hammy.item.LaserRender; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxy extends ServerProxy { public void registerRenderInfo(){ MinecraftForgeClient.registerItemRenderer(MainRegistry.Laser, new LaserRender()); } } Here is my Item LaserItem.java package com.hammy.item; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.hammy.lib.RefStrings; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class LaserItem extends Item { public LaserItem() { super(); this.setUnlocalizedName(RefStrings.MODID + "_" + "trustLaser"); this.setCreativeTab(CreativeTabs.tabCombat); //this.setTextureName("hammytest:LaserItem"); setMaxStackSize(1); } } Here is my Item Renderer LaserRender.java package com.hammy.item; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.IModelCustom; import com.hammy.item.LaserItem; import org.lwjgl.opengl.GL11; import com.hammy.lib.RefStrings; public class LaserRender implements IItemRenderer { public final ResourceLocation modelResource = new ResourceLocation(RefStrings.MODID, "models/LaserItem.obj"); //public IModelCustom model = AdvancedModelLoader.loadModel(modelResource); IModelCustom model; public LaserRender(){ IModelCustom model = AdvancedModelLoader.loadModel(modelResource); // public final ResourceLocation texture = new ResourceLocation("assets/textures/items/Laser-texture.jpg"); } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { // TODO Auto-generated method stub switch(type){ case EQUIPPED: case EQUIPPED_FIRST_PERSON: return true; default: return false; } } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { // TODO Auto-generated method stub return false; } public void renderItem(ItemRenderType type, ItemStack stack, Object... data) { switch(type){ case EQUIPPED: case EQUIPPED_FIRST_PERSON: { GL11.glPushMatrix(); //Minecraft.getMinecraft().renderEngine.bindTexture(texture); //Not 100% sure if I got this right, but you bing the texture here. //Do all your GL11 rotations, scales, and translaters here... //this.model.renderAll(); //Finally render the model model.renderAll(); GL11.glPopMatrix(); } default: break; } } } Here is my ClientProxy.java package com.hammy.MainRegistry; import com.hammy.item.LaserItem; import com.hammy.item.LaserRender; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxy extends ServerProxy { public void registerRenderInfo(){ MinecraftForgeClient.registerItemRenderer(MainRegistry.Laser, new LaserRender()); } } And here is my really basic .obj file created during Blender (which I also have no idea how to use but it is a dumb pyramid). LaserItem.obj # Blender v2.74 (sub 0) OBJ File: '' # www.blender.org o Cube v 1.000000 0.000000 -1.000000 v 1.000000 0.000000 1.000000 v -1.000000 0.000000 1.000000 v -1.000000 0.000000 -1.000000 v -0.000000 1.500000 0.000000 vn 0.000000 -1.000000 0.000000 vn 0.832100 0.554700 0.000000 vn -0.000000 0.554700 0.832100 vn -0.832100 0.554700 -0.000000 vn 0.000000 0.554700 -0.832100 s off f 2//1 3//1 4//1 f 1//2 5//2 2//2 f 2//3 5//3 3//3 f 3//4 5//4 4//4 f 5//5 1//5 4//5 f 1//1 2//1 4//1 I am really sorry for the wall of text and code. Also, here is my file tree just incase.. http://gyazo.com/9fa0cae3bddc6e45e8257e289cd23060 Is this forum running on 2011 software? The WYSIWYG isn't really doing anything in Chrome. Anyhow, many thanks for any help or insight you guys can shed. Ham out!