Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Reopened again][1.12.2] How to change blockstate based on helditem


Recommended Posts

So my Problem is I try to make an invisible block that is visible if the Player Helds a specific Item. I've already found out that tickable TileEntities are the best way for that. But as I tried nothing happened. So could someone help me, with that,please?

 

My Hiddenblock.class

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModBlocks;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import static com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod.CRUELARS_TRIFORCEMOD;

public class Hidden_Block extends Block implements ITileEntityProvider {
    public static final PropertyBool VISIBLE = PropertyBool.create("visible");
    private static boolean keepInventory;

    public Hidden_Block(boolean visibility){
        super(Material.ROCK);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VISIBLE,visibility));
        String name="";
        if (visibility){
            name="_visible";
        }
        this.setRegistryName("hidden_block"+name);
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".hidden_block"+name);
        this.setCreativeTab(CRUELARS_TRIFORCEMOD);
    }

    @MethodsReturnNonnullByDefault
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[]{VISIBLE});
    }

    @Override
    @SuppressWarnings("deprecation")
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState()
                .withProperty(VISIBLE, meta!=0);

    }

    public static void setState(boolean p_setState_0_, World p_setState_1_, BlockPos p_setState_2_) {
        IBlockState lvt_3_1_ = p_setState_1_.getBlockState(p_setState_2_);
        TileEntity lvt_4_1_ = p_setState_1_.getTileEntity(p_setState_2_);
        keepInventory = true;
        if (!p_setState_0_) {
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block.getDefaultState(), 3);
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block.getDefaultState(), 3);
        } else {
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block_visible.getDefaultState(), 3);
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block_visible.getDefaultState(), 3);
        }

        keepInventory = false;
        if (lvt_4_1_ != null) {
            lvt_4_1_.validate();
            p_setState_1_.setTileEntity(p_setState_2_, lvt_4_1_);
        }

    }

    @SuppressWarnings("deprecation")
    public IBlockState getActualState(IBlockState iBlockState,IBlockAccess iBlockAccess, BlockPos blockPos) {
        return iBlockState;
    }

    public int getMetaFromState(IBlockState blockState) {
        int i = 0;
        if ((boolean)blockState.getValue(VISIBLE)){
            i |= 2;
        }
        return i;
    }

    @Override
    public TileEntity createNewTileEntity(World world, int meta){
        return new Hidden_Block_TileEntity();
    }

    @SuppressWarnings("deprecation")
    public boolean isOpaqueCube(IBlockState p_isOpaqueCube_1_) {
        return false;
    }

    @SuppressWarnings("deprecation")
    public EnumBlockRenderType getRenderType(IBlockState p_getRenderType_1_) {
        return EnumBlockRenderType.MODEL;
    }

    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer() {
        return BlockRenderLayer.CUTOUT;
    }

    public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState iBlockState, EntityPlayer entityPlayer, EnumHand enumHand, EnumFacing enumFacing, float p_float_1, float p_float_2, float p_float_3) {
        if (entityPlayer.getHeldItem(enumHand).getItem()== ModItems.lens_of_truth&&!iBlockState.getValue(VISIBLE)){
            iBlockState.cycleProperty(VISIBLE);
        } else if (iBlockState.getValue(VISIBLE)){
            iBlockState.cycleProperty(VISIBLE);
        }
        return true;
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }

    @SuppressWarnings("deprecation")
    public EnumPushReaction getMobilityFlag(IBlockState p_getMobilityFlag_1_) {
        return EnumPushReaction.IGNORE;
    }

}

 

And the TileEntity:

import com.cruelar.cruelars_triforcemod.blocks.Hidden_Block;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class Hidden_Block_TileEntity extends TileEntity implements ITickable {
    private EntityPlayer entityPlayer;

    @Override
    public void update() {
        entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        if (entityPlayer!=null){
           if ((entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth) && this.isVisible()) {
               Hidden_Block.setState(false,this.getWorld(),this.getPos());
           }
       }
        if (!this.isVisible()) {
            Hidden_Block.setState(true,this.getWorld(),this.getPos());
            //this.getWorld().getBlockState(this.pos).cycleProperty(Hidden_Block.VISIBLE);
            entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        }
        entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
    }

    public Hidden_Block_TileEntity(){

    }

    @SideOnly(Side.CLIENT)
    public boolean isVisible(){
        return this.getWorld().getBlockState(this.getPos()).getValue(Hidden_Block.VISIBLE);
    }
}

 

