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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was trying to find a mod that added something specific, and was unable to find it with what limited memory I had of seeing it. I don't know why there isn't an option to include words in overviews of mods. I could see it being in the sort tab near filters on the app in my opinion. It might help someone trying to find something specific, only based off something from the overview tab, but idk
    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
    • I am creating a server with mods but when i try tostart it it say in the logs:   [29Jan2025 20:36:50.715] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/fmlcore/1.20.1-47.3.27/fmlcore-1.20.1-47.3.27.jar is missing mods.toml file 159[29Jan2025 20:36:50.717] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar 160[29Jan2025 20:36:50.717] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar is missing mods.toml file 161[29Jan2025 20:36:50.718] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar 162[29Jan2025 20:36:50.718] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar is missing mods.toml file 163[29Jan2025 20:36:50.719] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar 164[29Jan2025 20:36:50.719] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar is missing mods.toml file
    • How do you configure the entity reach of a custom weapon? Asking for 1.21 Minecraft parchment
  • Topics

×
×
  • Create New...

Important Information

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