Posted September 5, 20169 yr When I place down a block and right click it, I want to change the blockstate. But when I right click the block, it changes blockstates for a second before switching back. Here is the code: Block public class BlockSentry extends Block implements ISpecialBlock, ITileEntityProvider { public static final PropertyEnum LEVEL = PropertyEnum.create("level", BlockSentry.EnumLevel.class); public static final PropertyEnum TEAM = PropertyEnum.create("team", EnumTeam.class); public BlockSentry (Material material) { super(material); setDefaultState(blockState.getBaseState().withProperty(LEVEL, EnumLevel.ONE).withProperty(TEAM, EnumTeam.BLU)); } @Override protected BlockStateContainer createBlockState () { return new BlockStateContainer(this, new IProperty[] { LEVEL, TEAM }); } @Override public IBlockState getStateFromMeta (int meta) { switch (meta) { case 0: return getDefaultState().withProperty(LEVEL, EnumLevel.MINI).withProperty(TEAM, EnumTeam.BLU); case 1: return getDefaultState().withProperty(LEVEL, EnumLevel.ONE).withProperty(TEAM, EnumTeam.BLU); case 2: return getDefaultState().withProperty(LEVEL, EnumLevel.TWO).withProperty(TEAM, EnumTeam.BLU); case 3: return getDefaultState().withProperty(LEVEL, EnumLevel.THREE).withProperty(TEAM, EnumTeam.BLU); case 4: return getDefaultState().withProperty(LEVEL, EnumLevel.MINI).withProperty(TEAM, EnumTeam.RED); case 5: return getDefaultState().withProperty(LEVEL, EnumLevel.ONE).withProperty(TEAM, EnumTeam.RED); case 6: return getDefaultState().withProperty(LEVEL, EnumLevel.TWO).withProperty(TEAM, EnumTeam.RED); case 7: return getDefaultState().withProperty(LEVEL, EnumLevel.THREE).withProperty(TEAM, EnumTeam.RED); } return getDefaultState().withProperty(LEVEL, EnumLevel.MINI).withProperty(TEAM, EnumTeam.BLU); } @Override public boolean onBlockActivated (World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntitySentry) { TileEntitySentry sentry = (TileEntitySentry)tile; if (heldItem != null) { if (heldItem.getItem() == TFCItems.wrench) { worldIn.setBlockState(pos, getStateFromMeta(6)); } } } } return true; } @Override public TileEntity createNewTileEntity (World worldIn, int meta) { return new TileEntitySentry(meta); } } TileEntity public class TileEntitySentry extends TileEntity { public static int level; private static int meta; public TileEntitySentry (int meta) { level = getLevelFromMeta(meta); this.meta = meta; } public void setLevel (int level) { this.level = level; } public int getLevel () { return level; } public int getMeta () { return meta; } @Override public NBTTagCompound writeToNBT (NBTTagCompound compound) { super.writeToNBT(compound); compound.setTag("sentry", new NBTTagList()); NBTTagCompound sentry = compound.getCompoundTag("sentry"); sentry.setInteger("level", level); return compound; } @Override public void readFromNBT (NBTTagCompound compound) { super.readFromNBT(compound); level = compound.getInteger("level"); } private int getLevelFromMeta (int meta) { switch (meta) { case 0: return 0; case 1: return 1; case 2: return 2; case 3: return 3; case 4: return 0; case 5: return 1; case 6: return 2; case 7: return 3; } return 0; } @Override public boolean shouldRefresh (World world, BlockPos pos, IBlockState old, IBlockState newState) { return false; } } MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
September 5, 20169 yr if (worldIn.isRemote) Lets only do this on the client because the server has control over everything. Why? Raisins. 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.
September 5, 20169 yr World#isRemote is true on the client and false on the server. The server is in control of the game state, but you're making your changes on the client so they get overwritten the next time it syncs. Side note: Consider using bitwise operations when storing multiple values in metadata instead of using harcoded metadata values for each combination. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
September 5, 20169 yr Author if (worldIn.isRemote) Lets only do this on the client because the server has control over everything. Why? Raisins. I'm stupid... thank you MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
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.