package RobbiBlechdoseMod.Basis.Block;
import java.util.Random;
import RobbiBlechdoseMod.Basis.Basis;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.common.Configuration;
public class BlockFriendBush extends BlockFlower implements ITileEntityProvider
{
public BlockFriendBush(int par1)
{
super(par1, Material.vine);
float f = 0.4F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f);
this.setCreativeTab(Basis.tabRobbiBlechdoseMod);
}
/**
* Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
* blockID passed in. Args: blockID
*/
protected boolean canThisPlantGrowOnThisBlockID(int par1)
{
return par1 == Block.sand.blockID;
}
/**
* Returns the ID of the items to drop on destruction.
*/
public int idDropped(int par1, Random par2Random, int par3)
{
return -1;
}
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer player, int par6, float f1, float f2, float f3)
{
BlockFriendBushTileEntity tileEntity = (BlockFriendBushTileEntity)world.getBlockTileEntity(par2, par3, par4);
tileEntity.talk(player, world);
return true;
}
/**
* Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
* block and l is the block's subtype/damage.
*/
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
{
if (!par1World.isRemote && par2EntityPlayer.getCurrentEquippedItem() != null && par2EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.itemID)
{
par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
this.dropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(Basis.FriendBush, 1, par6));
}
else
{
super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
}
}
public void registerIcons(IconRegister reg)
{
this.blockIcon = reg.registerIcon("deadbush");
}
public TileEntity createNewTileEntity(World par1World)
{
return new BlockFriendBushTileEntity();
}
}
TileEntity:
package RobbiBlechdoseMod.Basis.Block;
import RobbiBlechdoseMod.Basis.Basis;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class BlockFriendBushTileEntity extends TileEntity{
public String owner;
public int FriendVar;
public int first;
public BlockFriendBushTileEntity()
{
FriendVar = 0;
first = 0;
owner = "NoOwner";
}
public void talk(EntityPlayer player, World world)
{
if (first == 0)
{
owner = player.username;
first = 1;
//System.out.println("RobbiBlechdoseMod:" + first);
}
//System.out.println("RobbiBlechdoseMod: Owner: " + owner);
//System.out.println("RobbiBlechdoseMod: Name: " + player.username);
if(owner == player.username){
System.out.println("RobbiBlechdoseMod:" + first);
//world.playSoundAtEntity(player, "RobbiBlechdoseMod:friendbush", 0.5F, 0.4F);
if(player.getCurrentEquippedItem() != null)
{
ItemStack held = player.getCurrentEquippedItem();
if(held.getItem().itemID == Item.diamond.itemID)
{
if(world.isRemote)
{
player.addChatMessage("Oh... Is that... a diamond? For ... ME? You're a really good friend! Thanks!");
}
player.inventory.consumeInventoryItem(held.itemID);
FriendVar = FriendVar +10;
}
else if(held.getItem().itemID == Item.appleRed.itemID)
{
if(world.isRemote)
{
player.addChatMessage("Now I can grow and become a big and strong Bush! YAAY! You made me happy, my friend!");
}
player.inventory.consumeInventoryItem(held.itemID);
FriendVar = FriendVar +3;
}
else if(held.getItem().itemID == Item.goldenCarrot.itemID)
{
if(world.isRemote)
{
player.addChatMessage("A golden carrot!");
}
player.inventory.consumeInventoryItem(held.itemID);
FriendVar = FriendVar +4;
}
else if(held.getItem().itemID == Item.emerald.itemID)
{
if(world.isRemote)
{
player.addChatMessage("You want to trade?");
player.addChatMessage("Here you are!");
player.dropItem(Basis.PCIdle.blockID, 1);
}
player.inventory.consumeInventoryItem(held.itemID);
}
}
else
{
if(FriendVar < 5 && FriendVar >=0){
if(world.isRemote){
player.addChatMessage("Hello "+ player.username + ".");
}
}
if(FriendVar >= 5 && FriendVar < 10){
if(world.isRemote){
player.addChatMessage("Hello my friend "+ player.username + "!");
}
}
else if(FriendVar >= 10 && FriendVar < 20){
if(world.isRemote){
player.addChatMessage("Hello my really good friend "+ player.username + "!");
}
}
else if(FriendVar >=20){
if(world.isRemote){
player.addChatMessage("Hello my really really good friend "+ player.username + "!");
}
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.owner = nbt.getString("owner");
this.FriendVar = nbt.getInteger("FriendVar");
this.first = nbt.getInteger("first");
System.out.println("Loading NBT for Friend Bush");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setString("owner", owner);
nbt.setInteger("FriendVar", FriendVar);
nbt.setInteger("first", first);
System.out.println("Saving NBT for FriendBush");
}
public Packet getDescriptionPacket()
{
NBTTagCompound nbtTag = new NBTTagCompound();
this.writeToNBT(nbtTag);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
public void onDataPacket(INetworkManager net, Packet132TileEntityData packet)
{
readFromNBT(packet.data);
}
}
And why doesn't it say in the log "Svaing/Loading NBT"?
Er...
Why haven't I got time?
And I don't have all I need.
If I would have all I need, it would work.
I've tried with the debugger and so on, but I cant find my mistake.
EDIT:
After I've added an @Override to createNewTileEntity, it now tells me everytime I right click the block "Saving NBT" and one line underneath "Loading NBT".
Here's my suggestion, which is a standard way of approaching development of anything:
Do it one part at a time.
First, create a new block which will be the replacement of this old broken one.
Create a new tile entity class for your block.
Link them with the ITileEntityProvider interface, and ensure this part actually works by using the debugger or console output.
Add variables to your tile entity, and make sure they are stored in NBT. Place the block, and do something that alters some value. For example, make right clicking the block change some boolean from false to true. Then use the debugger or console output to check if these value remain between sessions.
Then make sure the values remain synched between the server side and the client side.
Then you can try to implement functionality, bit by bit. Add one if statement at a time, and check if they work frequently.
I did the first step!!!
It saves and loads my variables!!!
Now I can re-create my system!
Glenn, if I hadn't alredy given you a reputation point for your post, I would give you ten!
Diamonds for you:
Have you got an answer for my second question, too?
What Maze said, and really using an API is the best option for the type of mod he's wanting to make.
Author of the Clarity, Serenity, Sapphire & Halcyon shader packs for Minecraft: Java Edition.
My Github page.
The entire Minecraft shader development community now has its own Discord server! Feel free to join and chat with all the developers!
Can't anyone HELP me?
Block:
TileEntity:
And why doesn't it say in the log "Svaing/Loading NBT"?
Robbi Blechdose
Well except time
So I guess there's not much we can do for ya mate.
Why haven't I got time?
And I don't have all I need.
If I would have all I need, it would work.
I've tried with the debugger and so on, but I cant find my mistake.
EDIT:
After I've added an @Override to createNewTileEntity, it now tells me everytime I right click the block "Saving NBT" and one line underneath "Loading NBT".
Robbi Blechdose
Do it one part at a time.
First, create a new block which will be the replacement of this old broken one.
Create a new tile entity class for your block.
Link them with the ITileEntityProvider interface, and ensure this part actually works by using the debugger or console output.
Add variables to your tile entity, and make sure they are stored in NBT. Place the block, and do something that alters some value. For example, make right clicking the block change some boolean from false to true. Then use the debugger or console output to check if these value remain between sessions.
Then make sure the values remain synched between the server side and the client side.
Then you can try to implement functionality, bit by bit. Add one if statement at a time, and check if they work frequently.
Thanks Glenn. Will try it.
Wait... I have to implement ITileEntityProvider?
EDIT: Just saw it was in the block class already...
Robbi Blechdose
It saves and loads my variables!!!
Now I can re-create my system!
Glenn, if I hadn't alredy given you a reputation point for your post, I would give you ten!
Diamonds for you:
Have you got an answer for my second question, too?
Robbi Blechdose
I did it.
Thread is solved.
Robbi Blechdose
Isn't that a fun feeling, when you figure it out and get the "Aha!" moment?
Congrats on solving it, and good luck on your future development
Robbi Blechdose
If I've saved the world and opened it again, I can't talk to it anymore.
Robbi Blechdose
in the @EventHandler wich is preInit.
Robbi Blechdose
With
Thanks. Works.
Robbi Blechdose