public static IBlockState rotate(@Nonnull IBlockState paintSource) { // TODO: Need to handle cases like stairs that have 'upper' and 'lower' so they are included in the rotation // cycle for (IProperty<?> prop : paintSource.getPropertyKeys()) { if (prop instanceof PropertyDirection) { return paintSource.cycleProperty(prop); } else if (prop == BlockSlab.HALF) { return paintSource.cycleProperty(prop); } } if (paintSource.getBlock() instanceof BlockLog) { return paintSource.cycleProperty(BlockLog.LOG_AXIS); } return paintSource; }
private static IBlockState cyclePropertyBackwards(IBlockState state, IProperty<?> property) { IBlockState result = state; for (int i = 0; i < property.getAllowedValues().size() - 1; i++) { result = result.cycleProperty(property); } return result; }
@Override public @Nonnull <T extends Comparable<T>> IBlockState cycleProperty(@Nonnull IProperty<T> property) { return new BlockStateWrapperBase(this, state.cycleProperty(property)); }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack heldItem = playerIn.getHeldItem(hand); if (!playerIn.capabilities.allowEdit) { return false; } else { final int MARK_BLOCKS_FOR_UPDATE_FLAG = 2; final int NOTIFY_NEIGHBOURS_FLAG = 1; worldIn.setBlockState(pos, state.cycleProperty(POWER_INDEX), MARK_BLOCKS_FOR_UPDATE_FLAG | NOTIFY_NEIGHBOURS_FLAG); return true; } }
@Override public boolean rotateBlock(net.minecraft.world.World world, BlockPos pos, EnumFacing axis) { net.minecraft.block.state.IBlockState state = world.getBlockState(pos); for(net.minecraft.block.properties.IProperty<?> prop : state.getProperties().keySet()) { if(prop == BlockRotatedPillar.AXIS) { world.setBlockState(pos, state.cycleProperty(prop)); return true; } } return false; }
@Override public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { if (state.getValue(STAGE).intValue() == 0) { worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4); } else { generateTree(worldIn, pos, state, rand); } }
@Override public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) { IBlockState state = world.getBlockState(pos); for (IProperty<?> prop : state.getProperties().keySet()) { if (prop == BlockRotatedPillar.AXIS) { world.setBlockState(pos, state.cycleProperty(prop)); return true; } } return false; }
@Override public boolean rotateBlock(net.minecraft.world.World world, BlockPos pos, EnumFacing axis) { net.minecraft.block.state.IBlockState state = world.getBlockState(pos); for (net.minecraft.block.properties.IProperty<?> prop : state.getProperties().keySet()) { if (prop.getName().equals("axis")) { world.setBlockState(pos, state.cycleProperty(prop)); return true; } } return false; }
public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (state.getValue(STAGE) == 0) { worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4); } else { generateTree(worldIn, pos, state, rand); } }
@Override public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { if (state.getValue(STAGE) == 0) { worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4); } else { this.generateTree(worldIn, pos, state, rand); } }
public void grow(World world, BlockPos pos, IBlockState state, Random rand) { if (state.getValue(STAGE) == 0) { world.setBlockState(pos, state.cycleProperty(STAGE), 4); } else { this.treeType.getTreeGenerator().generate(world, rand, pos); } }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack heldItem = player.getHeldItem(hand); if (state.getValue(IS_BURST) && heldItem != null && ItemStackUtility.isItemOreDictedAs(heldItem, OreDictEntries.PLATE_THIN_ZINC)) { state.cycleProperty(IS_BURST); if (!player.capabilities.isCreativeMode) { heldItem.shrink(1); } return true; } return false; }
@Override public void fillWithRain(World worldIn, BlockPos pos) { if (worldIn.rand.nextInt(2) == 0) { float f = worldIn.getBiome(pos).getTemperature(pos); if (worldIn.getBiomeProvider().getTemperatureAtHeight(f, pos.getY()) >= 0.15F) { IBlockState iblockstate = worldIn.getBlockState(pos); if (((Integer)iblockstate.getValue(LEVEL)).intValue() < 3) { worldIn.setBlockState(pos, iblockstate.cycleProperty(LEVEL), 2); } } } }
@Override public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { int blocks = 0; for (int i = 0; i < EnumFacing.VALUES.length; i++) { EnumFacing dir = EnumFacing.VALUES[i]; IBlockState neighbour = world.getBlockState(pos.offset(dir)); Block block = neighbour.getBlock(); if (!block.isAir(neighbour, world, pos)) { blocks++; } } if (blocks != 6) { int randInt; if (leafType == 3) { randInt = rand.nextInt(10); } else if (leafType < 2) { randInt = rand.nextInt(8); } else { randInt = rand.nextInt(9); } if (randInt <= 2) { LeafGrowth leaf = state.getValue(GROWTH); if (leaf.canGrow()) { world.setBlockState(pos, state.cycleProperty(GROWTH)); } } } }
@Override public void setPaintSource(@Nullable IBlockState paintSource) { super.setPaintSource(paintSource); // force re-calc of lighting for both client and server IBlockState bs = world.getBlockState(pos); IBlockState newBs = bs.withProperty(BlockConduitBundle.OPAQUE, getLightOpacity() > 0); if (bs == newBs) { world.setBlockState(getPos(), newBs.cycleProperty(BlockConduitBundle.OPAQUE)); } world.setBlockState(getPos(), newBs); forceUpdatePlayers(); // send the packet now so the re-render we just triggered will render with the new data }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { ItemStack stack = player.getHeldItem(hand); if (!stack.isEmpty() && stack.getItem() == ModItems.MATERIALS && stack.getItemDamage() == ItemMaterials.EnumErebusMaterialsType.BAMBOO_PIPE_WRENCH.ordinal()) { if (!player.isSneaking()) { state = state.cycleProperty(FACING); state.cycleProperty(FACING); world.setBlockState(pos, state, 3); return true; } else { breakBlock(world, pos, state); dropBlockAsItem(world, pos, state, 0); world.setBlockToAir(pos); return true; } } return false; } }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { ItemStack stack = player.getHeldItem(hand); if (!stack.isEmpty() && stack.getItem() == ModItems.MATERIALS && stack.getItemDamage() == ItemMaterials.EnumErebusMaterialsType.BAMBOO_PIPE_WRENCH.ordinal()) { if (!player.isSneaking()) { state = state.cycleProperty(FACING); state.cycleProperty(FACING); world.setBlockState(pos, state, 3); return true; } else { breakBlock(world, pos, state); dropBlockAsItem(world, pos, state, 0); world.setBlockToAir(pos); return true; } } else { IBlockState activeState = ModBlocks.BAMBOO_PIPE_EXTRACT_ACTIVE.getDefaultState().withProperty(BlockBambooPipeExtractActive.FACING, state.getValue(FACING)); world.setBlockState(pos, activeState, 3); world.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, 0.6F); return true; } } }
@Override public void resetTask() { if(closeDoor) { IBlockState state = entity.world.getBlockState(doorPosition).getActualState(entity.world, doorPosition); if(!state.getPropertyKeys().contains(BlockDoor.OPEN)) return; EnumFacing direction = state.getValue(BlockDoor.FACING); boolean isOpen = state.getValue(BlockDoor.OPEN); BlockDoor.EnumHingePosition isMirrored = state.getValue(BlockDoor.HINGE); BlockPos mirrorPos = doorPosition.offset(isMirrored == BlockDoor.EnumHingePosition.RIGHT ? direction.rotateYCCW() : direction.rotateY()); BlockPos doorPos = state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER ? mirrorPos : mirrorPos.down(); IBlockState other = entity.world.getBlockState(doorPos).getActualState(entity.world, doorPos); if(state.getMaterial() != Material.IRON && other.getBlock() == doorBlock && other.getValue(BlockDoor.FACING) == direction && other.getValue(BlockDoor.OPEN) == isOpen && other.getValue(BlockDoor.HINGE) != isMirrored) { IBlockState newState = other.cycleProperty(BlockDoor.OPEN); entity.world.setBlockState(doorPos, newState, 10); } doorBlock.toggleDoor(entity.world, doorPosition, false); } }
@Override public void startExecuting() { closeDoorTemporisation = 20; IBlockState state = entity.world.getBlockState(doorPosition).getActualState(entity.world, doorPosition); EnumFacing direction = state.getValue(BlockDoor.FACING); boolean isOpen = state.getValue(BlockDoor.OPEN); BlockDoor.EnumHingePosition isMirrored = state.getValue(BlockDoor.HINGE); BlockPos mirrorPos = doorPosition.offset(isMirrored == BlockDoor.EnumHingePosition.RIGHT ? direction.rotateYCCW() : direction.rotateY()); BlockPos doorPos = state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER ? mirrorPos : mirrorPos.down(); IBlockState other = entity.world.getBlockState(doorPos).getActualState(entity.world, doorPos); if(state.getMaterial() != Material.IRON && other.getBlock() == doorBlock && other.getValue(BlockDoor.FACING) == direction && other.getValue(BlockDoor.OPEN) == isOpen && other.getValue(BlockDoor.HINGE) != isMirrored) { IBlockState newState = other.cycleProperty(BlockDoor.OPEN); entity.world.setBlockState(doorPos, newState, 10); } doorBlock.toggleDoor(entity.world, doorPosition, true); }
@SubscribeEvent(priority = EventPriority.LOWEST) public void onPlayerInteract(PlayerInteractEvent.RightClickBlock event) { if(event.getEntityPlayer().isSneaking() || event.isCanceled() || event.getResult() == Result.DENY) return; World world = event.getWorld(); IBlockState state = world.getBlockState(event.getPos()).getActualState(world, event.getPos()); Block block = state.getBlock(); if(!(block instanceof BlockDoor)) return; EnumFacing direction = state.getValue(BlockDoor.FACING); boolean isOpen = state.getValue(BlockDoor.OPEN); BlockDoor.EnumHingePosition isMirrored = state.getValue(BlockDoor.HINGE); BlockPos mirrorPos = event.getPos().offset(isMirrored == BlockDoor.EnumHingePosition.RIGHT ? direction.rotateYCCW() : direction.rotateY()); BlockPos doorPos = state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER ? mirrorPos : mirrorPos.down(); IBlockState other = world.getBlockState(doorPos).getActualState(world, doorPos); if(block.getMaterial(state) != Material.IRON && other.getBlock() == (BlockDoor) block && other.getValue(BlockDoor.FACING) == direction && other.getValue(BlockDoor.OPEN) == isOpen && other.getValue(BlockDoor.HINGE) != isMirrored) { IBlockState newState = other.cycleProperty(BlockDoor.OPEN); world.setBlockState(doorPos, newState, 10); } }