I think there's something false with the way I Change the Visibility.

Edited by _Cruelar_
See title

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites
  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Code style, issue 2. You have this VISIBLE property, which you store in metadata. But then you seem to also have two different blocks, one suffixed "visible". This makes no sense. You only need

Yes. And also the fact that you have two blocks.

Why is entityPlayer a field? Do not blindly return true from shouldRefresh. You must actually perform logic about when you want the tile entity to be replaced (return true) or not (return false

4 hours ago, _Cruelar_ said:

So my Problem is I try to make an invisible block that is visible if the Player Helds a specific Item. I've already found out that tickable TileEntities are the best way for that. But as I tried nothing happened. So could someone help me, with that,please?

What is it doing exactly that is wrong.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to post
Share on other sites
  • 2 weeks later...

Changed the Code according to Problematic code #4 by diesieben07. I get an error now when I switch to my item triggering the change

Spoiler

[15:13:59] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking entity
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:771) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:666) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
Caused by: java.lang.NullPointerException
    at net.minecraft.pathfinding.WalkNodeProcessor.getSafePoint(WalkNodeProcessor.java:192) ~[WalkNodeProcessor.class:?]
    at net.minecraft.pathfinding.WalkNodeProcessor.findPathOptions(WalkNodeProcessor.java:114) ~[WalkNodeProcessor.class:?]
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:82) ~[PathFinder.class:?]
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:40) ~[PathFinder.class:?]
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:30) ~[PathFinder.class:?]
    at net.minecraft.pathfinding.PathNavigate.getPathToPos(SourceFile:114) ~[PathNavigate.class:?]
    at net.minecraft.pathfinding.PathNavigateGround.getPathToPos(SourceFile:51) ~[PathNavigateGround.class:?]
    at net.minecraft.pathfinding.PathNavigate.getPathToXYZ(SourceFile:93) ~[PathNavigate.class:?]
    at net.minecraft.pathfinding.PathNavigate.tryMoveToXYZ(SourceFile:143) ~[PathNavigate.class:?]
    at net.minecraft.entity.ai.EntityAIWander.startExecuting(SourceFile:65) ~[EntityAIWander.class:?]
    at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(SourceFile:102) ~[EntityAITasks.class:?]
    at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:763) ~[EntityLiving.class:?]
    at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2347) ~[EntityLivingBase.class:?]
    at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:577) ~[EntityLiving.class:?]
    at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:45) ~[EntityMob.class:?]
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2167) ~[EntityLivingBase.class:?]
    at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:295) ~[EntityLiving.class:?]
    at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:50) ~[EntityMob.class:?]
    at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1986) ~[World.class:?]
    at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:831) ~[WorldServer.class:?]
    at net.minecraft.world.World.updateEntity(World.java:1948) ~[World.class:?]
    at net.minecraft.world.World.updateEntities(World.java:1755) ~[World.class:?]
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:612) ~[WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:765) ~[MinecraftServer.class:?]
    ... 4 more
[15:13:59] [Server thread/ERROR]: This crash report has been saved to: C:\Users\lars\Desktop\Ordner\Minecraft\Mods\Cruelars Triforcemod\run\.\crash-reports\crash-2018-07-15_15.13.59-server.txt
[15:13:59] [Server thread/INFO]: Stopping server
[15:13:59] [Server thread/INFO]: Saving players
[15:13:59] [main/INFO]: [net.minecraft.init.Bootstrap:printToSYSOUT:553]: ---- Minecraft Crash Report ----
// I just don't know what went wrong :(

