Jump to content

StrangeOne101

Members
  • Posts

    48
  • Joined

  • Last visited

Posts posted by StrangeOne101

  1. As Draco said, you need to call setTextureName in order for this.getTextureName() to get the right texture. Use this.setTextureName(YourMod.modID + ":yourCustomCakeTexture"); to set the texture, but be sure not to include .png on the end. Forge does that by itself :P

  2. Hope you aren't the person I helped on the irc, and if not, I may have a solution. If you want to check if a block does something on right click, you can just see if it is overridden from the vanilla one with reflection, I'll get the specific code to you soon, not at a workspace.

    Haha, hey dude xD I tried what you said but it seemed to make everything stop working completely. Still was stuck so I posted here in hope of getting a solution.

     

    As diesieben said, there may not be a way without some really clever stuff so I might just settle on testing for TileEntities and some other blocks. Thanks anyway.

  3. Don't check for

    RIGHT_CLICK_BLOCK

    then...

    That means that it will not spawn when they right click on any block. So if they click on grass even, it won't spawn. I don't want that.

     

    Or you could fix your RIGHT_CLICK_BLOCK section of code to actually check for your block.  More than one block returns false when right clicked and more than one returns true...

    I know that. I don't have a certain block I'm trying to check for though. I'm trying to check for all blocks that interact only so I can spawn my entity if it doesn't interact.
  4. I need an event that either triggers on right click AFTER block interaction or for some way to do that with the PlayerInteractEvent. I want it to be like the onItemUse method in items that triggers after block interaction or if the player is holding shift.

     

    I did originally have the code in an item, but the item is meant to override a vanilla item with a new function and that's not possible with 1.7.

     

    The following code it what I currently have for my PlayerInteractEvent. I've tried manually triggering the activation then canceling the event after (to prevent activation from happening twice, too) but it seems to cause other problems like no more chest animations or sound.

     

    If anyone could help me with this, that'd be great.

     

    Thanks :D

     

    Code:

    @SubscribeEvent
    public void onRightClick(PlayerInteractEvent e)
    {
    	if (e.isCanceled())
    	{
    		return;
    	}
    
    	if (e.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR )
    	{
    		this.throwBrickEvent(e.entityPlayer); //New item function. Just easier in once line and place.
    	}
    	else if (e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && e.entityPlayer.getHeldItem() != null && this.canThrow(e.entityPlayer.getHeldItem()))
    	{
    		Block block = e.world.getBlock(e.x, e.y, e.z);
    		if (!block.onBlockActivated(e.world, e.x, e.y, e.z, e.entityPlayer, e.face, e.x, e.y, e.z)) //Don't know what the last 3 parameters are 
    		{
    			e.setResult(Result.DEFAULT);
    			this.throwBrickEvent(e.entityPlayer);
    		} 			
    		e.setCanceled(true);
    	}
    }

  5. No, just make sure your doing it client side. That's what the

    if (!world.isRemote)

    is for. If isRemote returns true, it's running the code from the server (it runs from both client and server though). So the code only runs when the client runs the code.

     

    And I have no idea about GUIs. There's bound to be a method for when you close them though.

  6. Hello all. :)

     

    Whenever I have tried to make a simple new dimension with even just one biome, it never ever generates. All I see is stone, and the odd patches of dirt. It seems that the biome hasn't been generated, but the world has. And when I look in F3, the biome is null.

     

    I would post the huge amount of code here, but when I tried to fix it, I kind of screwed it up and now it doesn't even work. :/

     

    Any help on the situation would be great.

    Thanks. :)

  7. If you make a new instance of a DamageSource, you can add a custom death message for it via the LanguageRegistry.

     

    DamageSourceSword class:

     

    package you.modname;
    
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.util.ChatMessageComponent;
    import net.minecraft.util.DamageSource;
    import net.minecraft.util.EntityDamageSourceIndirect;
    import net.minecraft.util.StatCollector;
    
    public class DamageSourceSword extends DamageSource
    {
    
    protected DamageSourceSword(String par1Str) 
    {
    	super(par1Str);
    }
    
    public static DamageSource causeSwordDamage(Entity par0Entity, Entity par1Entity)
    {
    	return (new EntityDamageSourceIndirect("sword", par0Entity, par1Entity));
    }
    
    @Override
    public ChatMessageComponent func_111181_b(EntityLivingBase par1EntityLivingBase)
        {
    	EntityLivingBase entitylivingbase1 = par1EntityLivingBase.func_94060_bK();
            String s = "death.attack." + this.damageType;
            String s1 = s + ".player";
            return entitylivingbase1 != null && StatCollector.func_94522_b(s1) ? ChatMessageComponent.func_111082_b(s1, new Object[] {par1EntityLivingBase.getTranslatedEntityName(), entitylivingbase1.getTranslatedEntityName()}): ChatMessageComponent.func_111082_b(s, new Object[] {par1EntityLivingBase.getTranslatedEntityName()});
        }
    }

     

     

    In your mod file, preferably in @PreInit():

     

    LanguageRegistry.instance().addStringLocalization("death.attack.sword", "%1$s was sliced to death"); //This shouldn't happen, but add anyway.
    LanguageRegistry.instance().addStringLocalization("death.attack.sword.player", "%1$s was sliced to death by %2$s"); //Death from the damagesource, because of a player. Should always be this.
    LanguageRegistry.instance().addStringLocalization("death.attack.sword.item", "%1$s was sliced to death by %2$s using %3$s"); //Death from the damagesource of they renamed the sword

     

     

  8. Thank you so much. I understand now. I had it completely wrong before.

     

    Anyway, basicly all aspects of my mod work apart from this one thing. My staff, when right click, should also summon the event, but doesn't. It says "Hidding Eggs" (which is in the event code, not the item's code), but does nothing else.

     

    [spoiler=Staff Code]

    package so101.eastersurprise.eggs;
    
    import java.util.List;
    import java.util.Random;
    
    import net.minecraft.block.Block;
    import net.minecraft.client.renderer.texture.IconRegister;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.Icon;
    import net.minecraft.world.World;
    
    import cpw.mods.fml.relauncher.*;
    import so101.eastersurprise.Main;
    import so101.eastersurprise.client.ConfigEasterSurprise;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.entity.player.EntityPlayer;
    
    public class ItemEasterStaff extends Item 
    {
    private Random rand = new Random();
    private ConfigEasterSurprise ces = Main.ces;
    private RandomEasterHuntEvent rehe = new RandomEasterHuntEvent();
    private int randItem;
    private boolean lock = false;
    
    protected int[] items;
    
    public ItemEasterStaff(int par1) 
    {
    	super(par1); 
    	setCreativeTab(CreativeTabs.tabMisc); 
    	setMaxStackSize(1);
    	this.bFull3D = true;
    
    }
    
    
    public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count)
    {
    	//par1ItemStack.damageItem(rehe.getHuntProgress(), null);
    	//for (int i=0;i<10;i++)
    	player.worldObj.spawnParticle("smoke", player.posX-1+rand.nextInt(2)+rand.nextDouble(), player.posY-1+rand.nextDouble(), player.posZ-1+rand.nextInt(2)+rand.nextDouble(), 0.0D, 0.0D, 0.0D);
    	if (!lock)
    	{
    		Main.startHunt(player);
    		lock = true;
    	}
    }
    
    /**Adds the texture from the directory stated**/
    @Override
    public void updateIcons(IconRegister ir)
    {
    	iconIndex = ir.registerIcon("EasterSurpriseMod:staff");
    }
    
    
    public String getItemDisplayName(ItemStack is)
    {
    	return "Easter Staff";
    }
    
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
        {
    	par3EntityPlayer.setItemInUse(par1ItemStack, 5);
    	return par1ItemStack; 
        }
    }

     

     

    [spoiler=Event Code]

    package so101.eastersurprise.eggs;
    
    import java.util.Random;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.src.ModLoader;
    import net.minecraft.world.World;
    
    import so101.eastersurprise.Main;
    import so101.eastersurprise.client.ConfigEasterSurprise;
    
    public class RandomEasterHuntEvent 
    {
    private Random rand = new Random();
    
    private ConfigEasterSurprise ces = Main.ces;
    private int radius;
    private int amount;
    
    int i = 0;
    int j = 0;
    
    private EntityItem[] item;
    private double[] x;
    private double[] z;
    
    private String message = "";
    
    public RandomEasterHuntEvent()
    {
    	radius = ces.huntRadius;
    	amount = ces.huntAmount;
    	item = new EntityItem[amount];
    	x = new double[amount];
    	z = new double[amount];
    
    }
    
    public void startEasterHunt(World world, EntityPlayer player)
    {
    	player.addChatMessage(message+"§7Hidding eggs...");
    	if (!world.isRemote)
    	{
    		for (i = 0; i<amount/2;i++)
    		{
    			int randomChange = world.rand.nextInt(50);
    			int damageValue;
    			if (randomChange < 3)
    			{
    				damageValue = 4;
    			}
    			else if (randomChange < 20)
    			{
    				damageValue = 2 + rand.nextInt(2);
    			}
    			else
    			{
    				damageValue = 0 + rand.nextInt(2);
    			}
    			double x = player.posX-(float)radius+(float)world.rand.nextInt(radius*2);
    			double z = player.posZ-(float)radius+(float)world.rand.nextInt(radius*2);
    			item[i] = new EntityItem(world, x, world.getTopSolidOrLiquidBlock((int)x, (int)z)+ rand.nextInt(16), z, new ItemStack(Main.EasterEgg, 1, damageValue));
    			item[i].delayBeforeCanPickup = 0;
    			item[i].age = -24000*3;
    			world.spawnEntityInWorld(item[i]);
    		}
    
    		for (j = 0; j<amount/2;j++)
    		{
    			int randomChange2 = rand.nextInt(50);
    			int damageValue2;
    			if (randomChange2 < 3)
    			{
    				damageValue2 = 4;
    			}
    			else if (randomChange2 < 20)
    			{
    				damageValue2 = 2 + rand.nextInt(2);
    			}
    			else
    			{
    				damageValue2 = 0 + rand.nextInt(2);
    			}
    			double x = player.posX-(float)radius+(float)rand.nextInt(radius*2);
    			double z = player.posZ-(float)radius+(float)rand.nextInt(radius*2);
    			item[i+j] = new EntityItem(world, x, world.getFirstUncoveredBlock((int)x, (int)z), z, new ItemStack(Main.EasterEgg, 1, damageValue2+world.rand.nextInt(1)));
    			item[i+j].delayBeforeCanPickup = 0;
    			item[i+j].age = -24000*3;
    			world.spawnEntityInWorld(item[i+j]);
    		}
    		player.addChatMessage("§7The eggs have been hidden. Let the Easter Hunt... BEGIN!");
    
    	}
    }
    
    public boolean getIsHuntActive()
    {
    	if (item[0] == null)
    	{
    		return false;
    	}
    	return true;
    }
    
    public void setHuntCancel(boolean messageUserOfCancel, EntityPlayer entityplayer)
    {
    	for (int k = 0; k<amount;k++)
    	{
    		item[k].setDead();
    	}
    	i = 0;
    	j = 0;
    
    	if (messageUserOfCancel)
    	{
    		entityplayer.addChatMessage("§7Current Easter Hunt canceled.");
    	}
    }
    
    public void setHuntCancelIfActive(boolean messageUserOfCancel, EntityPlayer entityplayer)
    {
    	if (this.getIsHuntActive())
    	{
    		for (int k = 0; k<amount;k++)
    		{
    			item[k].setDead();
    		}
    		i = 0;
    		j = 0;
    
    		if (messageUserOfCancel)
    		{
    			entityplayer.addChatMessage("§7Easter hunt is already active. Cancelling...");
    		}
    	}
    }
    
    public void setHuntCancelIfActiveWithNew(boolean messageUserOfCancel, EntityPlayer entityplayer)
    {
    	if (this.getIsHuntActive())
    	{
    		for (int k = 0; k<amount;k++)
    		{
    			item[k].setDead();
    		}
    		i = 0;
    		j = 0;
    
    		if (messageUserOfCancel)
    		{
    			entityplayer.addChatMessage("§7Easter hunt is already active. Cancelling...");
    		}
    		message = "§7Starting new Easter Hunt. ";
    		this.startEasterHunt(entityplayer.worldObj, entityplayer);
    		message = "";
    	}
    	else 
    	{
    		this.startEasterHunt(entityplayer.worldObj, entityplayer);
    	}
    }
    
    public int getHuntProgress()
    {
    	return i+j;
    }
    }
    

     

     

    [spoiler=Mod Class Hunt Method]

    public static void startHunt(EntityPlayer entityplayer)
    {
    		hunt.setHuntCancelIfActiveWithNew(true, entityplayer);
    }

     

     

    Everything else works, so thank you guys so much. I will credit you in the official thread.

  9. damageValue = 4; //rare item damage value

    }

    else if (randomChange < 20)

    {

    damageValue2 =

     

    damageValue, damageValue2  - it's not working because of a typo, I believe.

     

     

     

    As For onPlayerStoppedUsing, You may need to specify getMaxItemUseDuration or getItemUseAction.

     

    Also, do You call

    par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
    

    in onItemRightClick?

    That is a typo, just not in my code. I tried to clear up my variables, sorry.

     

    As for the second thing, I'll try it.

     

    Edit: That didn't seem to do what I want. I want the item to spawn smoke while the tight mouse button is held down but run an event once released.

  10. I've also had some other small problems over the last day or so with my mod.

     

    I've been spawning in items with different damage values, but some damage values aren't spawned. It will make no sense, so here:

    int randomChange = rand.nextInt(50);
    			int damageValue;
    			if (randomChange < 3)
    			{
    				damageValue = 4; //rare item damage value
    			}
    			else if (randomChange < 20)
    			{
    				damageValue2 = 2 + rand.nextInt(1); //uncommon items, either damage value of 2 or 3. only difference is texture
    			}
    			else
    			{
    				damageValue2 = 0 + rand.nextInt(1); //same as above, but for common items.
    			}
    			EntityItem item = new EntityItem(world, x, y, z, new ItemStack(Main.CustomItem, 1, damageValue));
    			world.spawnEntityInWorld(item);

    So basicly it only spawns the items with damage values of 0, 2 and 4. I want 1 and 3 also in there. This used to work though! I don't know what has changed since it did.

     

    And second basic problem:

    @Override
    public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) 
    {
    //stuff here
    }
    

    This isn't getting called, even though it recognizes the method (it has a javadoc).

     

    Other big problem: I still can't get the WorldData thingy to work. I need help on this. A PM would be great.

  11. Thank you all for your help! I've got the player joining event sorted, just not the data thing sorted.

     

    I've registered the data class in my load method and I've tried loading it in my event class but I don't know how to access the specific variables in the data class. So how do I do this?

  12. I don't know about NBT, but about players logging in, there is a IPlayerTracker interface.

    Just create a class like so:

     

    public class PlayerTracker implements IPlayerTracker {
    @Override
    public void onPlayerLogin(EntityPlayer player) {
            //Your code
    }
    public void onPlayerLogout(EntityPlayer player) {	}
    public void onPlayerChangedDimension(EntityPlayer player) {}
    public void onPlayerRespawn(EntityPlayer player) {}
    }
    

    onLogin method gets called every time a player joins a server (in Single Player too).

     

    You register player trackers in Your main mod class, preferably in load method.

    GameRegistry.registerPlayerTracker(new PlayerTracker());
    

    Thank you. That's exactly what I need. However, for my event, I need the world instance. I don't know how to get it.

    Ok. Now to change my data, what do I do? I actually don't have a clue. Sorry.

    Once you created it (note: you must only do this once per world!) you use loadItemData() to get your data back. Then modify it and use markDirty() to notify minecraft it has changed.

    What do you mean by "get your data back"?
×
×
  • Create New...

Important Information

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