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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hey! I noticed you're trying to register your alexandrite item and possibly set its resource location manually with setId(...). I wanted to help clarify a few things that might simplify your code and avoid errors. ✅ The issue: You're using setId(...) inside the item registration like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties().useItemDescriptionPrefix() .setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "alexandrite"))))); But: Item.Properties does not have a setId(...) method — this line will either fail or do nothing meaningful. useItemDescriptionPrefix() is mostly used for translation keys (like "item.modid.name") but isn't needed unless you have a very specific reason. 🛠 The fix: You only need to register your item like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); Forge automatically handles the ResourceLocation (modid:alexandrite) based on the name passed into .register(...), so there’s no need to manually assign it. 📝 For the texture: Make sure you have this file in your resources: src/main/resources/assets/tutorialmod/models/item/alexandrite.json { "parent": "item/generated", "textures": { "layer0": "tutorialmod:item/alexandrite" } } And your texture PNG goes here: src/main/resources/assets/tutorialmod/textures/item/alexandrite.png 🌍 For the name in-game: Add this to your en_us.json under: src/main/resources/assets/tutorialmod/lang/en_us.json { "item.tutorialmod.alexandrite": "Alexandrite" }   Note: if im wrong about the issue you are encountering, i apologize.
    • 🛠️ Fix for Transparent or Clipping Item Render Issues When Held in First Person (Forge 1.20+) Hey everyone! I recently ran into a frustrating bug while making a custom item (a rocket) for my Forge mod, and I’m sharing the fix because it’s a bit obscure — and it worked wonders. 💥 The Problem: My item rendered semi-transparent and see-through — but only in first person. It also clipped through nearby blocks when held, unlike default items like swords or leads. The texture file was confirmed to be fully opaque (alpha 255), so the issue wasn’t the PNG itself. Interestingly, when no texture was present and the default purple-black checkerboard appeared, the clipping issue disappeared. ✅ The Fix: I ended up resolving it by randomly trying something I found on a Forge forum post about block rendering. I added this property to my item's model JSON — even though it's typically only used for blocks: { "parent": "item/generated", "textures": { "layer0": "farbeyond:item/rocket_item" }, "render_type": "minecraft:cutout" } Boom. That single line forced the item to render using a proper opaque (cutout) layer, removing all the unwanted transparency and clipping behavior in first person. 🙌 Credit: I originally found the "render_type" trick mentioned here, in a block rendering context: 👉 https://forums.minecraftforge.net/topic/149644-1201-help-with-transparent-blocks/ Even though it was meant for blocks, I thought, why not try it on an item? And it worked! Big thanks to the poster — this fix wouldn’t have happened without that tip. Hopefully this helps anyone else stuck on a weird rendering bug like I was. This isn’t a common item solution, so feel free to share it further. I’d love to know if it works for you too.
    • Use Java 21 instead of Java 24   Also make a test without modernfix
    • Ive been on this world for 2 days now, my computer blue screens pretty often so maybe that has something to do with it. maybe just incompatible mods like a lot of people so im hoping someone more knowledgeable can help me find what i need to get rid of. thank you! paste bin
    • Should probably say that i am running minecraft 1.21.1 and with quite a lot of mods (many of which im unsure should even be on the server side)
  • Topics

×
×
  • Create New...

Important Information

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