Time: 7/15/18 3:13 PM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
    at net.minecraft.pathfinding.WalkNodeProcessor.getSafePoint(WalkNodeProcessor.java:192)
    at net.minecraft.pathfinding.WalkNodeProcessor.findPathOptions(WalkNodeProcessor.java:114)
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:82)
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:40)
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:30)
    at net.minecraft.pathfinding.PathNavigate.getPathToPos(SourceFile:114)
    at net.minecraft.pathfinding.PathNavigateGround.getPathToPos(SourceFile:51)
    at net.minecraft.pathfinding.PathNavigate.getPathToXYZ(SourceFile:93)
    at net.minecraft.pathfinding.PathNavigate.tryMoveToXYZ(SourceFile:143)
    at net.minecraft.entity.ai.EntityAIWander.startExecuting(SourceFile:65)
    at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(SourceFile:102)
    at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:763)
    at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2347)
    at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:577)
    at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:45)
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2167)
    at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:295)
    at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:50)
    at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1986)
    at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:831)
    at net.minecraft.world.World.updateEntity(World.java:1948)
    at net.minecraft.world.World.updateEntities(World.java:1755)
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:612)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:765)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:666)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524)
    at java.lang.Thread.run(Thread.java:748)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
    at net.minecraft.pathfinding.WalkNodeProcessor.getSafePoint(WalkNodeProcessor.java:192)
    at net.minecraft.pathfinding.WalkNodeProcessor.findPathOptions(WalkNodeProcessor.java:114)
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:82)
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:40)
    at net.minecraft.pathfinding.PathFinder.findPath(SourceFile:30)
    at net.minecraft.pathfinding.PathNavigate.getPathToPos(SourceFile:114)
    at net.minecraft.pathfinding.PathNavigateGround.getPathToPos(SourceFile:51)
    at net.minecraft.pathfinding.PathNavigate.getPathToXYZ(SourceFile:93)
    at net.minecraft.pathfinding.PathNavigate.tryMoveToXYZ(SourceFile:143)
    at net.minecraft.entity.ai.EntityAIWander.startExecuting(SourceFile:65)
    at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(SourceFile:102)
    at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:763)
    at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2347)
    at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:577)
    at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:45)
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2167)
    at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:295)
    at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:50)
    at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1986)
    at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:831)
    at net.minecraft.world.World.updateEntity(World.java:1948)

-- Entity being ticked --
Details:
    Entity Type: cruelars_triforcemod:textures/entity/bokoblin.png (com.cruelar.cruelars_triforcemod.entities.monster.Bokoblin)
    Entity ID: 153
    Entity Name: Bokoblin
    Entity's Exact location: 235.34, 95.00, 260.77
    Entity's Block location: World: (235,95,260), Chunk: (at 11,5,4 in 14,16; contains blocks 224,0,256 to 239,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: 0.00, -0.08, 0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.world.World.updateEntities(World.java:1755)
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:612)

