Jump to content

intermediateuser

Members
  • Posts

    57
  • Joined

  • Last visited

Posts posted by intermediateuser

  1. There's a list of modding tutorials for 1.9.x/1.10.x [here](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2716947-can-we-start-a-thorough-list-of-really-good), some of which have been updated to 1.11.

     

    1.11 is still fairly similar to 1.10.2, but the main change is that

    ItemStack

    s can no longer be

    null

    (the default value is now the empty

    ItemStack

    , see

    ItemStack#isEmpty

    ) and most fields of

    ItemStack

    that were public are now private with public getters/setters. Because

    ItemStack

    s can no longer be

    null

    , anywhere that used a

    List<ItemStack>

    or

    ItemStack[]

    should now use a

    NonNullList<ItemStack>

    .

     

    Tyvm!  I will have to look into this when I get time.  :)

  2. edit2: Here this looks like a good set by step quick guide to getting you up and running, what kind of mod are you making?

     

    Thanks for the reply!  But you didn't seem to include the link... haha

     

    I'm trying to make a mod that adds a few mobs, some items, and changes the difficulty a bit, among other things.  I already have this mod working in Minecraft 1.5, but it's been about three years since I modded Minecraft so I'm trying to get back into it.

  3. So the state of things in the modding community seems to be that all the information we need IS out there, but none of it is easily located and 95% of it is outdated.  This makes getting started modding (or in my case, returning to it) very hard!  Discouragingly hard.

     

    Thing is, I know Java, too.  I just don't know how Forge and Minecraft connect and how it all looks and works in Eclipse.  But I realize this is very BASIC information!  I simply need some page or tutorial that shows me how to get a mod even started once I already have Eclipse set up.  Most "Getting Started" guides only show how to setup Eclipse and Forge, and then figuring things out from there is a matter of Googling and reading through these forums for hours piecing together outdated information to hopefully come up with a working solution.

     

    Am I the only one feeling this way?  Is there, by this point, some up-to-date resource that actually covers the simple things, so that I just get my foot in the door?  Surely there exists one, at least, and I'm simply not aware of it?

  4. Follow the Getting Started guide, then copy your existing code into the new project.

    However keep in mind that a lot of things changed, so depending on the mod you might be better of rewriting it from scratch.

     

    Thank you!  Is there a resource somewhere that can tell me what files I need to create to get things going now that I have Eclipse set up?  The Getting Started Guide doesn't actually address how to get started, once you've got Eclipse set up.

     

    I just need to know where to start coding, and what code is expected to start...

     

    Or, if I wanted to use my existing code from three years ago, how do I get the files into THIS project?  Where do I put them and how do I get Minecraft to recognize it all as a mod when I hit the green play button?

  5. I'm all set up to begin!  My project window:

     

    cZWD2HVDH.png

     

    I can even click the green play button and have it launch Minecraft 1.11.  Awesome!  But, what now?  Where do I start writing my code so that Minecraft can recognize it as a mod?  I don't know which of these files to edit, or what files to create.

     

    Note: I've made mods for Minecraft 1.5, but that was more than three years ago and things were different then...

     

    The Getting Started Guide isn't too helpful, as it doesn't address how to actually get started once you've set up Eclipse.

  6. I have a mod I was working on just about 3 years ago, in Minecraft 1.5.  Recently I have figured out how to get Eclipse and Forge working again, and I still have the 1.5 project.

     

    How can I make Eclipse launch Minecraft 1.11 using my mod when I press the green "play" button in the workspace?

     

    Or... better yet, what's the best set of steps I need to take to get my 1.5 mod code INTO a 1.11 project?  I'm not asking for specifics on code, just how to set up my workspace so I can actually start re-coding my mod.

  7. I'm new to modding in Forge, and now that I have a working 1.5.2 mod I'd like to know how I'd go about updating it to work with Minecraft 1.6.

    So would a lot of us, I think. I didn't know that Forge had been updated yet (to a stable point.)

     

    Ah, I see.  I wasn't sure how quickly things would be updated.  I've done some digging around and found LexManos' twitter, and read the changelogs and such, but there are no update nor fresh install instructions to speak of.

     

    Is there anywhere else, that you know of which I as a new modder do not, that I should be keeping tabs for information on when I can start updating my mod?

  8. What... are you doing... with a cow...?

     

    lmao  after your post i had to check for it in the code, and yup, there's something going on here with cows and solar energy.

     

    I apologize for posting without bringing any knowledge on how to address this issue to the table... ObsequiousNewt's reaction was too intriguing not to take a peek.  Ah, man, that's funny.

  9. If you're making custom blocks, it might be a good idea to consider what number range you're using for their ID's.  When an Enderman tries to pick up one of your blocks, it will check the block's ID (that you gave it) against an array of blocks it is allowed to carry.  The array itself has a set size of 256; if your ID's go beyond 255 127* (because 0 is one of the 256 indices), and an Enderman tries to pick up one of your blocks, the game will crash with an "index out of bounds" error.

     

    It's a rare occurrence, of course; I just thought I'd mention it to help anybody who might be searching for a solution, or just starting out.

     

    Happy code wrangling!

     

    *Edit: As Draco pointed out below, the bug has been reported and it appears that the number you cannot go above is 127, rather than 255.  Still, here's hoping this helps someone out.

  10. What's the basic structure for this?  I was going to just copy BlockDoor and ItemDoor and work with that, but in the process of doing so I came across EnumHelper.addDoor().  This leads me to think Forge has an easy way to add doors, but aside from this one clue I don't see how.

     

    Should I just go with my original method, or should I utilize whatever method Forge has intended for this—and if the latter, how?

  11. Got it.

     

    Mouse 3 (middle click, usually) is assigned integer -98 in the keybindings.  So if you're looking for a particular "key" in your code where you would normally use Keyboard.KEY_whatever (which is actually just a fancy name for an integer assigned to that key), you'd simply type "-98" (without the quotes, of course).

     

    I figured this out by having another key call this when pressed:

     

    System.out.println(Minecraft.getMinecraft().gameSettings.keyBindPickBlock.keyCode);

     

    You can get any of the game's keybindings that way (though I don't imagine you'd need to except if you were looking for mouse buttons).  Just be sure to delete the above line of code when you've got the information you need.

     

    Huh.  Just noticing that I used a lot of parenthesis in this post (and that's probably okay).  :P

  12. I have never looked into this myself.... But wouldn't it be logical (if the keybindings use Keyboard) to assume that it would be Mouse.nameOfVariable?

     

    Quite logical!  And I have looked into that.  It is not as straightforward as the keyboard stuff.  Thus I asked here.

     

    Well then.. I have no idea xD Try looking through source code... But have fun with that.

     

    Haha, well, thanks.  I'll post here if I find anything.

     

    In the meantime, if anyone else knows, please feel free to race me to posting the solution.  :P

  13. I have never looked into this myself.... But wouldn't it be logical (if the keybindings use Keyboard) to assume that it would be Mouse.nameOfVariable?

     

    Quite logical!  And I have looked into that.  It is not as straightforward as the keyboard stuff.  Thus I asked here.

  14. So I know how to set a keybinding already.  When I'm looking for the G key, for example, I'd use Keyboard.KEY_G

     

    What if I'm looking for Mouse Button 3?  The game already uses it for "Pick Block" (so I know it's possible) but Pick Block is essentially useless in the Survival game type so I'd like to have my mod remap it to something more useful.

  15. Solved.  The entity (in this case, EntityExplodets) must be registered in the base mod class.  I added the following code and now it's displaying properly.

     

    EntityRegistry.registerModEntity(EntityExplodets.class, "Explodets", 49, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.Explodets.name", "Explodets");

     

    I'm not certain, currently, that the second line is needed, but I added it anyway.  Happy code wrangling!

     

  16. I'm trying to emulate a thrown item, the snowball.

     

    The item I made shows up in game, can be held in hand, and on right-click gets thrown properly, but the projectile is invisible.  I know it impacts because it explodes in-world.

     

    But the item does not render in-world.  I've seen tutorials for this, and other posts in this forum, but all these tutorials and posts use their own models as the entity to render.  I simply want to render the sprite and have that thrown, the way the snowball does.  I've copied the snowball's code almost exactly (changing only what needs to be changed), but the doRender method never gets called.

     

    I System.out.println()'d my way through and the constructor in the renderer gets called.  But nothing ever reaches doRender.

     

    This is all set up precisely like the snowball, so I'm confused.

     

    ItemExplodets.java

    package x.thealphaelement.item;
    
    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.world.World;
    import x.thealphaelement.entity.EntityExplodets;
    
    public class ItemExplodets extends Item {
    public ItemExplodets(int par1)
        {
            super(par1);
            this.maxStackSize = 64;
            this.setCreativeTab(CreativeTabs.tabMisc);
            setUnlocalizedName("explodets");
        }
    
    public void registerIcons(IconRegister iconRegister) {
            itemIcon = iconRegister.registerIcon("TheAlphaElement:explodetsHeld");
    }
    
        /**
         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
         */
        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
        {
            if (!par3EntityPlayer.capabilities.isCreativeMode)
            {
                --par1ItemStack.stackSize;
            }
    
            par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
    
            if (!par2World.isRemote)
            {
                par2World.spawnEntityInWorld(new EntityExplodets(par2World, par3EntityPlayer));
            }
    
            return par1ItemStack;
        }
    
    }
    

     

     

    EntityExplodets.java

    package x.thealphaelement.entity;
    
    import net.minecraft.entity.EntityLiving;
    import net.minecraft.entity.projectile.EntityThrowable;
    import net.minecraft.util.MovingObjectPosition;
    import net.minecraft.world.World;
    
    public class EntityExplodets extends EntityThrowable {
    
    public EntityExplodets(World par1World)
        {
            super(par1World);
        }
    
        public EntityExplodets(World par1World, EntityLiving par2EntityLiving)
        {
            super(par1World, par2EntityLiving);
        }
    
        public EntityExplodets(World par1World, double par2, double par4, double par6)
        {
            super(par1World, par2, par4, par6);
        }
    
    @Override
    protected void onImpact(MovingObjectPosition movingobjectposition) {
    	this.worldObj.newExplosion(getThrower(), this.posX, this.posY, this.posZ, 1.0f, false, false);
    	this.setDead();
    }
    
    }
    

     

     

    RenderExplodets.java

    package x.thealphaelement.client.renderer.entity;
    
    import net.minecraft.client.renderer.Tessellator;
    import net.minecraft.client.renderer.entity.Render;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.projectile.EntityPotion;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemPotion;
    import net.minecraft.potion.PotionHelper;
    import net.minecraft.util.Icon;
    
    import org.lwjgl.opengl.GL11;
    import org.lwjgl.opengl.GL12;
    
    import x.thealphaelement.TheAlphaElement;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    
    @SideOnly(Side.CLIENT)
    public class RenderExplodets extends Render {
    
    private Item field_94151_a;
        private int field_94150_f;
    
        public RenderExplodets(Item par1, int par2)
        {
            this.field_94151_a = par1;
            this.field_94150_f = par2;
            System.out.println("Constructor RenderExplodets: " + this.field_94151_a + " // " + this.field_94150_f);
        }
    
        public RenderExplodets(Item par1)
        {
            this(par1, 0);
        }
    
        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {
        	Icon icon = this.field_94151_a.getIconFromDamage(this.field_94150_f);
        	System.out.println("Rendering!"); // This never gets called!  It's supposed to be called when throwing the item.
    
            if (icon != null)
            {
                GL11.glPushMatrix();
                GL11.glTranslatef((float)par2, (float)par4, (float)par6);
                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
                GL11.glScalef(0.5F, 0.5F, 0.5F);
                this.loadTexture("/gui/items.png");
                Tessellator tessellator = Tessellator.instance;
    
                if (icon == ItemPotion.func_94589_d("potion_splash"))
                {
                    int i = PotionHelper.func_77915_a(((EntityPotion)par1Entity).getPotionDamage(), false);
                    float f2 = (float)(i >> 16 & 255) / 255.0F;
                    float f3 = (float)(i >> 8 & 255) / 255.0F;
                    float f4 = (float)(i & 255) / 255.0F;
                    GL11.glColor3f(f2, f3, f4);
                    GL11.glPushMatrix();
                    this.func_77026_a(tessellator, ItemPotion.func_94589_d("potion_contents"));
                    GL11.glPopMatrix();
                    GL11.glColor3f(1.0F, 1.0F, 1.0F);
                }
    
                this.func_77026_a(tessellator, icon);
                GL11.glDisable(GL12.GL_RESCALE_NORMAL);
                GL11.glPopMatrix();
            }
        }
    
        private void func_77026_a(Tessellator par1Tessellator, Icon par2Icon)
        {
            float f = par2Icon.getMinU();
            float f1 = par2Icon.getMaxU();
            float f2 = par2Icon.getMinV();
            float f3 = par2Icon.getMaxV();
            float f4 = 1.0F;
            float f5 = 0.5F;
            float f6 = 0.25F;
            GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
            GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
            par1Tessellator.startDrawingQuads();
            par1Tessellator.setNormal(0.0F, 1.0F, 0.0F);
            par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3);
            par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3);
            par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2);
            par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2);
            par1Tessellator.draw();
    
        }
    }
    
    
    

     

    ClientProxy.java

    package x.thealphaelement.client;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    import x.thealphaelement.CommonProxy;
    import x.thealphaelement.TheAlphaElement;
    import x.thealphaelement.client.gui.GuiMerchantBlock;
    import x.thealphaelement.client.renderer.RenderBlazeModded;
    import x.thealphaelement.client.renderer.RenderCreeperModded;
    import x.thealphaelement.client.renderer.RenderEndermanModded;
    import x.thealphaelement.client.renderer.RenderGhastModded;
    import x.thealphaelement.client.renderer.RenderSkeletonModded;
    import x.thealphaelement.client.renderer.RenderSpiderModded;
    import x.thealphaelement.client.renderer.RenderWitchModded;
    import x.thealphaelement.client.renderer.RenderZombieModded;
    import x.thealphaelement.client.renderer.entity.RenderExplodets;
    import x.thealphaelement.entity.EntityExplodets;
    import x.thealphaelement.entity.monster.EntityBlazeModded;
    import x.thealphaelement.entity.monster.EntityBlueSkeleton;
    import x.thealphaelement.entity.monster.EntityBlueSpider;
    import x.thealphaelement.entity.monster.EntityBlueZombie;
    import x.thealphaelement.entity.monster.EntityCaveSpiderModded;
    import x.thealphaelement.entity.monster.EntityCreeperModded;
    import x.thealphaelement.entity.monster.EntityEndermanModded;
    import x.thealphaelement.entity.monster.EntityGhastModded;
    import x.thealphaelement.entity.monster.EntityPigZombieModded;
    import x.thealphaelement.entity.monster.EntityRedSkeleton;
    import x.thealphaelement.entity.monster.EntityRedSpider;
    import x.thealphaelement.entity.monster.EntityRedZombie;
    import x.thealphaelement.entity.monster.EntitySkeletonModded;
    import x.thealphaelement.entity.monster.EntitySpiderModded;
    import x.thealphaelement.entity.monster.EntitySpiderling;
    import x.thealphaelement.entity.monster.EntityWitchModded;
    import x.thealphaelement.entity.monster.EntityZombieModded;
    import x.thealphaelement.tileentity.TileEntityMerchantBlock;
    import cpw.mods.fml.client.registry.RenderingRegistry;
    import cpw.mods.fml.common.registry.EntityRegistry;
    
    public class ClientProxy extends CommonProxy {
            
            @Override
            public void registerRenderers() {
            	RenderingRegistry.registerEntityRenderingHandler(EntitySkeletonModded.class, new RenderSkeletonModded());
                EntityRegistry.registerGlobalEntityID(EntitySkeletonModded.class, "NormalSkeleton", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityZombieModded.class, new RenderZombieModded());
                EntityRegistry.registerGlobalEntityID(EntityZombieModded.class, "NormalZombie", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntitySpiderModded.class, new RenderSpiderModded());
                EntityRegistry.registerGlobalEntityID(EntitySpiderModded.class, "NormalSpider", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityCreeperModded.class, new RenderCreeperModded());
                EntityRegistry.registerGlobalEntityID(EntityCreeperModded.class, "NormalCreeper", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityEndermanModded.class, new RenderEndermanModded());
                EntityRegistry.registerGlobalEntityID(EntityEndermanModded.class, "NormalEnderman", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityCaveSpiderModded.class, new RenderSpiderModded());
                EntityRegistry.registerGlobalEntityID(EntityCaveSpiderModded.class, "NormalCaveSpider", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityWitchModded.class, new RenderWitchModded());
                EntityRegistry.registerGlobalEntityID(EntityWitchModded.class, "NormalWitch", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityBlazeModded.class, new RenderBlazeModded());
                EntityRegistry.registerGlobalEntityID(EntityBlazeModded.class, "NormalBlaze", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityGhastModded.class, new RenderGhastModded());
                EntityRegistry.registerGlobalEntityID(EntityGhastModded.class, "NormalGhast", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityPigZombieModded.class, new RenderZombieModded());
                EntityRegistry.registerGlobalEntityID(EntityPigZombieModded.class, "NormalPigZombie", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityRedZombie.class, new RenderZombieModded());
                EntityRegistry.registerGlobalEntityID(EntityRedZombie.class, "RedZombie", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityBlueZombie.class, new RenderZombieModded());
                EntityRegistry.registerGlobalEntityID(EntityBlueZombie.class, "BlueZombie", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityRedSkeleton.class, new RenderSkeletonModded());
                EntityRegistry.registerGlobalEntityID(EntityRedSkeleton.class, "RedSkeleton", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityBlueSkeleton.class, new RenderSkeletonModded());
                EntityRegistry.registerGlobalEntityID(EntityBlueSkeleton.class, "BlueSkeleton", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityRedSpider.class, new RenderSpiderModded());
                EntityRegistry.registerGlobalEntityID(EntityRedSpider.class, "RedSpider", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityBlueSpider.class, new RenderSpiderModded());
                EntityRegistry.registerGlobalEntityID(EntityBlueSpider.class, "BlueSpider", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntitySpiderling.class, new RenderSpiderModded());
                EntityRegistry.registerGlobalEntityID(EntitySpiderling.class, "Spiderling", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
                RenderingRegistry.registerEntityRenderingHandler(EntityExplodets.class, new RenderExplodets((Item)TheAlphaElement.explodets));
                EntityRegistry.registerGlobalEntityID(EntityExplodets.class, "Explodets", EntityRegistry.findGlobalUniqueEntityId(), 3515848, 12102);
                
           }
            
            public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
            	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
            	if (tileEntity != null) {
            		switch(ID) {
            			case 0: return new GuiMerchantBlock(player, (TileEntityMerchantBlock)tileEntity); // your GUIs go here
            		}
            	}
            	return null;
            }
            
    }

     

     

    CommonProxy.java

    package x.thealphaelement;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    import x.thealphaelement.client.gui.ContainerMerchantBlock;
    import x.thealphaelement.tileentity.TileEntityMerchantBlock;
    import cpw.mods.fml.common.network.IGuiHandler;
    
    public class CommonProxy implements IGuiHandler {
            
    	// Client stuff
            public void registerRenderers() {
                    // Nothing here as the server doesn't render graphics!
            }
    
    	@Override
    	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		return null;
    	}
    
    	@Override
    	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
    		if (tileEntity != null) {
    			switch(ID) {
    				case 0: return new ContainerMerchantBlock(player.inventory, (TileEntityMerchantBlock)tileEntity); // your Containers go here
    			}
    		}
    		return null;
    	}
    
            
    }
    

     

    Base mod class:

    package x.thealphaelement;
    
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.settings.KeyBinding;
    import net.minecraft.item.EnumToolMaterial;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.world.biome.BiomeGenBase;
    import net.minecraftforge.common.EnumHelper;
    import net.minecraftforge.common.MinecraftForge;
    
    import org.lwjgl.input.Keyboard;
    
    import x.thealphaelement.block.BlockBedModded;
    import x.thealphaelement.block.BlockGlassModded;
    import x.thealphaelement.block.MerchantBlock;
    import x.thealphaelement.client.keybinding.HealthPotionKeyBind;
    import x.thealphaelement.entity.monster.EntityBlazeModded;
    import x.thealphaelement.entity.monster.EntityBlueSkeleton;
    import x.thealphaelement.entity.monster.EntityBlueSpider;
    import x.thealphaelement.entity.monster.EntityBlueZombie;
    import x.thealphaelement.entity.monster.EntityCaveSpiderModded;
    import x.thealphaelement.entity.monster.EntityCreeperModded;
    import x.thealphaelement.entity.monster.EntityEndermanModded;
    import x.thealphaelement.entity.monster.EntityGhastModded;
    import x.thealphaelement.entity.monster.EntityPigZombieModded;
    import x.thealphaelement.entity.monster.EntityRedSkeleton;
    import x.thealphaelement.entity.monster.EntityRedSpider;
    import x.thealphaelement.entity.monster.EntityRedZombie;
    import x.thealphaelement.entity.monster.EntitySkeletonModded;
    import x.thealphaelement.entity.monster.EntitySpiderModded;
    import x.thealphaelement.entity.monster.EntitySpiderling;
    import x.thealphaelement.entity.monster.EntityWitchModded;
    import x.thealphaelement.entity.monster.EntityZombieModded;
    import x.thealphaelement.eventhandlers.EntityJoinWorldHandler;
    import x.thealphaelement.eventhandlers.EventSounds;
    import x.thealphaelement.eventhandlers.GenerateMinableHandler;
    import x.thealphaelement.eventhandlers.OverlayEventHandler;
    import x.thealphaelement.item.GlassShard;
    import x.thealphaelement.item.GlassSword;
    import x.thealphaelement.item.ItemExplodets;
    import x.thealphaelement.item.RedPotion;
    import x.thealphaelement.tileentity.TileEntityMerchantBlock;
    import cpw.mods.fml.client.registry.KeyBindingRegistry;
    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.PostInit;
    import cpw.mods.fml.common.Mod.PreInit;
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.common.event.FMLInitializationEvent;
    import cpw.mods.fml.common.event.FMLPostInitializationEvent;
    import cpw.mods.fml.common.event.FMLPreInitializationEvent;
    import cpw.mods.fml.common.network.NetworkMod;
    import cpw.mods.fml.common.network.NetworkRegistry;
    import cpw.mods.fml.common.registry.EntityRegistry;
    import cpw.mods.fml.common.registry.GameRegistry;
    import cpw.mods.fml.common.registry.LanguageRegistry;
    
    @Mod(modid="TheAlphaElement", name="The Alpha Element", version="0.2.4")
    @NetworkMod(clientSideRequired=true, serverSideRequired=false) //, channels = {"TheAlphaElement"}, packetHandler = TheAlphaElementPacketHandler.class)
    
    public class TheAlphaElement {
     // The instance of your mod that Forge uses.
        @Instance("TheAlphaElement")
        public static TheAlphaElement instance;
        
        // Monster spawning biomes.
        BiomeGenBase[] monsterSpawnBiomes = new BiomeGenBase[] { BiomeGenBase.plains, BiomeGenBase.desert, BiomeGenBase.extremeHills, BiomeGenBase.forest, BiomeGenBase.taiga, BiomeGenBase.swampland, BiomeGenBase.river, BiomeGenBase.icePlains, BiomeGenBase.iceMountains, BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.beach, BiomeGenBase.desertHills, BiomeGenBase.forestHills, BiomeGenBase.taigaHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.jungle, BiomeGenBase.jungleHills };
        private BiomeGenBase theNether = BiomeGenBase.biomeList[8];
        
        // Register materials here.
        private final static EnumToolMaterial GLASSMATERIAL = EnumHelper.addToolMaterial("GLASSMATERIAL", 0, 1, 6.0F, 35, 10);
        
    
        // Initialize items here.
        public static Item glassShard = new GlassShard(5000);
        public static Item glassSword = new GlassSword(5001, GLASSMATERIAL);
        public static Item redPotion = new RedPotion(5002);
        public static Item explodets = new ItemExplodets(5003);
        
        // Initialize blocks here.
        public final static Block merchantBlock = new MerchantBlock(500, 0, Material.wood);
        
        
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="x.thealphaelement.client.ClientProxy", serverSide="x.thealphaelement.CommonProxy")
        public static CommonProxy proxy;
        
        @PreInit
        public void preInit(FMLPreInitializationEvent event) {
        	NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
        	instance = this;
        	
        	MinecraftForge.EVENT_BUS.register(new EventSounds());
        	
        	
        	KeyBinding[] key = {new KeyBinding("Use Red Potion", Keyboard.KEY_G)};
            boolean[] repeat = {false};
            KeyBindingRegistry.registerKeyBinding(new HealthPotionKeyBind(key, repeat));
        }
        
        @Init
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
                
                // NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());
               
                // Register new mobs.
                EntityRegistry.registerModEntity(EntitySkeletonModded.class, "Normal Skeleton", 32, this, 80, 3, true);
                // EntityRegistry.addSpawn(EntitySkeletonModded.class, 30, 2, 4, EnumCreatureType.monster, monsterSpawnBiomes);
                LanguageRegistry.instance().addStringLocalization("entity.NormalSkeleton.name", "Normal Skeleton");
                
                EntityRegistry.registerModEntity(EntityZombieModded.class, "Normal Zombie", 33, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalZombie.name", "Normal Zombie");
                
                EntityRegistry.registerModEntity(EntitySpiderModded.class, "Normal Spider", 34, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalSpider.name", "Normal Spider");
                
                EntityRegistry.registerModEntity(EntityCreeperModded.class, "Normal Creeper", 35, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalCreeper.name", "Normal Creeper");
                
                EntityRegistry.registerModEntity(EntityEndermanModded.class, "Normal Enderman", 36, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalEnderman.name", "Normal Enderman");
                
                EntityRegistry.registerModEntity(EntityCaveSpiderModded.class, "Normal Cave Spider", 37, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalCaveSpider.name", "Normal Cave Spider");
                 
                EntityRegistry.registerModEntity(EntityWitchModded.class, "Normal Witch", 38, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalWitch.name", "Normal Witch");
    
                EntityRegistry.registerModEntity(EntityBlazeModded.class, "Normal Blaze", 39, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalBlaze.name", "Normal Blaze");
    
                EntityRegistry.registerModEntity(EntityGhastModded.class, "Normal Ghast", 40, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalGhast.name", "Normal Ghast");
                
                EntityRegistry.registerModEntity(EntityPigZombieModded.class, "Normal Pig Zombie", 41, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.NormalPigZombie.name", "Normal Pig Zombie");
                
                EntityRegistry.registerModEntity(EntityRedZombie.class, "Red Zombie", 42, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.RedZombie.name", "Red Zombie");
                
                EntityRegistry.registerModEntity(EntityBlueZombie.class, "Blue Zombie", 43, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.BlueZombie.name", "Blue Zombie");
                
                EntityRegistry.registerModEntity(EntityRedSkeleton.class, "Red Skeleton", 44, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.RedSkeleton.name", "Red Skeleton");
                
                EntityRegistry.registerModEntity(EntityBlueSkeleton.class, "Blue Skeleton", 45, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.BlueSkeleton.name", "Blue Skeleton");
                
                EntityRegistry.registerModEntity(EntityBlueSpider.class, "Blue Spider", 46, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.BlueSpider.name", "Blue Spider");
                
                EntityRegistry.registerModEntity(EntityRedSpider.class, "Red Spider", 47, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.RedSpider.name", "Red Spider");
                
                EntityRegistry.registerModEntity(EntitySpiderling.class, "Spiderling", 48, this, 80, 3, true);
                LanguageRegistry.instance().addStringLocalization("entity.Spiderling.name", "Spiderling");
                
                // Register item names
                LanguageRegistry.addName(glassShard, "Glass Shard");
                LanguageRegistry.addName(glassSword, "Glass Sword");
                LanguageRegistry.addName(redPotion, "Red Potion");
                LanguageRegistry.addName(explodets, "Explodets");
               
                // Register recipes.
                GameRegistry.addRecipe(new ItemStack(TheAlphaElement.glassSword), "x", "x", "y",
                        'x', TheAlphaElement.glassShard, 'y', Item.stick);
                GameRegistry.addRecipe(new ItemStack(TheAlphaElement.merchantBlock), "www", "wew", "www",
                        'w', Block.planks, 'e', Item.emerald);
                
                //Register event listeners.
                MinecraftForge.EVENT_BUS.register(new EntityJoinWorldHandler());  // Handle spawning of entities.
                MinecraftForge.ORE_GEN_BUS.register(new GenerateMinableHandler());
                
                //Register blocks.
                
                GameRegistry.registerBlock(merchantBlock, "generalMerchant");
                LanguageRegistry.addName(merchantBlock, "General Merchant");
                
                /* These blocks of code replace default blocks with our own.  Our blocks inherit all default block
                 * properties, but may also modify behaviors.
                 * 1.  Remove the block from the array called blocksList.
                 * 2.  Add our block class into that spot in the array.
                 * 3.  Register the block with the game.
                 */
                
                int glassID = Block.glass.blockID;
                Block.blocksList[glassID] = null;
                Block blockGlassModded = new BlockGlassModded(glassID, Material.glass, false);
                GameRegistry.registerBlock(blockGlassModded, "glass");
                
                int bedID = Block.bed.blockID;
                Block.blocksList[bedID] = null;
                Block blockBedModded = new BlockBedModded(bedID);
                GameRegistry.registerBlock(blockBedModded, "bed");
                
                // Register Tile Entities
                GameRegistry.registerTileEntity(TileEntityMerchantBlock.class, "generalMerchant");
        }
        
        @PostInit
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        	MinecraftForge.EVENT_BUS.register(new OverlayEventHandler(Minecraft.getMinecraft()));
        }
        
    }
    

  17. Alright, figured it out.  :)

     

    The texture bound to the renderEngine (using this.mc.renderEngine.bindTexture()) must be a 256x256 texture.  I made such a large, transparent texture (an item sheet) and pasted my item's icon into the top left 32x32 16x16 part of it (the first "slot" on the item sheet), and the icon renders properly on the main HUD now.

     

    This seems like a bit of a roundabout way to do it... though I do suppose it will be useful to have this item sheet if I need to do many such things later with the mod.

     

    If anyone knows of a more direct way, to do it, I'd be happy to hear it.

     

    Edit: Added a bit of elaboration and also changed 32x32 to 16x16, for anyone else needing info on this issue.  32x32 is slightly inaccurate; you'll most likely want to use 16x16 for your icons.

  18. This seems fairly simple, but it's taken up quite a bit of my time.

     

    I'd like to render an item on the game's main hud, but this code isn't working:

     

    package x.thealphaelement.eventhandlers;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.gui.Gui;
    import net.minecraft.client.gui.GuiIngame;
    import net.minecraft.client.renderer.entity.RenderItem;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.client.event.RenderGameOverlayEvent;
    import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
    import net.minecraftforge.event.EventPriority;
    import net.minecraftforge.event.ForgeSubscribe;
    
    import org.lwjgl.opengl.GL11;
    
    import x.thealphaelement.TheAlphaElement;
    
    public class OverlayEventHandler extends Gui {
    
    protected Minecraft mc;
    protected static RenderItem itemRenderer = new RenderItem();
    
    public OverlayEventHandler(Minecraft mc) {
    	super();
    
    	this.mc = mc;
    }
    
      @ForgeSubscribe(priority = EventPriority.NORMAL)
      public void onRenderExperienceBar(RenderGameOverlayEvent event)
      {
       
        if(event.isCancelable() || event.type != ElementType.EXPERIENCE)
        {      
          return;
        }
    
        EntityPlayer player = this.mc.thePlayer;
        
        int redPotionCount = getItemCount(player, TheAlphaElement.redPotion);
        ItemStack vendorStack = new ItemStack(TheAlphaElement.redPotion);
       	   
    	this.mc.renderEngine.bindTexture("/mods/TheAlphaElement/textures/items/redPotion.png");
            this.drawTexturedModalRect(40, 50, 0, 0, 18, 18);
        
        this.drawString(mc.fontRenderer, Integer.toString(redPotionCount), 30, 31, 16777215);
       
      }
      
      /**
    	 * Counts the number of the specified item in the player's inventory.
    	 * @param player - The player's inventory to check.
    	 * @param itemStack - The ItemStack to look for.
    	 * @return The number of items that match.
    	 */
    public int getItemCount(EntityPlayer player, Item item) {
    	ItemStack thisStack;
    	int count = 0;
    
    	int i;
    	for(i = 0; i < player.inventory.getSizeInventory(); ++i) {
    		thisStack = player.inventory.getStackInSlot(i);
    		if(thisStack != null && thisStack.itemID == item.itemID) {
    			count += thisStack.stackSize;
    		}
    	}
    
    	return count;
    }
    
    
    }
    

     

    The above code DOES work if I switch the texture to a different .png that doesn't have transparency.  Is transparency the issue?

  19. I have some code that is rendering icons on a gui, like so:

     

    // Fishing Rod
            vendorStack = new ItemStack(Item.fishingRod);
            itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, vendorStack, k+20, l+81);

     

    I'd like to also render Potion of Healing II and perhaps other potions on this gui, but I can't figure out how to make an ItemStack as the specified potion.

  20. Alright, finally got it.  My CommonProxy class didn't have container information in it.  I added this to my CommonProxy class:

     

    @Override
    	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
    		if (tileEntity != null) {
    			switch(ID) {
    				case 0: return new ContainerMerchantBlock(player.inventory, (TileEntityMerchantBlock)tileEntity); // your Containers go here
    			}
    		}
    		return null;
    	}

     

    I was mistakenly under the impression that a "server GUI element" (as in the method's name) wouldn't be needed for what I was trying to do, as the block was only supposed to display the player's inventory, and thus wouldn't need any inventory information from the server.  I therefore omitted this code.

     

    It was only after hours of tracking through Minecraft's code and adding verbosity through System.out.println() at key points was I able to discover that, when opening a normal chest or furnace, or anything of the sort, Minecraft was referring to the container by its container class name (so, something like ContainerChest or ContainerFurnace), but when activating my MerchantBlock the container object that Minecraft referenced was "ContainerPlayer", which is the same container used when a player opens their inventory normally.

     

    So my block was actually trying to manipulate the player's inventory via what Minecraft thought was the player's normal inventory window (which has additional slots), and the slots my ContainerMerchantBlock class were using, were, of course, mismatched to that of the player's inventory window.

     

    Once I discovered this, it still took me quite some time searching through the code and adding verbosity to realize I had to tell the server what container to use by adding the above code to the CommonProxy class.

     

    Thanks a ton Quarg, Newt, and Dark for your replies!  This has been quite a learning experience.

  21. I had realised much the same thing, except adding additional slots *before* the inventory results in offsetting the slot taken from, (see my post here which goes into a bit more detail about it and some other odd behaviour.)

     

    Yeah I'm following your post and reading your updates.  Thanks for posting here to let me know in case I wasn't, though.  :)  Here's something I just tried, and it's produced some interesting information.  In your Container class, try adding this method:

     

    public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
    	par4EntityPlayer.addChatMessage("clicky " + par1 + " " + par2 + " " + par3);
    	super.slotClick(par1, par2, par3, par4EntityPlayer);
    	return new ItemStack(Item.wheat);
    }

     

    The wheat is just a placeholder ItemStack to satisfy the return requirement.  What this does is override (but still activate, because of the super method call) the slotClick method, and it outputs the parameters the slotClick method is using to the player's chat screen (though you could use System.out.println() instead of player.addChatMessage() to have the echo go only to the console if you wanted).

     

    I'm finding the only thing that changes is the first int, par1 (everything else is 0's; I'm not sure if that should concern me yet).  But the result is what interests me; the par1 is always a number that's equal to the slot it should be clicking on, plus 9 (meaning the method always tries to use the slot directly above the slot actually clicked).

     

    I'm trying to find out why the method is identifying each slot the way it is.

×
×
  • Create New...

Important Information

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