方块状态导致的奇怪问题
#111
-
public class block_1 extends Block
{
public static final PropertyBool ACTIVATION = PropertyBool.create("activation");
public block_1(){
super(Material.ROCK, MapColor.LIGHT_BLUE);
this.setDefaultState(this.blockState.getBaseState().withProperty(ACTIVATION, false));
}
public static class block_1Entity extends TileEntity{
public block_1Entity(){}
private boolean event_activation;
public void setEventActivation(boolean bool){
this.event_activation = bool;
IBlockState newState = world.getBlockState(this.pos).withProperty(ACTIVATION, bool);
world.setBlockState(pos,newState);
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(world.isRemote){return true;}
block_1.block_1Entity tile = (block_1.block_1Entity)world.getTileEntity(pos);
tile.setEventActivation(true);
return true;
}
@Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this,ACTIVATION);
}
@Override
public int getMetaFromState(IBlockState state){
return 0;
}
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new block_1Entity();
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
bfwqzj
Jun 23, 2021
Replies: 1 comment
-
问题解决了,setBlockState在改变BlockState的同时会改变游戏内Block的实例 需要重新getTileEntity |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Snownee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题解决了,setBlockState在改变BlockState的同时会改变游戏内Block的实例 需要重新getTileEntity