-- Affected level --
Details:
    Level name: Triforce Test
    All players: 1 total; [EntityPlayerMP['Player560'/314, l='Triforce Test', x=231.94, y=95.00, z=263.69]]
    Chunk stats: ServerChunkCache: 626 Drop: 0
    Level seed: -7073363584905754142
    Level generator: ID 00 - default, ver 1. Features enabled: true
    Level generator options:
    Level spawn location: World: (172,64,212), Chunk: (at 12,4,4 in 10,13; contains blocks 160,0,208 to 175,255,223), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 1158986 game time, 16630 day time
    Level dimension: 0
    Level storage version: 0x04ABD - Anvil
    Level weather: Rain time: 96339 (now: false), thunder time: 154304 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:765)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:666)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524)
    at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_152, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 140866112 bytes (134 MB) / 923271168 bytes (880 MB) up to 1883242496 bytes (1796 MB)
    JVM Flags: 0 total;
    IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
    FML: MCP 9.42 Powered by Forge 14.23.1.2555 9 mods loaded, 9 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State              | ID                                         | Version            | Source                                                   | Signature |
    |:--------------   |:---------------------------   |:----------------- |:------------------------------------------ |:--------- |
    | UCHIJAAAA | minecraft                        | 1.12.2                | minecraft.jar                                       | None      |
    | UCHIJAAAA | mcp                                   | 9.42                   | minecraft.jar                                       | None      |
    | UCHIJAAAA | FML                                    | 8.0.99.99         | forgeBin-1.12.2-14.23.1.2555.jar | None      |
    | UCHIJAAAA | forge                                  | 14.23.1.2555 | forgeBin-1.12.2-14.23.1.2555.jar | None      |
    | UCHIJAAAA | cruelars_triforcemod | 0.4.1                 | Cruelars_Triforcemod_main         | None      |
    | UCHIJAAAA | journeymap                    | 1.12.2-5.5.2   | journeymap-1.12.2-5.5.2.jar         | None      |
    | UCHIJAAAA | baubles                            | 1.5.2                  | Baubles-Mod-1.12.2.jar                  | None      |
    | UCHIJAAAA | ichunutil                          | 7.1.4                  | iChunUtil-1.12.2-7.1.4.jar              | None      |
    | UCHIJAAAA | tabula                               | 7.0.0                  | Tabula-1.12.2-7.0.0-deobf.jar      | None      |

    Loaded coremods (and transformers):
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['Player560'/314, l='Triforce Test', x=231.94, y=95.00, z=263.69]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'
[15:13:59] [main/INFO]: [net.minecraft.init.Bootstrap:printToSYSOUT:553]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2018-07-15_15.13.59-server.txt
[15:13:59] [main/INFO]: Waiting for the server to terminate/save.
[15:13:59] [Server thread/INFO]: Saving worlds
[15:13:59] [Server thread/INFO]: Saving chunks for level 'Triforce Test'/overworld
[15:13:59] [Server thread/INFO]: Saving chunks for level 'Triforce Test'/the_nether
[15:13:59] [Server thread/INFO]: Saving chunks for level 'Triforce Test'/the_end
[15:13:59] [Server thread/INFO]: Mapping halted in .\journeymap\data\sp\Triforce Test\DIM0
[15:14:00] [Server thread/INFO]: Unloading dimension 0
[15:14:00] [Server thread/INFO]: Unloading dimension -1
[15:14:00] [Server thread/INFO]: Unloading dimension 1
[15:14:00] [Server thread/INFO]: Applying holder lookups
[15:14:00] [Server thread/INFO]: Holder lookups applied
[15:14:00] [Server thread/INFO]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[15:14:00] [main/INFO]: Server terminated.
[15:14:00] [Client Shutdown Thread/INFO]: Stopping server
[15:14:00] [Client Shutdown Thread/INFO]: Saving players
AL lib: (EE) alc_cleanup: 1 device not closed

Process finished with exit code -1

 

 

I changed only the block:

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModBlocks;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import static com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod.CRUELARS_TRIFORCEMOD;

public class Hidden_Block extends Block {
    public static final PropertyBool VISIBLE = PropertyBool.create("visible");
    private static boolean keepInventory;

