Java Code Examples for net.minecraft.block.state.IBlockState#withProperty()

The following examples show how to use net.minecraft.block.state.IBlockState#withProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockBambooBlock.java    From Sakura_mod with MIT License 6 votes vote down vote up
/**
 * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
 * blockstate.
 */
public IBlockState withRotation(IBlockState state, Rotation rot)
{
    switch (rot){
        case COUNTERCLOCKWISE_90:
        case CLOCKWISE_90:

            switch (state.getValue(LOG_AXIS)){
                case X:
                    return state.withProperty(LOG_AXIS, EnumAxis.Z);
                case Z:
                    return state.withProperty(LOG_AXIS, EnumAxis.X);
                default:
                    return state;
            }

        default:
            return state;
    }
}
 
Example 2
Source File: BlockCloud.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
	super.onBlockPlacedBy(world, pos, state, placer, stack);

	boolean hasLightValue = state.getValue(HAS_LIGHT_VALUE);
	for (int i = 1; i < pos.getY(); i++) {
		if (hasLightValue) {
			if (!world.isAirBlock(pos.down(i))) {
				hasLightValue = false;
				state = state.withProperty(HAS_LIGHT_VALUE, false);
				break;
			}
		}
	}
	for (int i = 1; i < 255 - pos.getY(); i++)
		if (world.getBlockState(pos.up(i)) == getDefaultState().withProperty(HAS_LIGHT_VALUE, true))
			world.setBlockState(pos.up(i), getDefaultState().withProperty(HAS_LIGHT_VALUE, false), 2);
}
 
Example 3
Source File: MinecraftTypeHelper.java    From malmo with MIT License 6 votes vote down vote up
/** Recolour the Minecraft block
 * @param state The block to be recoloured
 * @param colour The new colour
 * @return A new blockstate which is a recoloured version of the original
 */
static IBlockState applyColour(IBlockState state, Colour colour)
{
    for (IProperty prop : state.getProperties().keySet())
    {
        if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
        {
            net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop);
            if (!current.getName().equalsIgnoreCase(colour.name()))
            {
                return state.withProperty(prop, EnumDyeColor.valueOf(colour.name()));
            }
        }
    }
    return state;
}
 
Example 4
Source File: BlockTraverseSlab.java    From Traverse-Legacy-1-12-2 with MIT License 6 votes vote down vote up
public BlockTraverseSlab(String name, Material material, SoundType soundType) {
    super(material, material.getMaterialMapColor());
    this.name = name;
    IBlockState iblockstate = this.blockState.getBaseState();

    if (!this.isDouble()) {
        iblockstate = iblockstate.withProperty(HALF, EnumBlockHalf.BOTTOM);
        setRegistryName(new ResourceLocation(TraverseConstants.MOD_ID, name + "_slab"));
        halfslab = this;
    } else {
        setRegistryName(new ResourceLocation(TraverseConstants.MOD_ID, name + "_double_slab"));
    }
    setCreativeTab(TraverseTab.TAB);
    setUnlocalizedName(getRegistryName().toString());
    setHarvestLevel("pickaxe", 0);
    setHardness(2.0F);
    setResistance(10);
    setSoundType(soundType);
    this.setDefaultState(iblockstate.withProperty(VARIANT, BlockTraverseSlab.Variant.DEFAULT));
    useNeighborBrightness=true;
    ShootingStar.registerModel(new ModelCompound(TraverseConstants.MOD_ID, this, "slab"));
}
 
