Jump to content

Recommended Posts

Posted (edited)

Hi everyone. I am making a mod where there is a block that can "mask" itself so that people can't find it. However, I cannot seem to get the code to work, no matter how hard I try. I have tried a

TileEntitySpecialRenderer

, however this wouldn't work, I also have tried storing the blockstate and simply returning the blockstate in the tileentity in

getExtendedState()

 and

getActualState()

, but nothing works. I don't understand why. A little help would help me greatly.

TileEntity:

Quote

package com.obcletter.moddingchallenge.block.explosive_clay;

import com.obcletter.moddingchallenge.Reference;
import com.obcletter.moddingchallenge.tile.TileEntityBase;

import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;

public class TileEntityExplosiveClay extends TileEntityBase {

    private static final String DEFAULT_BLOCK_VALUE = Reference.MOD_ID + ":explosive_clay";

    private IBlockState state;

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        state = NBTUtil.readBlockState(compound.getCompoundTag("state"));
        System.out.println(state.getBlock().getRegistryName().toString());
        super.readFromNBT(compound);
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        NBTTagCompound stateTag = new NBTTagCompound();
        if (state != null) {
            System.out.println(state.getBlock().getRegistryName().toString());
            NBTUtil.writeBlockState(stateTag, state);
            compound.setTag("state", stateTag);
        }
        return super.writeToNBT(compound);
    }

    public IBlockState getState() {
        return state;
    }

    public boolean setState(IBlockState state) {
        this.state = state;
        this.markDirty();
        return true;
    }
}

 

Block:

Quote

package com.obcletter.moddingchallenge.block.explosive_clay;

import com.obcletter.moddingchallenge.block.BlockTileEntity;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockExplosiveClay extends BlockTileEntity<TileEntityExplosiveClay> {

    public BlockExplosiveClay() {
        super("explosive_clay", Material.CLAY);
        this.setSoundType(SoundType.GROUND);
    }

    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
            EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        if (!worldIn.isRemote) {
            TileEntity te = worldIn.getTileEntity(pos);
            if (te instanceof TileEntityExplosiveClay) {
                TileEntityExplosiveClay explosive_clay = (TileEntityExplosiveClay) te;
                ItemStack stack = playerIn.getHeldItem(hand);
                IBlockState staate = Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getMetadata());
                if (staate != Blocks.AIR.getDefaultState()) {
                    return explosive_clay.setState(staate);

                } else {
                    return explosive_clay.setState(getDefaultState());
                }
            }
        }
        return false;
    }

    @Override
    public Class<TileEntityExplosiveClay> getTileEntityClass() {
        return TileEntityExplosiveClay.class;
    }

    @Override
    public TileEntity createNewTileEntity(World worldIn, int meta) {
        return new TileEntityExplosiveClay();
    }
    
    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
        TileEntity entity = world.getTileEntity(pos);
        if (entity instanceof TileEntityExplosiveClay) {
            TileEntityExplosiveClay explosiveTe = (TileEntityExplosiveClay) entity;
            if (explosiveTe.getState() != null) {
                System.out.println(explosiveTe.getState().getBlock().getRegistryName().toString());
                return explosiveTe.getState();
            }
        }
        return super.getExtendedState(state, world, pos);
    }

}

 

 

Edited by OBCLetter

Hi! I'm a Java programmer but barely know anything Minecraft related. 

Posted

You don't need TEs or TESRs for this, is possible with blockstates.

 

Take a look at GreyGhosts's Minecraft By Example mod:

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe04_block_dynamic_block_model1

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.