    public Hidden_Block(boolean visibility){
        super(Material.ROCK);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VISIBLE,visibility));
        String name="";
        if (visibility){
            name="_visible";
        }
        this.setRegistryName("hidden_block"+name);
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".hidden_block"+name);
        this.setCreativeTab(CRUELARS_TRIFORCEMOD);
    }

    @MethodsReturnNonnullByDefault
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[]{VISIBLE});
    }

    @Override
    @SuppressWarnings("deprecation")
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState()
                .withProperty(VISIBLE, meta!=0);

    }

    public static void setState(boolean p_setState_0_, World p_setState_1_, BlockPos p_setState_2_) {
        IBlockState lvt_3_1_ = p_setState_1_.getBlockState(p_setState_2_);
        TileEntity lvt_4_1_ = p_setState_1_.getTileEntity(p_setState_2_);
        keepInventory = true;
        if (!p_setState_0_) {
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block.getDefaultState(), 3);
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block.getDefaultState(), 3);
        } else {
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block_visible.getDefaultState(), 3);
            p_setState_1_.setBlockState(p_setState_2_, ModBlocks.hidden_block_visible.getDefaultState(), 3);
        }

        keepInventory = false;
        if (lvt_4_1_ != null) {
            lvt_4_1_.validate();
            p_setState_1_.setTileEntity(p_setState_2_, lvt_4_1_);
        }

    }

    @SuppressWarnings("deprecation")
    public IBlockState getActualState(IBlockState iBlockState,IBlockAccess iBlockAccess, BlockPos blockPos) {
        return iBlockState;
    }

    public int getMetaFromState(IBlockState blockState) {
        int i = 0;
        if ((boolean)blockState.getValue(VISIBLE)){
            i |= 2;
        }
        return i;
    }

    @Override
    public TileEntity createTileEntity(World world, IBlockState iBlockState){
        return new Hidden_Block_TileEntity();
    }

    public boolean hasTileEntity(IBlockState p_hasTileEntity_1_) {
        return true;
    }

    @SuppressWarnings("deprecation")
    public boolean isOpaqueCube(IBlockState p_isOpaqueCube_1_) {
        return false;
    }

    @SuppressWarnings("deprecation")
    public EnumBlockRenderType getRenderType(IBlockState p_getRenderType_1_) {
        return EnumBlockRenderType.MODEL;
    }

    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer() {
        return BlockRenderLayer.CUTOUT;
    }

    public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState iBlockState, EntityPlayer entityPlayer, EnumHand enumHand, EnumFacing enumFacing, float p_float_1, float p_float_2, float p_float_3) {
        if (entityPlayer.getHeldItem(enumHand).getItem()== ModItems.lens_of_truth&&!iBlockState.getValue(VISIBLE)){
            iBlockState.cycleProperty(VISIBLE);
        } else if (iBlockState.getValue(VISIBLE)){
            iBlockState.cycleProperty(VISIBLE);
        }
        return true;
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }

    @SuppressWarnings("deprecation")
    public EnumPushReaction getMobilityFlag(IBlockState p_getMobilityFlag_1_) {
        return EnumPushReaction.IGNORE;
    }

}

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites
  • Code style, issue 2.
  • You have this VISIBLE property, which you store in metadata. But then you seem to also have two different blocks, one suffixed "visible". This makes no sense. You only need the metadata property. Also, do not use that gross "keep my tile entity" hack that you copied from the vanilla furnace. Override shouldRefresh in your TileEntity instead.
  • What are those parameter names?!
  • Thanks 1
Link to post
Share on other sites
  1. I've recognized the code style issue the moment I posted the code
  2. with the copy of the Furnace you mean setState?
  3. the parameter names are mostly copied from Minecraft or the name of the class of the object. I'm working on a documentation and will change the names then

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

So like this?

The TileEntity:

package com.cruelar.cruelars_triforcemod.tileentity;

import com.cruelar.cruelars_triforcemod.blocks.Hidden_Block;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class Hidden_Block_TileEntity extends TileEntity implements ITickable {
    private EntityPlayer entityPlayer;

    @Override
    public void update() {
        entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        if (entityPlayer!=null){
           if ((entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth) && this.isVisible()) {
               this.getWorld().getBlockState(this.getPos()).cycleProperty(Hidden_Block.VISIBLE);
           }
       }
        if (!this.isVisible()) {
            this.getWorld().getBlockState(this.pos).cycleProperty(Hidden_Block.VISIBLE);
            entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        }
        entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
    }

    public Hidden_Block_TileEntity(){

    }

    @SideOnly(Side.CLIENT)
    public boolean isVisible(){
        return this.getWorld().getBlockState(this.getPos()).getValue(Hidden_Block.VISIBLE);
    }

    @Override
    public boolean shouldRefresh(World p_shouldRefresh_1_, BlockPos p_shouldRefresh_2_, IBlockState p_shouldRefresh_3_, IBlockState p_shouldRefresh_4_) {
        return true;
    }
}

 

The Block:

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModBlocks;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import static com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod.CRUELARS_TRIFORCEMOD;

public class Hidden_Block extends Block {
    public static final PropertyBool VISIBLE = PropertyBool.create("visible");
    private static boolean keepInventory;