Example 5
Source File: BlockMinecoprocessor.java    From Minecoprocessors with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
  super.updateTick(world, pos, state, rand);
  updateInputPorts(world, pos, state);

  if (world.isRemote) {
    return;
  }

  TileEntityMinecoprocessor te = (TileEntityMinecoprocessor) world.getTileEntity(pos);

  boolean changed = false;

  boolean blockActive = state.getValue(ACTIVE);
  boolean processorActive = !te.getProcessor().isWait() && !te.getProcessor().isFault();

  if (blockActive && !processorActive) {
    state = state.withProperty(ACTIVE, Boolean.valueOf(false));
    changed = true;
  } else if (!blockActive && processorActive) {
    state = state.withProperty(ACTIVE, Boolean.valueOf(true));
    changed = true;
  }

  if (changed) {
    world.setBlockState(pos, state, 2);
  }
}
 
Example 6
Source File: BlockLeaves.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	if(state.getValue(META_PROPERTY) == WoodType.Palm)
		return state.withProperty(FANCY, false);

	return state.withProperty(FANCY, isTransparent);

}
 
Example 7
Source File: BlockLeaves2.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	boolean fancy = true;
	if(!isTransparent)
		fancy = false;
	if(state.getValue(META_PROPERTY) == WoodType.Palm)
		fancy = false;

	return state.withProperty(BlockLeaves.FANCY, fancy);
}
 
Example 8
Source File: BlockStoneStalag.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	int size = getSize(state, world, pos);
	if(size < 3)
		return state.withProperty(SIZE_PROPERTY, size);
	return state.withProperty(SIZE_PROPERTY, 0);
}
 
Example 9
Source File: BlockComponentBox.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public IBlockState withRotation(IBlockState state, Rotation rot)
{
	return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
 
Example 10
Source File: BlockTFOven.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
 * blockstate.
 */
public IBlockState withRotation(IBlockState state, Rotation rot)
{
    return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
 
Example 11
Source File: BlockBeacon.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public IBlockState withRotation(IBlockState state, Rotation rot)
{
	return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
 
Example 12
Source File: Cooker.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
    return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
}
 
Example 13
Source File: BlockFuton.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
	if (worldIn.isRemote) {
		return true;
	}
	if (state.getValue(PART) != EnumPartType.HEAD) {
		pos = pos.offset(state.getValue(FACING));
		state = worldIn.getBlockState(pos);

		if (state.getBlock() != this) {
			return true;
		}
	}

	if (worldIn.provider.canRespawnHere() && worldIn.getBiome(pos) != Biomes.HELL) {
		if (state.getValue(OCCUPIED).booleanValue()) {
			EntityPlayer entityplayer = this.getPlayerInBlanket(worldIn, pos);

			if (entityplayer != null) {
				playerIn.sendMessage(new TextComponentTranslation("tile.bed.occupied"));
				return true;
			}

			state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
			worldIn.setBlockState(pos, state, 4);
		}

		EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);

		if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK) {
			state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
			worldIn.setBlockState(pos, state, 4);
			return true;
		}
		if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW) {
			playerIn.sendMessage(new TextComponentTranslation("tile.bed.noSleep"));
		} else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE) {
			playerIn.sendMessage(new TextComponentTranslation("tile.bed.notSafe"));
		}

		return true;
	}
	worldIn.setBlockToAir(pos);
	BlockPos blockpos = pos.offset(state.getValue(FACING).getOpposite());

	if (worldIn.getBlockState(blockpos).getBlock() == this) {
		worldIn.setBlockToAir(blockpos);
	}

	worldIn.newExplosion(null, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, 5.0F, true, true);
	return true;
}
 
