Jump to content

Recommended Posts

Posted

Hey all, I'm having another undoubtedly silly issue with my mod.

There's a block in my mod which extends the vanilla cauldron and adds some functionality.

However, I'm having a problem where every block of my cauldron's type updates itself based on only one.

 

In other words, if I interact with one cauldron, they all act as if they've been interacted with.

 

Here's the code for my cauldron, what am I doing wrong? I know very little of java, so I could use some help/advice.

 

package mod_mythica;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockCauldron;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class Cauldronm extends BlockCauldron
{
    @SideOnly(Side.CLIENT)
    private Icon field_94378_a;
    @SideOnly(Side.CLIENT)
    private Icon cauldronTopIcon;
    @SideOnly(Side.CLIENT)
    private Icon cauldronBottomIcon;

    
public boolean potionPrimaryAdded;
    

    public Cauldronm(int par1)
    {
        super(par1);
        this.potionPrimaryAdded = false;
    }

    
    
    @SideOnly(Side.CLIENT)

    public Icon getIcon(int par1, int par2)
    {
        return par1 == 1 ? this.cauldronTopIcon : (par1 == 0 ? this.cauldronBottomIcon : this.blockIcon);
    }

    @SideOnly(Side.CLIENT)

    public void registerIcons(IconRegister par1IconRegister)
    {
        this.field_94378_a = par1IconRegister.registerIcon("modmythica:cauldronm_inner");
        this.cauldronTopIcon = par1IconRegister.registerIcon("modmythica:cauldronm_top");
        this.cauldronBottomIcon = par1IconRegister.registerIcon("modmythica:cauldronm_bottom");
        this.blockIcon = par1IconRegister.registerIcon("modmythica:cauldronm_side");
    }

    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
    {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3125F, 1.0F);
        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        float f = 0.125F;
        this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
        super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        this.setBlockBoundsForItemRender();
    }

    @SideOnly(Side.CLIENT)
    public static Icon func_94375_b(String par0Str)
    {
        return par0Str.equals("inner") ? Block.cauldron.getField_94378_a() : (par0Str.equals("bottom") ? Block.cauldron.getCauldronBottomIcon() : null);
    }

    public void setBlockBoundsForItemRender()
    {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    }
    
    

    public boolean isOpaqueCube()
    {
        return false;
    }

    public int getRenderType()
    {
        return 24;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    
    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
    	
        if (par1World.isRemote)
        {
            return true;
        }
        else
        {
            ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem();

            if (itemstack == null)
            {
                return true;
            }
            else
            {
                int i1 = par1World.getBlockMetadata(par2, par3, par4);
                int j1 = func_111045_h_(i1);
                
                //Adding water from a bucket
                if (itemstack.itemID == Item.bucketWater.itemID)
                {
                    if (j1 < 3)
                    {
                        if (!par5EntityPlayer.capabilities.isCreativeMode)
                        {
                            par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, new ItemStack(Item.bucketEmpty));
                        }

                        par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
                        par1World.func_96440_m(par2, par3, par4, this.blockID);
                    }

                    return true;
                }
                else
                {
                	//Adding water from a bottle
                    if (itemstack.itemID == Item.glassBottle.itemID)
                    {
                        if (j1 > 0)
                        {
                            ItemStack itemstack1 = new ItemStack(Item.potion, 1, 0);

                            if (!par5EntityPlayer.inventory.addItemStackToInventory(itemstack1))
                            {
                                par1World.spawnEntityInWorld(new EntityItem(par1World, (double)par2 + 0.5D, (double)par3 + 1.5D, (double)par4 + 0.5D, itemstack1));
                            }
                            else if (par5EntityPlayer instanceof EntityPlayerMP)
                            {
                                ((EntityPlayerMP)par5EntityPlayer).sendContainerToPlayer(par5EntityPlayer.inventoryContainer);
                            }

                            --itemstack.stackSize;

                            if (itemstack.stackSize <= 0)
                            {
                                par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
                            }

                            par1World.setBlockMetadataWithNotify(par2, par3, par4, j1 - 1, 2);
                            par1World.func_96440_m(par2, par3, par4, this.blockID);
                        }
                    }
                    
                    //Washing armor
                    else if (j1 > 0 && itemstack.getItem() instanceof ItemArmor && ((ItemArmor)itemstack.getItem()).getArmorMaterial() == EnumArmorMaterial.CLOTH)
                    {
                        ItemArmor itemarmor = (ItemArmor)itemstack.getItem();
                        itemarmor.removeColor(itemstack);
                        par1World.setBlockMetadataWithNotify(par2, par3, par4, j1 - 1, 2);
                        par1World.func_96440_m(par2, par3, par4, this.blockID);
                        return true;
                    }
                    
                    //Adding potions
                    else if (itemstack.itemID == Item.potion.itemID && j1 >= 3)
                    {
                    	if (this.potionPrimaryAdded == false)
                    	{
                    	
                    		String potionIngred;
                    		int dmg = itemstack.getItemDamage();
                    	
                    	
                    		if (dmg == 8193 || dmg == 8257 || dmg == 8225)
                    		{
                    			potionIngred = "resistance";
                    			this.potionPrimaryAdded = true;
                    			ChatMessageComponent chatMessage1 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Resistance added [1]");
                    			par5EntityPlayer.sendChatToPlayer(chatMessage1);
                    			++itemstack.itemID;
                    		}
                    	
                    		else if (dmg == 8194 || dmg == 8258 || dmg == 8226)
                    		{
                    			potionIngred = "swiftness";
                    			this.potionPrimaryAdded = true;
                    			ChatMessageComponent chatMessage2 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Swiftness added [2]");
                    			par5EntityPlayer.sendChatToPlayer(chatMessage2);
                    			++itemstack.itemID;
                    		}
                    	
                    		else if (dmg == 8195 || dmg == 8259 || dmg == 8227)
                    		{
                    			potionIngred = "fireresistance";
                    			this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage3 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Fire Resistance added [3]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage3);
                    		++itemstack.itemID;
                    		}
                    	
                    		else if (dmg == 8196 || dmg == 8260 || dmg == 8228)
                    		{
                    			potionIngred = "poison";
                    			this.potionPrimaryAdded = true;
                    			ChatMessageComponent chatMessage4 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Poison added [4]");
                    			par5EntityPlayer.sendChatToPlayer(chatMessage4);
                    			++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8197 || dmg == 8261 || dmg == 8229)
                    	{
                    		potionIngred = "healing";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage5 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Healing added [5]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage5);
                    		++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8198 || dmg == 8262 || dmg == 8230)
                    	{
                    		potionIngred = "nightvision";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage6 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Night Vision added [6]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage6);
                    		++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8200 || dmg == 8264 || dmg == 8232)
                    	{
                    		potionIngred = "weakness";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage7 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Weakness added [7]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage7);
                    		++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8201 || dmg == 8265 || dmg == 8233)
                    	{
                    		potionIngred = "strength";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage8 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Strength added [8]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage8);
                    		++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8202 || dmg == 8266 || dmg == 8234)
                    	{
                    		potionIngred = "slowness";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage9 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Slowness added [9]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage9);
                    		++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8204 || dmg == 8268 || dmg == 8236)
                    	{
                    		potionIngred = "harming";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage10 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Harming added [10]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage10);
                    		++itemstack.itemID;
                    	}
                    	
                    	else if (dmg == 8206 || dmg == 8270 || dmg == 8238)
                    	{
                    		potionIngred = "invisibility";
                    		this.potionPrimaryAdded = true;
                    		ChatMessageComponent chatMessage11 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Invisibility added [11]");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage11);
                    		++itemstack.itemID;
                    	}  
                    	}
                    	
                    	else
                    	{
                    		ChatMessageComponent chatMessage12 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Primary potion already added");
                    		par5EntityPlayer.sendChatToPlayer(chatMessage12);
                    	}
                    }
                    
                    return true;
                }
                

            }
        }
    }

    public void fillWithRain(World par1World, int par2, int par3, int par4)
    {
        if (par1World.rand.nextInt(20) == 1)
        {
            int l = par1World.getBlockMetadata(par2, par3, par4);

            if (l < 3)
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, l + 1, 2);
            }
        }
    }
    
    //This just makes it display portal particles for testing purposes.
    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
    	if (potionPrimaryAdded == true)
    	{
    		
    		for (int l = 0; l < 4; ++l)
    		{
            	double d0 = (double)((float)par2 + par5Random.nextFloat());
            	double d1 = (double)((float)par3 + par5Random.nextFloat());
            	double d2 = (double)((float)par4 + par5Random.nextFloat());
            	double d3 = 0.0D;
            	double d4 = 0.0D;
            	double d5 = 0.0D;
            	int i1 = par5Random.nextInt(2) * 2 - 1;
            	d3 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;
            	d4 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;
            	d5 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;
            	
            	/*
            	if (par1World.getBlockId(par2 - 1, par3, par4) != this.blockID && par1World.getBlockId(par2 + 1, par3, par4) != this.blockID)
            	{
                	d0 = (double)par2 + 0.5D + 0.25D * (double)i1;
                	d3 = (double)(par5Random.nextFloat() * 2.0F * (float)i1);
            	}
            	
            	else
            	{
                	d2 = (double)par4 + 0.5D + 0.25D * (double)i1;
                	d5 = (double)(par5Random.nextFloat() * 2.0F * (float)i1);
            	}
            	*/

            	par1World.spawnParticle("portal", d0, d1, d2, d3, d4, d5);
        	}
    	}
    	
    	else
    	{
    		
    	}
    }

    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Item.cauldron.itemID;
    }

    @SideOnly(Side.CLIENT)

    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        return Item.cauldron.itemID;
    }

    public boolean hasComparatorInputOverride()
    {
        return true;
    }

    public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
    {
        int i1 = par1World.getBlockMetadata(par2, par3, par4);
        return func_111045_h_(i1);
    }

    public static int func_111045_h_(int par0)
    {
        return par0;
    }
    
}

 