    public Hidden_Block(){
        super(Material.ROCK);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VISIBLE,true));
        this.setRegistryName("hidden_block");
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".hidden_block");
        this.setCreativeTab(CRUELARS_TRIFORCEMOD);
    }

    @MethodsReturnNonnullByDefault
    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[]{VISIBLE});
    }

    @Override
    @SuppressWarnings("deprecation")
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState()
                .withProperty(VISIBLE, meta!=0);

    }

    @SuppressWarnings("deprecation")
    @Override
    public IBlockState getActualState(IBlockState iBlockState,IBlockAccess iBlockAccess, BlockPos blockPos) {
        return iBlockState;
    }

    @Override
    public int getMetaFromState(IBlockState blockState) {
        int i = 0;
        if ((boolean)blockState.getValue(VISIBLE)){
            i |= 2;
        }
        return i;
    }

    @Override
    public TileEntity createTileEntity(World world, IBlockState iBlockState){
        return new Hidden_Block_TileEntity();
    }

    @Override
    public boolean hasTileEntity(IBlockState p_hasTileEntity_1_) {
        return true;
    }

    @SuppressWarnings("deprecation")
    @Override
    public boolean isOpaqueCube(IBlockState p_isOpaqueCube_1_) {
        return false;
    }

    @Override
    @SuppressWarnings("deprecation")
    public EnumBlockRenderType getRenderType(IBlockState p_getRenderType_1_) {
        return EnumBlockRenderType.MODEL;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer() {
        return BlockRenderLayer.CUTOUT;
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState iBlockState, EntityPlayer entityPlayer, EnumHand enumHand, EnumFacing enumFacing, float p_float_1, float p_float_2, float p_float_3) {
        if (entityPlayer.getHeldItem(enumHand).getItem()== ModItems.lens_of_truth&&!iBlockState.getValue(VISIBLE)){
            iBlockState.cycleProperty(VISIBLE);
        } else if (iBlockState.getValue(VISIBLE)){
            iBlockState.cycleProperty(VISIBLE);
        }
        return true;
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
    }

    @Override
    @SuppressWarnings("deprecation")
    public EnumPushReaction getMobilityFlag(IBlockState p_getMobilityFlag_1_) {
        return EnumPushReaction.IGNORE;
    }

}

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites
  • Why is entityPlayer a field?
  • Do not blindly return true from shouldRefresh. You must actually perform logic about when you want the tile entity to be replaced (return true) or not (return false). Note: This method will be called when your block is replaced by any other block (including air). Only return false if you actually want the tile entity to stay.
  • Why is keepInventory still there?

Other than that, looks okay.

  • Thanks 1
Link to post
Share on other sites

Is this better?

@Override
    public boolean shouldRefresh(World p_shouldRefresh_1_, BlockPos p_shouldRefresh_2_, IBlockState firstBlockState, IBlockState secondBlockState) {
        return firstBlockState.getBlock() != secondBlockState.getBlock();
    }

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

So I get no error, the blocks have the right texture when placed but the textures still doesn't change when I held the lens of truth(look in the code it's the Item triggering the change. In theory at least)

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

Thanks for saying me that I've missed something quite clear

@Override
    public void update() {
        EntityPlayer entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        if (entityPlayer!=null){
           if ((entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth) && this.isVisible()) {
               this.getWorld().getBlockState(this.getPos()).cycleProperty(Hidden_Block.VISIBLE);
           }
       }
        if (!this.isVisible()&&!(entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth)) {
            this.getWorld().getBlockState(this.pos).cycleProperty(Hidden_Block.VISIBLE);
            entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        }
        entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
    }

 

!this.isVisible()&&!(entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth

This should fix that, doesn't it?

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

There was a NullPointerException at if (!this.isVisible()&&!(entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth))

the entityPlayer might be null.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

Why are you making this so complicated for yourself?

Pseudocode:

if (player != null) {
    boolean isVisible = isVisible();
    boolean shouldBeVisible = player.hasYourItem();

   if (isVisible != shouldBeVisible) {
       world.setBlockState(pos, world.getBlockState(pos).withProperty(VISIBLE, shouldBeVisible));
   }
}

 

Edited by diesieben07
Link to post
Share on other sites

Like this?

@Override
    public void update() {
        EntityPlayer entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);
        if (entityPlayer!=null){
            boolean visible = isVisible();
            boolean shouldBeVisible = entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth;
            if (visible!=shouldBeVisible){
                world.setBlockState(pos, world.getBlockState(pos).withProperty(Hidden_Block.VISIBLE, shouldBeVisible));
            }
        }
    }

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

When I test with System.out.println(entityPlayer) it prints null so the problem is

this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, true);

