Jump to content

Recommended Posts

Posted

Alright, so I cannot add or remove info to my block. Here is my code:

Block

 

 

package kore.korecraft.mod;

 

import net.minecraft.block.BlockContainer;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.item.EntityXPOrb;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

 

public class BlockExpBank extends BlockContainer

{

private TileEntityExpBank expbankte;

private int maxExpStorage = 64;

 

    protected BlockExpBank(int par1, Material par2Material)

    {

        super(par1, par2Material);

        this.blockIndexInTexture = 0;

        this.setCreativeTab(CreativeTabs.tabBlock);

        this.setHardness(6F);

        this.setBlockName("Experience Bank");

    }

   

    public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {

    expbankte = (TileEntityExpBank) par1World.getBlockTileEntity(par2, par3, par4);

    try{

    if(expbankte==null)expbankte.setWorldObj(par1World);

    if(expbankte==null)expbankte.setExpLevel(0);

    }catch(Exception e){

    e.printStackTrace();

    }

    if(expbankte!=null){

    if(expbankte.getExpLevel()<this.maxExpStorage&&par5EntityPlayer.experienceLevel>=1){

    par5EntityPlayer.addExperienceLevel(-1);

    expbankte.setExpLevel(expbankte.getExpLevel()-1);

    }

    }

    }

   

    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)

    {

    expbankte = (TileEntityExpBank) par1World.getBlockTileEntity(par2, par3, par4);

    try{

    if(expbankte==null)expbankte.setWorldObj(par1World);

    if(expbankte==null)expbankte.setExpLevel(0);

    }catch(Exception e){

    e.printStackTrace();

    }

    if(expbankte!=null){

    if(expbankte.getExpLevel()>0){

    par5EntityPlayer.addExperienceLevel(1);

    expbankte.setExpLevel(expbankte.getExpLevel()+1);

    }

    }

        return false;

    }

   

    public int getIndexFromDamage(int i) {

return i;

    }

   

    public int idDropped() {

    return this.blockID;

    }

   

    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)

    {

        super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);

        expbankte = (TileEntityExpBank) par1World.getBlockTileEntity(par2, par3, par4); 

        if(expbankte.getExpLevel()!=(Integer)null){

        this.dropXpOnBlockBreak(par1World, par2, par3, par4, expbankte.getExpLevel());

        }

    }

   

    public String getTextureFile() {

    return Korecraft.blockTexture;

    }

 

    public void onBlockAdded(World par1World, int par2, int par3, int par4) {

    expbankte = (TileEntityExpBank) createNewTileEntity(par1World);

    par1World.setBlockTileEntity(par2, par3, par4, expbankte);

    }

   

@Override

public TileEntity createNewTileEntity(World var1) {

return expbankte;

}

 

}

 

 

 

 

TileEntity

 

 

package kore.korecraft.mod;

 

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.network.packet.Packet;

import net.minecraft.network.packet.Packet130UpdateSign;

import net.minecraft.tileentity.TileEntity;

import cpw.mods.fml.common.Side;

import cpw.mods.fml.common.asm.SideOnly;

 

public class TileEntityExpBank extends TileEntity

{

private int expLevel;

 

public void setExpLevel(int level) {

this.isEditable=true;

expLevel = level;

writeToNBT(null);

this.isEditable=false;

}

public int getExpLevel() {

return expLevel;

}

 

    /**

    * The index of the line currently being edited. Only used on client side, but defined on both. Note this is only

    * really used when the > < are going to be visible.

    */

    private int lineBeingEdited = 1;

    private boolean isEditable = false;

 

    /**

    * Writes a tile entity to NBT.

    */

    public void writeToNBT(NBTTagCompound par1NBTTagCompound)

    {

        super.writeToNBT(par1NBTTagCompound);

        if(expLevel==(Integer)null)expLevel=0;

        par1NBTTagCompound.setInteger("Levels", this.expLevel);

    }

 

    /**

    * Reads a tile entity from NBT.

    */

    public void readFromNBT(NBTTagCompound par1NBTTagCompound)

    {

        this.isEditable = false;

        super.readFromNBT(par1NBTTagCompound);

          this.expLevel= par1NBTTagCompound.getInteger("Levels");

    }

 

    public boolean isEditable()

    {

        return this.isEditable;

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * Sets the sign's isEditable flag to the specified parameter.

    */

    public void setEditable(boolean par1)

    {

        this.isEditable = par1;

    }

}

 

 

 

The Korecraft Mod

Posted

Alright, so I cannot add or remove info to my block. Here is my code:

Block

--snip--

    expbankte = (TileEntityExpBank) par1World.getBlockTileEntity(par2, par3, par4);

    try{

    if(expbankte==null)expbankte.setWorldObj(par1World);

    if(expbankte==null)expbankte.setExpLevel(0);

    }catch(Exception e){

 

 

That's always going to throw an exception, and you use that in every function - if it's null, how can you set the world?

 

And, you could have a perfect TE, but you never actually make a new instance - it is ALWAYS going to be null. Fix your createNewTileEntity method!

 

 

Protip: try and find answers yourself before asking on the forum.

It's pretty likely that there is an answer.

 

Was I helpful? Give me a thank you!

 

 

width=635 height=903http://bit.ly/HZ03zy[/img]

 

 

Tired of waiting for mods to port to bukkit?

use BukkitForge! (now with a working version of WorldEdit!)

Posted

could you please show me how to create the new te? that would help alot!

Edit:

Fixed it I just need to return a new TileEntityExpBank()

The Korecraft Mod

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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