• 0

    posted a message on Trouble with getting a player from a Tile Entity
    Ok well, most of the time I send the packet to the client through PacketDispatcher to update the string values but, I'll try sending it to the server. I enjoy the wonderful wealth of help I get from you guys.

    Posted in: Modification Development
  • 0

    posted a message on Trouble with getting a player from a Tile Entity
    I should of realized that after the fifth try. XD Would it be possible to create a boolean that limits how many people can use it. Set it to false and then, set it to true when the gui is opened and grab the player that opened it? If you think this is possible, how could I get the player that opened it?

    Posted in: Modification Development
  • 0

    posted a message on Trouble with getting a player from a Tile Entity
    So, my mod implements a new currency (Silver) and I want to make a sell gui for it. I got it to work but, one problem; when I put an item in the slot thr game crashes and throws a NullPointerException. I know this happens because I try to grab the players username when I getSilverTotal (see the SilverKeeper) and it can't because the player is null. If anyone can help me I would really appreciate it. I just need to get the damn player that is accessing the tile entity.



    TileEntitySell:

    package com.happycraft.happycraftmod.tileentity;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    
    import com.happycraft.happycraftmod.utils.api.ExperienceKeeper;
    import com.happycraft.happycraftmod.utils.api.SilverKeeper;
    import com.happycraft.happycraftmod.utils.handlers.SilverValueHandler;
    import com.happycraft.happycraftmod.utils.packets.PacketSilver;
    import com.happycraft.happycraftmod.utils.packets.PacketType;
    
    import cpw.mods.fml.client.FMLClientHandler;
    import cpw.mods.fml.common.FMLCommonHandler;
    import cpw.mods.fml.common.network.PacketDispatcher;
    import cpw.mods.fml.common.network.Player;
    
    public class TileEntitySell extends TileEntity implements IInventory {
        private ItemStack[] inventory;
        public SilverKeeper silver;
        public World world;
        public EntityPlayer player;
        public SilverValueHandler silvervalues;
        public ExperienceKeeper experience;
        public Player par1player;
    
        public TileEntitySell() {
            inventory = new ItemStack[1];
            this.player = setPlayerName(player);
        }
    
        @Override
        public int getSizeInventory() {
            return inventory.length;
        }
    
        @Override
        public ItemStack getStackInSlot(int i) {
            int j = 0;
            if (inventory[i] != null) {
                for (int k = 0; k < inventory[i].stackSize; k++) {
                    Item item = inventory[i].getItem();
                    String s = item.getUnlocalizedName();
                    j = silvervalues.getSilverValue(s);
                    if (FMLCommonHandler.instance().getEffectiveSide().isServer())
                        silver.addSilver(this.player, j);
                    this.par1player = (Player) player;
                    PacketDispatcher.sendPacketToPlayer(PacketType.populatePacket(new PacketSilver(player.username, silver.getSilverTotal(this.player))),
                            (Player) player);
                }
                if (j != 0) {
                    inventory[i] = null;
                }
            }
            return inventory[i];
        }
    
        @Override
        public void setInventorySlotContents(int i, ItemStack itemstack) {
            inventory[i] = itemstack;
            if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
                itemstack.stackSize = getInventoryStackLimit();
            }
        }
    
        @Override
        public ItemStack decrStackSize(int i, int j) {
            if (inventory[i] != null) {
                if (inventory[i].stackSize <= j) {
                    ItemStack itemstack = inventory[i];
                    inventory[i] = null;
                    return itemstack;
                }
                ItemStack itemstack1 = inventory[i].splitStack(j);
                if (inventory[i].stackSize == 0) {
                    inventory[i] = null;
                }
                return itemstack1;
            } else {
                return null;
            }
        }
    
        @Override
        public ItemStack getStackInSlotOnClosing(int slotIndex) {
            return null;
        }
    
        @Override
        public int getInventoryStackLimit() {
            return 64;
        }
    
        @Override
        public boolean isUseableByPlayer(EntityPlayer player) {
            return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this
                    && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5,
                            zCoord + 0.5) < 64;
        }
    
        @Override
        public void openChest() {
        }
    
        @Override
        public void closeChest() {
        }
    
        @Override
        public String getInvName() {
            return null;
        }
    
        public EntityPlayer setPlayerName(EntityPlayer player) {
            return this.player = player;
        }
    
        @Override
        public boolean isInvNameLocalized() {
            return false;
        }
    
        @Override
        public boolean isItemValidForSlot(int i, ItemStack itemstack) {
            return false;
        }
    }
    
    


    Silver Keeper (Look at getSilverTotal(EntityPlayer player)):

    package com.happycraft.happycraftmod.utils.api;
    
    import java.util.HashMap;
    
    import net.minecraft.entity.player.EntityPlayer;
    
    /**
     * addSilver and removeSilver are the only 2 you should use!
     * 
     * @author HappyKiller1O1
     */
    
    public class SilverKeeper {
        private static HashMap<String, Integer> SilverValues = new HashMap<String, Integer>();
    
        public static int getSilverTotal(EntityPlayer player) {
            if (!SilverValues.containsKey(player.username)) {
                return 0;
            }
            return SilverValues.get(player.username);
        }
    
        public static int getSilverTotal(String username) {
            if (!SilverValues.containsKey(username)) {
                return 0;
            }
            return SilverValues.get(username);
        }
    
        public static void setSilver(EntityPlayer player, int SilverValue) {
            SilverValues.put(player.username, SilverValue);
        }
    
        /**
         * Adds 1 Silver coin
         * 
         * @param player
         */
        public static void addSilver(EntityPlayer player) {
            int i = getSilverTotal(player);
            i++;
            setSilver(player, i);
        }
    
        public static void addSilver(String username, int amount) {
            int i = SilverValues.get(username);
            i += amount;
            SilverValues.put(username, i);
        }
    
        /**
         * Add a specific amount of Silver
         * 
         * @param player
         * @param amount
         */
        public static void addSilver(EntityPlayer player, int amount) {
            int i = getSilverTotal(player);
            i += amount;
            setSilver(player, i);
        }
    
        /**
         * Remove a specific amount of Silver coins
         * 
         * @param player
         * @param amount
         */
        public static void removeSilver(EntityPlayer player, int amount) {
            int i = getSilverTotal(player);
            i -= amount;
            setSilver(player, i);
        }
    }
    
    


    Thanks for any help!

    -Joey
    Posted in: Modification Development
  • 0

    posted a message on [Forge] Trouble with getting a player from a TileEntity
    So, my mod implements a a new currency (Silver) and I am trying to make a gui container that, when the item is placed in the slot, it give a certain amount of money and takes the item. The problem is, the game crashes with a NullPointerException. This is caused by player being null; I know this because it saves the player username to a hashmap and the error is when getting the player username in my SilverKeeper. My question is, how can a get the player in a Tile Entity?



    TileEntitySell:



    
    package com.happycraft.happycraftmod.tileentity;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    
    import com.happycraft.happycraftmod.utils.api.ExperienceKeeper;
    import com.happycraft.happycraftmod.utils.api.SilverKeeper;
    import com.happycraft.happycraftmod.utils.handlers.SilverValueHandler;
    import com.happycraft.happycraftmod.utils.packets.PacketSilver;
    import com.happycraft.happycraftmod.utils.packets.PacketType;
    
    import cpw.mods.fml.client.FMLClientHandler;
    import cpw.mods.fml.common.FMLCommonHandler;
    import cpw.mods.fml.common.network.PacketDispatcher;
    import cpw.mods.fml.common.network.Player;
    
    public class TileEntitySell extends TileEntity implements IInventory {
        private ItemStack[] inventory;
        public SilverKeeper silver;
        public World world;
        public EntityPlayer player;
        public SilverValueHandler silvervalues;
        public ExperienceKeeper experience;
        public Player par1player;
    
        public TileEntitySell() {
            inventory = new ItemStack[1];
            this.player = setPlayerName(player);
        }
    
        @Override
        public int getSizeInventory() {
            return inventory.length;
        }
    
        @Override
        public ItemStack getStackInSlot(int i) {
            int j = 0;
            if (inventory[i] != null) {
                for (int k = 0; k < inventory[i].stackSize; k++) {
                    Item item = inventory[i].getItem();
                    String s = item.getUnlocalizedName();
                    j = silvervalues.getSilverValue(s);
                    if (FMLCommonHandler.instance().getEffectiveSide().isServer())
                        silver.addSilver(this.player, j);
                    this.par1player = (Player) player;
                    PacketDispatcher.sendPacketToPlayer(PacketType.populatePacket(new PacketSilver(player.username, silver.getSilverTotal(this.player))),
                            (Player) player);
                }
                if (j != 0) {
                    inventory[i] = null;
                }
            }
            return inventory[i];
        }
    
        @Override
        public void setInventorySlotContents(int i, ItemStack itemstack) {
            inventory[i] = itemstack;
            if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
                itemstack.stackSize = getInventoryStackLimit();
            }
        }
    
        @Override
        public ItemStack decrStackSize(int i, int j) {
            if (inventory[i] != null) {
                if (inventory[i].stackSize <= j) {
                    ItemStack itemstack = inventory[i];
                    inventory[i] = null;
                    return itemstack;
                }
                ItemStack itemstack1 = inventory[i].splitStack(j);
                if (inventory[i].stackSize == 0) {
                    inventory[i] = null;
                }
                return itemstack1;
            } else {
                return null;
            }
        }
    
        @Override
        public ItemStack getStackInSlotOnClosing(int slotIndex) {
            return null;
        }
    
        @Override
        public int getInventoryStackLimit() {
            return 64;
        }
    
        @Override
        public boolean isUseableByPlayer(EntityPlayer player) {
            return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this
                    && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5,
                            zCoord + 0.5) < 64;
        }
    
        @Override
        public void openChest() {
        }
    
        @Override
        public void closeChest() {
        }
    
        @Override
        public String getInvName() {
            return null;
        }
    
        public EntityPlayer setPlayerName(EntityPlayer player) {
            return this.player = player;
        }
    
        @Override
        public boolean isInvNameLocalized() {
            return false;
        }
    
        @Override
        public boolean isItemValidForSlot(int i, ItemStack itemstack) {
            return false;
        }
    }
    
    





    SilverKeeper(Look at getSilverTotal with the EntityPlayer parm required):



    
    package com.happycraft.happycraftmod.utils.api;
    
    import java.util.HashMap;
    
    import net.minecraft.entity.player.EntityPlayer;
    
    /**
     * addSilver and removeSilver are the only 2 you should use!
     * 
     * @author HappyKiller1O1
     */
    
    public class SilverKeeper {
        private static HashMap<String, Integer> SilverValues = new HashMap<String, Integer>();
    
        public static int getSilverTotal(EntityPlayer player) {
            if (!SilverValues.containsKey(player.username)) {
                return 0;
            }
            return SilverValues.get(player.username);
        }
    
        public static int getSilverTotal(String username) {
            if (!SilverValues.containsKey(username)) {
                return 0;
            }
            return SilverValues.get(username);
        }
    
        public static void setSilver(EntityPlayer player, int SilverValue) {
            SilverValues.put(player.username, SilverValue);
        }
    
        /**
         * Adds 1 Silver coin
         * 
         * @param player
         */
        public static void addSilver(EntityPlayer player) {
            int i = getSilverTotal(player);
            i++;
            setSilver(player, i);
        }
    
        public static void addSilver(String username, int amount) {
            int i = SilverValues.get(username);
            i += amount;
            SilverValues.put(username, i);
        }
    
        /**
         * Add a specific amount of Silver
         * 
         * @param player
         * @param amount
         */
        public static void addSilver(EntityPlayer player, int amount) {
            int i = getSilverTotal(player);
            i += amount;
            setSilver(player, i);
        }
    
        /**
         * Remove a specific amount of Silver coins
         * 
         * @param player
         * @param amount
         */
        public static void removeSilver(EntityPlayer player, int amount) {
            int i = getSilverTotal(player);
            i -= amount;
            setSilver(player, i);
        }
    }
    
    





    Thanks in advance!

    -Joey
    Posted in: Modification Development
  • 0

    posted a message on [1.6.4] [FORGE] HappyCraft Mod [Pre-Beta V1.0.0] (New Level Up System, Skills, Mana, Dungeons and MORE!)
    I am aware of this and it should be fixed in Pre-Beta 1.0.0. If not, I will up the spawn chance by quite a big difference and see how that works out.

    Posted in: Minecraft Mods
  • 0

    posted a message on [1.6.4] [FORGE] HappyCraft Mod [Pre-Beta V1.0.0] (New Level Up System, Skills, Mana, Dungeons and MORE!)
    New update! Includes a new lvel up system skills and more!
    Posted in: Minecraft Mods
  • 0

    posted a message on [1.6.4] [FORGE] HappyCraft Mod [Pre-Beta V1.0.0] (New Level Up System, Skills, Mana, Dungeons and MORE!)
    Working on some bug fixes; also, HappyCraft now has a server! Come check it out at omnikraft.net! Server IP(Currently, you have to be whitelisted on it for Alpha purposes): hc.omnikraft.net
    Posted in: Minecraft Mods
  • 0

    posted a message on [1.6.4][FORGE] Custom rendered 7 high block not rendering correctly
    So, I am trying to render my seven high block and, it's not working. The texture isn't loading correctly and, it no clips through the ground. Would appreciate some help.

    RenderClass:



    
    package com.happycraft.happycraftmod.render;
    
    import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.ResourceLocation;
    
    import org.lwjgl.opengl.GL11;
    
    import com.happycraft.happycraftmod.blocks.models.ModelWindmill;
    import com.happycraft.happycraftmod.lib.Strings;
    
    public class TileEntityWindmillRender extends TileEntitySpecialRenderer {
        
        private final ResourceLocation windmill_normal = new ResourceLocation(Strings.MODID + ":" + "textures/models/windmill/Windmill.png");
        
        private ModelWindmill model;
        
        public TileEntityWindmillRender() {
            this.model = new ModelWindmill();
        }
    
        public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
            GL11.glPushMatrix();
            {
                GL11.glTranslatef((float)x, (float)y, (float)z);
                GL11.glRotatef(180, 0, 0, 1);
                this.bindTexture(windmill_normal);
                GL11.glPushMatrix();
                {
                    this.model.renderModel(0.0625F);
                }
                GL11.glPopMatrix();
            }
            GL11.glPopMatrix();
        }
    }
    
    
    
    





    And yes, everything is registered correctly.
    Posted in: Modification Development
  • 0

    posted a message on [1.6.4] [FORGE] HappyCraft Mod [Pre-Beta V1.0.0] (New Level Up System, Skills, Mana, Dungeons and MORE!)
    Mod updated! See the change log for more information.
    Posted in: Minecraft Mods
  • 0

    posted a message on [1.6.4][Forge]How to make a Minecraft profile for your mod?
    Quote from Anon10W1z

    May I ask why you need a new launcher for your mod?

    Well, to make it easier for the players to install the mod and play it. But, I know making a launcher is quite a hard and lengthy process so, that's why I am asking about how to make a auto generated profile. Kind of like how forge does it.
    Posted in: Modification Development
  • 0

    posted a message on [1.6.4][Forge]How to make a Minecraft profile for your mod?
    So, I was going to create my own launcher for my mod but, I would need to learn more C# or C++ or that. :P So, what I want to do is have a jar file that can be run to create a new profile in the Minecraft launcher that will launch my mod. Is this possible? Or, would it be easier to just make a launcher?
    Posted in: Modification Development
  • 0

    posted a message on NullPointerException crash when spawning custom mob
    So, for this I would suggest replacing the id's of the items that aren't appearing with the numeric id's that you want for the desired items. If that doesn't seem to work, debug a little bit and, do some print outs upon the registry section for your items so you can see if all of your items are registering. I personally perfer registering my items and blocks in my main modding class which, although I am probably wrong but, could also be your problem. First try changing the id's to the desired numeric id's and, if it doesn't work, try registering each item in your main modding class.
    Posted in: Modification Development
  • 0

    posted a message on NullPointerException crash when spawning custom mob
    Quote from Werty6401

    You rock! Now I just need to get the texture working :D


    A simple way to do textures for mobs using the default model biped would be this:

    Make a new class, I called mine "RenderBipedMod":
    package com.main.mobs.render;
    
    import net.minecraft.client.model.ModelBiped;
    import net.minecraft.client.renderer.entity.RenderBiped;
    import net.minecraft.entity.Entity;
    import net.minecraft.util.ResourceLocation;
    
    public class RenderBipedMod extends RenderBiped {
        
        private String location;
    
        public RenderBipedMod(ModelBiped par1ModelBiped, float par2, String location) {
            super(par1ModelBiped, par2);
            this.location = location;
        }
    
        public ResourceLocation getEntityTexture(Entity entity) {
            return new ResourceLocation("yourmodid", location); //Where it says "yourmodid" call the class that has your mod id or, type it in.  //Note: It must be ALL lowercase.
        }
        
        public void doRender(Entity entity, double par2, double par4, double par6, float par8, float par9) {
            super.doRender(entity, par2, par4, par6, par8, par9);
        }
    }


    Next, in your client proxy, register your mob like so:
    package (the package it's in);
    
    public class ClientProxy extends CommonProxy {
        public void initRenders() {
            RenderingRegistry.registerEntityRenderingHandler(YourMobClass.class, new RenderBipedMod(new ModelBiped(), 0.4F /* Shadow Size **/, "the texture path"));
            //Note: When doing this, the texture path will NOT require you telling it where the location is because, you already defined that in the "RenderBipedMod" class.
        }
    }


    Just reply if you got any questions. ;)
    Posted in: Modification Development
  • 0

    posted a message on NullPointerException crash when spawning custom mob
    Your problem, from what I see, is that you're are calling "RenderingRegistry.renderEntityRenderingHandler" two times. Once in your Main Class and, once in your Client Proxy. Remove "RenderingRegistry.registerEntityRenderingHandler(EntityEnergyZombie.class, new RenderEnergyZombie(null, 500));" from your main class and, tell me if it works. Also, please use spoilers next time to clean up that mess of code. :P And, if you would like some helper methods that I use to register and add to the spawn list, I will happily provide them to you (they're much cleaner :P).
    Posted in: Modification Development
  • To post a comment, please .