Thanks for helping :)

Posted

public static boolean potionPrimaryAdded;

A static field is shared by every instance of the class. Changing will affect all instances simultaneously.

 

You may want to use static textures, but you may not want this boolean to be static.

Posted

I intend for 'potionPrimaryAdded' to be set to true for the cauldron being used, upon right clicking it with a potion item.

 

else if (itemstack.itemID == Item.potion.itemID && j1 >= 3)

If the held item is a potion and the cauldron has 3 levels of water in it,

if (this.potionPrimaryAdded == false)
                    	{

If potionPrimaryAdded is false,

 

if (dmg == 8193 || dmg == 8257 || dmg == 8225)
                    		{
                    			potionIngred = "resistance";
                    			this.potionPrimaryAdded = true;
                    			ChatMessageComponent chatMessage1 = ChatMessageComponent.func_111066_d("§5<<Mythica>>§r Resistance added [1]");
                    			par5EntityPlayer.sendChatToPlayer(chatMessage1);
                    			++itemstack.itemID;
                    		}

 

Then it checks the damage value of the held potion, and labels it in the chat (for debugging purposes), and is meant to set potionPrimaryAdded to true only for that particular cauldron.

However, all cauldrons in the world update, whether or not the boolean says static.

 

Posted
I'm not sure if bumping is allowed or not- I couldn't find any rules about it or anything.

Help would definitely be appreciated, though.

bullshit

 

pinned post called :

Modder Support Board Guidelines - READ ME BEFORE POSTING!!!

http://www.minecraftforge.net/forum/index.php/topic,5793.0.html

 

but people do it anyway

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Oh god am I oblivious.

I honestly didn't see that, I'll remove my bump post  :-\

Sorry.

EDIT: For the record, is there a way to post without bumping? Because this post is a bit ironic. I've seen the ability on other forums.

Posted

nono seriously dont worry about bumping, people do it all the time its not a problem :P

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

The reason this is happening, is because minecraft uses the same instance for every block. The only way I can see is to make a tile entity for the block and use

par1World.getBlockTileEntity(par2, par3, par4).potionPrimaryAdded = true;

Posted

Argh, I'm terrible with Tile Entities. I'll try that though, thanks.

-EDIT-

Actually, how might I go about that?

Doing this:

if (par1World.getBlockTileEntity(par2, par3, par4).potionPrimaryAdded == true)

Gives me an error, complaining that potionPrimaryAdded isn't a field in TileEntity. I've made it a field in TileEntityCauldronm, but how do I write it to check the state of potionPrimaryAdded in TileEntityCauldronm?

 

Also, note that 'Cauldronm' is intentionally spelled with an M at the end.

 

Posted

Well, this particular block already has metadata for the amount of water in it. Is it possible to have two different sets of metadata for one block, or would I need a tile entity for that?

Posted

as long as the total amount of combinaison is smaller then 16 then you're ok

 

in your case if you have 3 level of water and 2 potion status (on/off) then the total is 3*2 = 6 which is under 16

now suppose you also has 2 other type of potion (secondary and tertiary, both on and off) the total would become

3*2*2*2 = 24 which is bigger then 16 so youd need a TE

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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