Just so you know, the block doesn't have to extend BlockContainer, It can also implement ITileEntityProvider. They both work exactly the same, however; use whichever you want.
So I'm making an item which does as the title suggests, however I'm running into a (rather large) problem.
I have a tile entity which spawns custom particles which are colored based off tile entity values. I want the item to, when right clicking that tile entity, get those values, and save them to its own nbt (which works, afaik). If I right click on the block, it changes the color to that of its particles, and gives it nbt data for that. However, here's the problem: whenever I right click on anything else after right clicking the block, it reverts the color back to what it was before.
Here's the item code:
package com.blueraven.magicmod.item;
import com.blueraven.magicmod.tileentity.TileEntityPylon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import java.awt.*;
import java.util.List;
public class ItemColorCrystal extends ItemBase
{
public ItemColorCrystal()
{
super();
this.setUnlocalizedName("colorCrystal");
//this.setTextureName = "colorcrystal";
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int renderPass)
{
//if (!(stack.stackTagCompound.getInteger("colorHEX") == 0))
{
int red = stack.stackTagCompound.getInteger("colorRed");
int green = stack.stackTagCompound.getInteger("colorGreen");
int blue = stack.stackTagCompound.getInteger("colorBlue");
Color c = new Color(red, green, blue);
return c.getRGB();
}
//else return Integer.parseInt("ffffff", 16);
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
{
TileEntityPylon tePylon = (TileEntityPylon) world.getTileEntity(x, y, z);
if (world.getTileEntity(x, y, z) instanceof TileEntityPylon)
{
stack.stackTagCompound.setInteger("colorRed", tePylon.red);
stack.stackTagCompound.setInteger("colorGreen", tePylon.green);
stack.stackTagCompound.setInteger("colorBlue", tePylon.blue);
return true;
}
return false;
}
public void onUpdate(ItemStack stack, World world, Entity entity, int par1, boolean
{
/*if (stack.stackTagCompound == null)
{
stack.stackTagCompound = new NBTTagCompound();
}
if (world.isRemote)
{
stack.stackTagCompound.getInteger("colorRed");
stack.stackTagCompound.getInteger("colorGreen");
stack.stackTagCompound.getInteger("colorBlue");
}*/
}
@Override
public void addInformation(ItemStack stack, EntityPlayer par2EntityPlayer, List list, boolean par4)
{
if (stack.stackTagCompound != null)
{
int red = stack.stackTagCompound.getInteger("colorRed");
int green = stack.stackTagCompound.getInteger("colorGreen");
int blue = stack.stackTagCompound.getInteger("colorBlue");
// Color color = Color.decode(crystalColor);
list.add("Current colors stored:");
list.add(EnumChatFormatting.RED + "Red: "+ red);
list.add(EnumChatFormatting.GREEN + "Green: "+ green);
list.add(EnumChatFormatting.BLUE + "Blue: "+ blue);
}
}
}
I have absolutely no idea why this happens, and I have tried multiple things but I can't seem to fix it. What I'm guessing is happening is that the server and client are out of sync.
another weird thing is that if I look at the item information (hover over it) the color won't revert to what it was before.
EDIT: I forgot a word in the title, *whenever a Block is broken. sorry.
I'm trying to get a block, whenever broken, to drop a random item. I can get that to work, I just can't figure out how to make it drop an item with metadata on it. If I set it to the item it just drops the first item.
Pastebin of the block I want to drop the items. Also I'm sure that's not the most optimal way to get a random item, so if you could help me clean that up as well, that would be appreciated.
What's your in-game name? Blue_Raven
Did you read the rules? Yes.
Do you accept the rules? Yes.
Did you vote on minestatus(please make sure you are online when you are voting)? No
A little bit about yourself: I like playing minecraft and other video games. I have never greifed on any servers I have joined. I have been playing minecraft since the 1.2_02 patch. I love playing with redstone and creating awesome stuff
IGN: Blue_Raven
Age: 13
How Long Have I played: since 1.2_01
Do you enjoy vanilla? Yeah, definitely. There are some good mods out there but nothing beats plain 'ol vanilla.
IGN: Blue_Raven
Age: 13
Location: U.S.A.
Have you read the rules? Do trees in survival grow waffles? Yes.
Anything else you would like to tell us? THERE'D BETTER BE WAFFLES ON THE SERVER! *posts manditory image of an engie in tf2 eating a waffle* Yeah. Your server looks cool, and I've been trying to find a good whitelist server because the others without one are too greifed.
Is it possible to keep ur old skin when you have a different model, even when your model has a specific skin? As in if people dont have ava mod then they see your normal skin, then if they do they can see the model's specific skin.
0
0
If you do it that way, you'll never get better at modding minecraft.
0
I have a tile entity which spawns custom particles which are colored based off tile entity values. I want the item to, when right clicking that tile entity, get those values, and save them to its own nbt (which works, afaik). If I right click on the block, it changes the color to that of its particles, and gives it nbt data for that. However, here's the problem: whenever I right click on anything else after right clicking the block, it reverts the color back to what it was before.
Here's the item code:
Syntax highlighted version (pastebin)
I have absolutely no idea why this happens, and I have tried multiple things but I can't seem to fix it. What I'm guessing is happening is that the server and client are out of sync.
another weird thing is that if I look at the item information (hover over it) the color won't revert to what it was before.
0
0
My world generation code
I think I also need help making a block generate with metadata.
0
0
I'm trying to get a block, whenever broken, to drop a random item. I can get that to work, I just can't figure out how to make it drop an item with metadata on it. If I set it to the item it just drops the first item.
Pastebin of the block I want to drop the items. Also I'm sure that's not the most optimal way to get a random item, so if you could help me clean that up as well, that would be appreciated.
Pastebin of the item itself, not sure you need this, or what else you need.
0
Did you read the rules? Yes.
Do you accept the rules? Yes.
Did you vote on minestatus(please make sure you are online when you are voting)? No
A little bit about yourself: I like playing minecraft and other video games. I have never greifed on any servers I have joined. I have been playing minecraft since the 1.2_02 patch. I love playing with redstone and creating awesome stuff
0
0
Age: 13
How Long Have I played: since 1.2_01
Do you enjoy vanilla? Yeah, definitely. There are some good mods out there but nothing beats plain 'ol vanilla.
0
0
Age: 13
Location: U.S.A.
Have you read the rules? Do trees in survival grow waffles? Yes.
Anything else you would like to tell us? THERE'D BETTER BE WAFFLES ON THE SERVER! *posts manditory image of an engie in tf2 eating a waffle* Yeah. Your server looks cool, and I've been trying to find a good whitelist server because the others without one are too greifed.
0
0
0