Java Code Examples for net.minecraft.world.World#checkLight()

The following examples show how to use net.minecraft.world.World#checkLight() . 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: ItemJar.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);
	if (stack.getItemDamage() != 1) {
		BlockPos offset = pos.offset(side);
		IBlockState offsetState = world.getBlockState(offset);
		if (offsetState.getBlock().isAir(offsetState, world, offset) || offsetState.getBlock().isReplaceable(world, offset)) {

			if (!world.mayPlace(ModBlocks.JAR, offset, false, side, player)) return PASS;

			boolean replacable = world.getBlockState(pos).getBlock().isReplaceable(world, pos);
			boolean success = world.setBlockState(replacable ? pos : offset, ModBlocks.JAR.getDefaultState());
			if (success) {
				world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1, 1, false);

				if (!player.isCreative())
					stack.shrink(1);

				TileEntity tileEntity = world.getTileEntity(replacable ? pos : offset);
				if (tileEntity instanceof TileJar) {
					TileJar jar = (TileJar) tileEntity;
					jar.fairy = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy"));
					jar.markDirty();
					world.checkLight(replacable ? pos : offset);
				}
			}

			return SUCCESS;
		}
	}
	return PASS;
}
 
Example 2
Source File: ItemFairy.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack stack = player.getHeldItem(hand);
	if (stack.isEmpty()) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
	if (worldIn.isRemote) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);

	FairyData object = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy"));
	if (object == null) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);

	TileEntity tileEntity = worldIn.getTileEntity(pos);
	if (tileEntity instanceof TileJar) {
		TileJar jar = (TileJar) tileEntity;

		if (jar.fairy != null) return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);

		jar.fairy = object;
		jar.markDirty();
		worldIn.checkLight(pos);

	} else {

		BlockPos offsetpos = pos.offset(facing);
		EntityFairy entity = new EntityFairy(worldIn, object);
		entity.setPosition(offsetpos.getX() + 0.5, offsetpos.getY() + 0.5, offsetpos.getZ() + 0.5);
		entity.originPos = offsetpos;

		worldIn.spawnEntity(entity);
	}

	stack.shrink(1);
	worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), ModSounds.FAIRY, SoundCategory.BLOCKS, 1, 1, false);

	return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
 
Example 3
Source File: BlockJar.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
	TileEntity entity = worldIn.getTileEntity(pos);
	if (entity instanceof TileJar) {
		TileJar jar = (TileJar) entity;
		jar.fairy = FairyData.deserialize(NBTHelper.getCompound(stack, "fairy"));
		jar.markDirty();
		worldIn.checkLight(pos);
	}
}