Example 14
Source File: ItemAstroBed.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn,
		BlockPos pos, EnumHand hand, EnumFacing facing, float hitX,
		float hitY, float hitZ)
{
	if (worldIn.isRemote)
	{
		return EnumActionResult.SUCCESS;
	}
	else if (facing != EnumFacing.UP)
	{
		return EnumActionResult.FAIL;
	}
	else
	{
		ItemStack stack = playerIn.getHeldItem(hand);
		IBlockState iblockstate = worldIn.getBlockState(pos);
		Block block = iblockstate.getBlock();
		boolean flag = block.isReplaceable(worldIn, pos);

		if (!flag)
		{
			pos = pos.up();
		}

		int i = MathHelper.floor((double)(playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
		EnumFacing enumfacing = EnumFacing.getHorizontal(i);
		BlockPos blockpos = pos.offset(enumfacing);

		if (playerIn.canPlayerEdit(pos, facing, stack) && playerIn.canPlayerEdit(blockpos, facing, stack))
		{
			boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
			boolean flag2 = flag || worldIn.isAirBlock(pos);
			boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

			if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP) && worldIn.getBlockState(blockpos.down()).isSideSolid(worldIn, blockpos.down(), EnumFacing.UP))
			{
				IBlockState iblockstate1 = AdvancedRocketryBlocks.blockAstroBed.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);

				if (worldIn.setBlockState(pos, iblockstate1, 11))
				{
					IBlockState iblockstate2 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
					worldIn.setBlockState(blockpos, iblockstate2, 11);
				}

				SoundType soundtype = iblockstate1.getBlock().getSoundType();
				worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
				stack.setCount(stack.getCount() - 1);
				return EnumActionResult.SUCCESS;
			}
			else
			{
				return EnumActionResult.FAIL;
			}
		}
		else
		{
			return EnumActionResult.FAIL;
		}
	}
}
 
Example 15
Source File: BlockPressurePlate.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected IBlockState setRedstoneStrength(IBlockState state, int strength)
{
    return state.withProperty(POWERED, strength > 0);
}
 
Example 16
Source File: ItemFuton.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand,
		EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (worldIn.isRemote) {
		return EnumActionResult.SUCCESS;
	} else if (facing != EnumFacing.UP) {
		return EnumActionResult.FAIL;
	} else {
		IBlockState iblockstate = worldIn.getBlockState(pos);
		Block block = iblockstate.getBlock();
		boolean flag = block.isReplaceable(worldIn, pos);

		if (!flag) {
			pos = pos.up();
		}

		int i = MathHelper.floor(playerIn.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
		EnumFacing enumfacing = EnumFacing.getHorizontal(i);
		BlockPos blockpos = pos.offset(enumfacing);
		ItemStack itemstack = playerIn.getHeldItem(hand);

		if (playerIn.canPlayerEdit(pos, facing, itemstack) && playerIn.canPlayerEdit(blockpos, facing, itemstack)) {
			boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
			boolean flag2 = flag || worldIn.isAirBlock(pos);
			boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

			if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isTopSolid()
					&& worldIn.getBlockState(blockpos.down()).isFullCube()) {
				IBlockState iblockstate1 = BlockLoader.FUTON.getDefaultState()
						.withProperty(BlockFuton.OCCUPIED, Boolean.valueOf(false))
						.withProperty(BlockHorizontal.FACING, enumfacing)
						.withProperty(BlockFuton.PART, BlockFuton.EnumPartType.FOOT);

				if (worldIn.setBlockState(pos, iblockstate1, 11)) {
					IBlockState iblockstate2 = iblockstate1.withProperty(BlockFuton.PART,
							BlockFuton.EnumPartType.HEAD);
					worldIn.setBlockState(blockpos, iblockstate2, 11);
				}

				SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn);
				worldIn.playSound(null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS,
						(soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
				itemstack.shrink(1);
				return EnumActionResult.SUCCESS;
			}
			return EnumActionResult.FAIL;
		}
		return EnumActionResult.FAIL;
	}
}
 
Example 17
Source File: TidalGenerator.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
    return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
}
 
Example 18
Source File: BlockKawara.java    From Sakura_mod with MIT License 4 votes vote down vote up
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
  return state.withProperty(SHAPE, getStairsShape(state, worldIn, pos));
}
 
Example 19
Source File: Bioreactor.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
    return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
}
 
Example 20
Source File: BlockBlueprintArchive.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public IBlockState withRotation(IBlockState state, Rotation rot)
{
	return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}