doesn't find me.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites
  1. What happens when I pass false
  2. Thanks this I didn't know
  3. also doesn't work in survival
  4. only searching the Player on Serverside or update()?

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

So what is false?

Spoiler

[18:31:50] [Server thread/INFO]: Preparing start region for level 0
[18:31:51] [Server thread/INFO]: Preparing spawn area: 56%
[18:31:52] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking block entity
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:771) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:666) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:185) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:524) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
Caused by: java.lang.NoSuchMethodError: com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity.getPlayer()Lnet/minecraft/entity/player/EntityPlayer;
    at com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity.update(Hidden_Block_TileEntity.java:21) ~[Hidden_Block_TileEntity.class:?]
    at net.minecraft.world.World.updateEntities(World.java:1829) ~[World.class:?]
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:612) ~[WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:765) ~[MinecraftServer.class:?]
    ... 4 more
[18:31:52] [Server thread/ERROR]: This crash report has been saved to: C:\Users\lars\Desktop\Ordner\Minecraft\Mods\Cruelars Triforcemod\run\.\crash-reports\crash-2018-07-15_18.31.52-server.txt
[18:31:52] [Server thread/INFO]: Stopping server
[18:31:52] [Server thread/INFO]: Saving players
[18:31:52] [Server thread/INFO]: Saving worlds
[18:31:52] [Server thread/INFO]: Saving chunks for level 'Triforce Test'/overworld
[18:31:52] [Server thread/INFO]: Saving chunks for level 'Triforce Test'/the_nether
[18:31:52] [Server thread/INFO]: Saving chunks for level 'Triforce Test'/the_end
[18:31:52] [Server thread/ERROR]: ExecutionException in getPlayer: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2217)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4154)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at journeymap.client.data.DataCache.getPlayer(DataCache.java:303)
    at journeymap.client.data.DataCache.getPlayer(DataCache.java:190)
    at journeymap.client.forge.event.WorldEventHandler.onUnload(WorldEventHandler.java:33)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_67_WorldEventHandler_onUnload_Unload.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:452)
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:372)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:577)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4153)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153)
    at journeymap.client.data.DataCache.getEntityDTO(DataCache.java:441)
    at journeymap.client.data.PlayerData.load(PlayerData.java:86)
    at journeymap.client.data.PlayerData.load(PlayerData.java:30)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211)
    ... 13 more

[18:31:52] [Server thread/ERROR]: Error handling WorldEvent.Unload
java.lang.NullPointerException: null
    at journeymap.client.forge.event.WorldEventHandler.onUnload(WorldEventHandler.java:33) [WorldEventHandler.class:1.12.2-5.5.2]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_67_WorldEventHandler_onUnload_Unload.invoke(.dynamic) [?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) [ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) [EventBus.class:?]
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:452) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:372) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:577) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
[18:31:52] [Server thread/ERROR]: ExecutionException in getPlayer: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2217)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4154)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at journeymap.client.data.DataCache.getPlayer(DataCache.java:303)
    at journeymap.client.data.DataCache.getPlayer(DataCache.java:190)
    at journeymap.client.forge.event.WorldEventHandler.onUnload(WorldEventHandler.java:33)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_67_WorldEventHandler_onUnload_Unload.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:452)
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:372)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:577)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4153)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153)
    at journeymap.client.data.DataCache.getEntityDTO(DataCache.java:441)
    at journeymap.client.data.PlayerData.load(PlayerData.java:86)
    at journeymap.client.data.PlayerData.load(PlayerData.java:30)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211)
    ... 13 more

[18:31:52] [Server thread/ERROR]: Error handling WorldEvent.Unload
java.lang.NullPointerException: null
    at journeymap.client.forge.event.WorldEventHandler.onUnload(WorldEventHandler.java:33) [WorldEventHandler.class:1.12.2-5.5.2]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_67_WorldEventHandler_onUnload_Unload.invoke(.dynamic) [?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) [ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) [EventBus.class:?]
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:452) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:372) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:577) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
[18:31:52] [Server thread/ERROR]: ExecutionException in getPlayer: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2217)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4154)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at journeymap.client.data.DataCache.getPlayer(DataCache.java:303)
    at journeymap.client.data.DataCache.getPlayer(DataCache.java:190)
    at journeymap.client.forge.event.WorldEventHandler.onUnload(WorldEventHandler.java:33)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_67_WorldEventHandler_onUnload_Unload.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:452)
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:372)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:577)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4153)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153)
    at journeymap.client.data.DataCache.getEntityDTO(DataCache.java:441)
    at journeymap.client.data.PlayerData.load(PlayerData.java:86)
    at journeymap.client.data.PlayerData.load(PlayerData.java:30)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211)
    ... 13 more

[18:31:52] [Server thread/ERROR]: Error handling WorldEvent.Unload
java.lang.NullPointerException: null
    at journeymap.client.forge.event.WorldEventHandler.onUnload(WorldEventHandler.java:33) [WorldEventHandler.class:1.12.2-5.5.2]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_67_WorldEventHandler_onUnload_Unload.invoke(.dynamic) [?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) [ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) [EventBus.class:?]
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:452) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:372) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:577) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
[18:31:52] [Server thread/INFO]: Unloading dimension 0
[18:31:52] [Server thread/INFO]: Unloading dimension -1
[18:31:52] [Server thread/INFO]: Unloading dimension 1
[18:31:52] [Server thread/INFO]: Applying holder lookups
[18:31:52] [Server thread/INFO]: Holder lookups applied
[18:31:52] [Server thread/INFO]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.

 

TileEntity:

package com.cruelar.cruelars_triforcemod.tileentity;

import com.cruelar.cruelars_triforcemod.blocks.Hidden_Block;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;

public class Hidden_Block_TileEntity extends TileEntity implements ITickable {

    @Override
    public void update() {
        EntityPlayer entityPlayer = (EntityPlayer) getPlayer();
        if (entityPlayer!=null){
            boolean visible = isVisible();
            boolean shouldBeVisible = entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth;
            if (visible!=shouldBeVisible){
                world.setBlockState(pos, world.getBlockState(pos).withProperty(Hidden_Block.VISIBLE, shouldBeVisible));
            }
        }
        System.out.println(entityPlayer);
           
    }

    public Hidden_Block_TileEntity(){

    }

    
    @SideOnly(Side.SERVER)
    public EntityPlayer getPlayer(){
        return this.getWorld().getClosestPlayer(this.pos.getX(),this.pos.getY(),this.pos.getZ(),-1.0,false);
    }

    @SideOnly(Side.CLIENT)
    public boolean isVisible(){
        return this.getWorld().getBlockState(this.getPos()).getValue(Hidden_Block.VISIBLE);
    }

    @Override
    public boolean shouldRefresh(World p_shouldRefresh_1_, BlockPos p_shouldRefresh_2_, IBlockState firstBlockState, IBlockState secondBlockState) {
        return firstBlockState.getBlock() != secondBlockState.getBlock();
    }
}

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites
11 minutes ago, _Cruelar_ said:

What happens when I pass false

Read the code. It will exclude only spectators.

 

11 minutes ago, _Cruelar_ said:

only searching the Player on Serverside or update()?

You should only be searching for the player and updating the block on the server.

 

2 minutes ago, _Cruelar_ said:

@SideOnly(Side.SERVER)

That is not how any of this works. Read and understand the documentation about sides to understand why this is a terrible idea and does, in fact, not work.

  • Thanks 1
Link to post
Share on other sites

So I should use this?

@Override
    public void update() {
        if (!this.getWorld().isRemote) 
        {
            EntityPlayer entityPlayer = (EntityPlayer) this.getWorld().getClosestPlayer(this.pos.getX(), this.pos.getY(), this.pos.getZ(), -1.0, false);
            if (entityPlayer != null) {
                boolean visible = isVisible();
                boolean shouldBeVisible = entityPlayer.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.lens_of_truth || entityPlayer.getHeldItem(EnumHand.OFF_HAND).getItem() == ModItems.lens_of_truth;
                if (visible != shouldBeVisible) {
                    world.setBlockState(pos, world.getBlockState(pos).withProperty(Hidden_Block.VISIBLE, shouldBeVisible));
                }
            }
            System.out.println(entityPlayer);
        }

    }

 

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.