Java Code Examples for net.minecraft.world.World.notifyBlockUpdate()

The following are Jave code examples for showing how to use notifyBlockUpdate() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ExSartagine   File: BlockPan.java   Source Code and License Vote up 6 votes
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
	if(world.getBlockState(pos.down()).getBlock() == Blocks.LIT_FURNACE){
		((TileEntityPan)world.getTileEntity(pos)).setCooking();
		world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
	}
	if (world.getBlockState(pos.down()).getBlock() == ExSartagineBlock.range_extension){
		if(world.getTileEntity(pos.down()) instanceof TileEntityRangeExtension)
		{
			if(((TileEntityRangeExtension)world.getTileEntity(pos.down())).isCooking())
			{
				((TileEntityPan)world.getTileEntity(pos)).setCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
		}
	}
}
 
Example 2
Project: pnc-repressurized   File: HackableMobSpawner.java   Source Code and License Vote up 5 votes
@Override
public void onHackFinished(World world, BlockPos pos, EntityPlayer player) {
    if (!world.isRemote) {
        NBTTagCompound tag = new NBTTagCompound();
        TileEntity te = world.getTileEntity(pos);
        if (te != null) {
            te.writeToNBT(tag);
            tag.setShort("RequiredPlayerRange", (short) 0);
            te.readFromNBT(tag);
            IBlockState state = world.getBlockState(pos);
            world.notifyBlockUpdate(pos, state, state, 3);
        }
    }

}
 
Example 3
Project: ExSartagine   File: BlockSmelter.java   Source Code and License Vote up 5 votes
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos)
{

	if(world.getTileEntity(pos) instanceof TileEntitySmelter){
		if(fromPos.up().equals(pos)){ //if the block is beneath us
			Block down = world.getBlockState(fromPos).getBlock();
			if(down == Blocks.AIR)
			{
				dropBlockAsItem(world, pos, getDefaultState(), 0);
				world.setBlockToAir(pos);
			}

			else if(down == Blocks.LIT_FURNACE)
			{
				((TileEntitySmelter)world.getTileEntity(pos)).setCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}

			else if(down == Blocks.FURNACE)
			{
				((TileEntitySmelter)world.getTileEntity(pos)).stopCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
			else if (down == ExSartagineBlock.range_extension_lit)
			{
				((TileEntitySmelter)world.getTileEntity(pos)).setCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
			else if (down == ExSartagineBlock.range_extension)
			{
				((TileEntitySmelter)world.getTileEntity(pos)).stopCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
		}
	}
}
 
Example 4
Project: ExSartagine   File: BlockPan.java   Source Code and License Vote up 5 votes
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos)
{

	if(world.getTileEntity(pos) instanceof TileEntityPan){
		if(fromPos.up().equals(pos)){ //if the block is beneath us
			Block down = world.getBlockState(fromPos).getBlock();

			if(down == Blocks.AIR)
			{
				dropBlockAsItem(world, pos, getDefaultState(), 0);
				world.setBlockToAir(pos);
			}

			else if(down == Blocks.LIT_FURNACE)
			{
				((TileEntityPan)world.getTileEntity(pos)).setCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}

			else if(down == Blocks.FURNACE)
			{
				((TileEntityPan)world.getTileEntity(pos)).stopCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
			else if (down == ExSartagineBlock.range_extension_lit)
			{
				((TileEntityPan)world.getTileEntity(pos)).setCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
			else if (down == ExSartagineBlock.range_extension)
			{
				((TileEntityPan)world.getTileEntity(pos)).stopCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
		}
	}
}
 
Example 5
Project: Bewitchment   File: BlockBarrel.java   Source Code and License Vote up 5 votes
@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;
	TileEntityBarrel barrel = (TileEntityBarrel) world.getTileEntity(pos);
	world.notifyBlockUpdate(pos, state, state, 3);
	ItemStack stack = player.getHeldItem(hand);
	if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
		IFluidHandlerItem itemHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
		IFluidHandler barrelHandler = barrel.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
		FluidStack fluidInItem = itemHandler.drain(Fluid.BUCKET_VOLUME, false);
		FluidStack fluidInBarrel = barrelHandler.drain(Fluid.BUCKET_VOLUME, false);
		if ((fluidInBarrel != null && fluidInBarrel.amount > 0) && (fluidInItem == null || fluidInItem.amount == 0 || (fluidInItem.isFluidEqual(fluidInBarrel) && fluidInItem.amount < Fluid.BUCKET_VOLUME))) {
			itemHandler.fill(barrelHandler.drain(Fluid.BUCKET_VOLUME, true), true);
			player.setHeldItem(hand, itemHandler.getContainer());
		} else if (fluidInItem != null && fluidInItem.amount > 0 && fluidInItem.getFluid() != null && (fluidInBarrel == null || fluidInBarrel.amount == 0 || (fluidInBarrel.amount < Fluid.BUCKET_VOLUME && fluidInBarrel.isFluidEqual(fluidInItem)))) {
			FluidStack fsin = itemHandler.drain(Fluid.BUCKET_VOLUME, true);
			if (fsin != null && fsin.amount > 0 && fsin.getFluid() != null) {
				barrelHandler.fill(fsin, true);
				player.setHeldItem(hand, itemHandler.getContainer());
				player.inventory.markDirty();
			}
		}
		return true;
	}

	player.openGui(Bewitchment.instance, LibGui.BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
	return true;
}
 
Example 6
Project: Bewitchment   File: BlockWitchAltar.java   Source Code and License Vote up 5 votes
@SuppressWarnings("deprecation")
public static void notifyAround(BlockPos pos, World world) {
	for (int dx = -1; dx <= 1; dx++)
		for (int dy = -1; dy <= 1; dy++) {
			BlockPos bp = pos.add(dx, 0, dy);
			if (world.getBlockState(bp).getBlock().equals(ModBlocks.witch_altar))
				world.notifyBlockUpdate(bp, world.getBlockState(bp), world.getBlockState(bp).getBlock().getActualState(world.getBlockState(bp), world, bp), 11);
		}
}
 
Example 7
Project: SimplyTea   File: SimplyTea.java   Source Code and License Vote up 5 votes
@Override
public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
       if (state.getBlock() == this){
       	if (state.getValue(CLIPPED)){
       		worldIn.setBlockState(pos, state.withProperty(CLIPPED, false));
       		worldIn.notifyBlockUpdate(pos, state, state.withProperty(CLIPPED, false), 8);
       	}
       }
}
 
Example 8
Project: morefurnaces   File: BlockMoreFurnaces.java   Source Code and License Vote up 5 votes
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase living, ItemStack stack)
{
    EnumFacing facing = living.getHorizontalFacing().getOpposite();

    TileEntity te = world.getTileEntity(pos);
    if (te != null && te instanceof TileEntityIronFurnace)
    {
        ((TileEntityIronFurnace) te).setFacing((byte) facing.ordinal());
        world.notifyBlockUpdate(pos, state, state, 3);
    }
}
 
Example 9
Project: SimpleTubes   File: ItemUpgrade.java   Source Code and License Vote up 5 votes
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {

	if (!world.isRemote) {

		ItemStack held = player.getHeldItem(hand);

		if (player.isSneaking())
			return EnumActionResult.PASS;

		if (held != ItemStack.EMPTY && held.getItem() instanceof ItemUpgrade) {

			if (held.getMetadata() == 0) {

				IBlockState state = world.getBlockState(pos);
				if (state.getBlock() instanceof BlockDisplacer)
					if (!state.getValue(BlockDisplacer.FILTER)) {
						state = state.withProperty(BlockDisplacer.FILTER, true);

						if (world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof TileDisplacer) {
							if (!((TileDisplacer) world.getTileEntity(pos)).hasFilter()) {
								((TileDisplacer) world.getTileEntity(pos)).setHasFilter(true);
								((TileDisplacer) world.getTileEntity(pos)).markDirty();

								PacketHandler.sendToAll(new PacketDisplacerSync(((TileDisplacer) world.getTileEntity(pos)), true));
							}
						}
					}
				world.setBlockState(pos, state, 3);
				world.notifyBlockUpdate(pos, state, state, 3);

				if (!player.isCreative())
					player.getHeldItem(hand).splitStack(1);
			}
			return EnumActionResult.SUCCESS;
		}
	}

	return EnumActionResult.PASS;
}
 
Example 10
Project: CustomWorldGen   File: BlockSnapshot.java   Source Code and License Vote up 5 votes
public boolean restoreToLocation(World world, BlockPos pos, boolean force, boolean applyPhysics)
{
    IBlockState current = getCurrentBlock();
    IBlockState replaced = getReplacedBlock();
    if (current.getBlock() != replaced.getBlock() || current.getBlock().getMetaFromState(current) != replaced.getBlock().getMetaFromState(replaced))
    {
        if (force)
        {
            world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
        }
        else
        {
            return false;
        }
    }

    world.setBlockState(pos, replaced, applyPhysics ? 3 : 2);
    world.notifyBlockUpdate(pos, current, replaced, applyPhysics ? 3 : 2);
    TileEntity te = null;
    if (getNbt() != null)
    {
        te = world.getTileEntity(pos);
        if (te != null)
        {
            te.readFromNBT(getNbt());
            te.markDirty();
        }
    }

    if (DEBUG)
    {
        System.out.printf("Restored BlockSnapshot with data [World: %s ][Location: %d,%d,%d ][Meta: %d ][Block: %s ][TileEntity: %s ][force: %s ][applyPhysics: %s]", world.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), replaced.getBlock().getMetaFromState(replaced), replaced.getBlock().delegate.name(), te, force, applyPhysics);
    }
    return true;
}
 
Example 11
Project: CustomWorldGen   File: BlockFlowerPot.java   Source Code and License Vote up 4 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (heldItem != null && heldItem.getItem() instanceof ItemBlock)
    {
        TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);

        if (tileentityflowerpot == null)
        {
            return false;
        }
        else if (tileentityflowerpot.getFlowerPotItem() != null)
        {
            return false;
        }
        else
        {
            Block block = Block.getBlockFromItem(heldItem.getItem());

            if (!this.canContain(block, heldItem.getMetadata()))
            {
                return false;
            }
            else
            {
                tileentityflowerpot.setFlowerPotData(heldItem.getItem(), heldItem.getMetadata());
                tileentityflowerpot.markDirty();
                worldIn.notifyBlockUpdate(pos, state, state, 3);
                playerIn.addStat(StatList.FLOWER_POTTED);

                if (!playerIn.capabilities.isCreativeMode)
                {
                    --heldItem.stackSize;
                }

                return true;
            }
        }
    }
    else
    {
        return false;
    }
}
 
Example 12
Project: Backmemed   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 13
Project: ExSartagine   File: BlockPot.java   Source Code and License Vote up 4 votes
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos)
{

	if(world.getTileEntity(pos) instanceof TileEntityPot){
		if(fromPos.up().equals(pos)){ //if the block is beneath us
			Block down = world.getBlockState(fromPos).getBlock();
			if(down == Blocks.AIR)
			{
				dropBlockAsItem(world, pos, getDefaultState(), 0);
				world.setBlockToAir(pos);
			}

			else if(down == Blocks.LIT_FURNACE)
			{
				if(((TileEntityPot)world.getTileEntity(pos)).getWaterLevel() > 0)
				{
					((TileEntityPot)world.getTileEntity(pos)).setCooking();
					world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
				}
			}

			else if(down == Blocks.FURNACE)
			{
				if(((TileEntityPot)world.getTileEntity(pos)).getWaterLevel() > 0)
				{
					((TileEntityPot)world.getTileEntity(pos)).stopCooking();
					world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
				}
			}
			else if (down == ExSartagineBlock.range_extension_lit)
			{
				((TileEntityPot)world.getTileEntity(pos)).setCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
			else if (down == ExSartagineBlock.range_extension)
			{
				((TileEntityPot)world.getTileEntity(pos)).stopCooking();
				world.notifyBlockUpdate(pos, state, getDefaultState(), 3);
			}
		}
	}
}
 
Example 14
Project: CustomWorldGen   File: CommandBlockData.java   Source Code and License Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 15
Project: CustomWorldGen   File: ItemMonsterPlacer.java   Source Code and License Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return EnumActionResult.SUCCESS;
    }
    else if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack))
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);

        if (iblockstate.getBlock() == Blocks.MOB_SPAWNER)
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityMobSpawner)
            {
                MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic();
                mobspawnerbaselogic.setEntityName(getEntityIdFromItem(stack));
                tileentity.markDirty();
                worldIn.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);

                if (!playerIn.capabilities.isCreativeMode)
                {
                    --stack.stackSize;
                }

                return EnumActionResult.SUCCESS;
            }
        }

        pos = pos.offset(facing);
        double d0 = 0.0D;

        if (facing == EnumFacing.UP && iblockstate.getBlock() instanceof BlockFence) //Forge: Fix Vanilla bug comparing state instead of block
        {
            d0 = 0.5D;
        }

        Entity entity = spawnCreature(worldIn, getEntityIdFromItem(stack), (double)pos.getX() + 0.5D, (double)pos.getY() + d0, (double)pos.getZ() + 0.5D);

        if (entity != null)
        {
            if (entity instanceof EntityLivingBase && stack.hasDisplayName())
            {
                entity.setCustomNameTag(stack.getDisplayName());
            }

            applyItemEntityDataToEntity(worldIn, playerIn, stack, entity);

            if (!playerIn.capabilities.isCreativeMode)
            {
                --stack.stackSize;
            }
        }

        return EnumActionResult.SUCCESS;
    }
}
 
Example 16
Project: Backmemed   File: BlockFlowerPot.java   Source Code and License Vote up 4 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY)
{
    ItemStack itemstack = playerIn.getHeldItem(hand);
    TileEntityFlowerPot tileentityflowerpot = this.getTileEntity(worldIn, pos);

    if (tileentityflowerpot == null)
    {
        return false;
    }
    else
    {
        ItemStack itemstack1 = tileentityflowerpot.getFlowerItemStack();

        if (itemstack1.func_190926_b())
        {
            if (!this.func_190951_a(itemstack))
            {
                return false;
            }

            tileentityflowerpot.func_190614_a(itemstack);
            playerIn.addStat(StatList.FLOWER_POTTED);

            if (!playerIn.capabilities.isCreativeMode)
            {
                itemstack.func_190918_g(1);
            }
        }
        else
        {
            if (itemstack.func_190926_b())
            {
                playerIn.setHeldItem(hand, itemstack1);
            }
            else if (!playerIn.func_191521_c(itemstack1))
            {
                playerIn.dropItem(itemstack1, false);
            }

            tileentityflowerpot.func_190614_a(ItemStack.field_190927_a);
        }

        tileentityflowerpot.markDirty();
        worldIn.notifyBlockUpdate(pos, state, state, 3);
        return true;
    }
}
 
Example 17
Project: BetterBeginningsReborn   File: TileEntityInfusionRepair.java   Source Code and License Vote up 4 votes
public void activate(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
   {
if(player.isSneaking())
{
    if(Prep1_11.isEmpty(heldItem))
    {
	if(hasEnchItem())
	{
	    if(!world.isRemote)
	    {
		world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), mainHandler.getStackInSlot(SLOT_ENCH_ITEM)));
	    }
	    mainHandler.setStackInSlot(SLOT_ENCH_ITEM, null);
	    mode = Mode.NONE;
	    pendingIngredients.clear();
	    markDirty();
	    world.notifyBlockUpdate(pos, state, state, 8);
	}
	else if(world.isRemote)
	{
	    ITextComponent link1 = new TextComponentString("Infusion Repair");
	    link1.setStyle(new Style().setBold(true).setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/einsteinsci/betterbeginnings/wiki/Infusion-Repair")));
	    ITextComponent link2 = new TextComponentString("Enchantment Diffusion");
	    link2.setStyle(new Style().setBold(true).setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/einsteinsci/betterbeginnings/wiki/Enchantment-Diffusion")));
	    ITextComponent message = new TextComponentString("See the BB wiki articles on ");
	    message.appendSibling(link1);
	    player.sendMessage(message);
	    player.sendMessage(new TextComponentString("and ").appendSibling(link2));
	}
    }
}
else
{
    if(Prep1_11.isEmpty(heldItem) || hasEnchItem() || mode != Mode.NONE) return;
    if(heldItem.getItem() == RegisterItems.cloth)
    {
	mode = Mode.DIFFUSION;
    }
    else if(heldItem.isItemEnchanted())
    {
	if(heldItem.getEnchantmentTagList().tagCount() > 8)
	{
	    player.sendMessage(new TextComponentTranslation("diffusion.toomanyenchants"));
	    mode = Mode.NONE;
	    return;
	}
	mode = Mode.REPAIR;
	pendingIngredients.clear();
	pendingIngredients.addAll(InfusionRepairUtil.getRequiredStacks(heldItem));
	xpLevelsNeeded = InfusionRepairUtil.getTakenLevels(heldItem);
	markDirty();
    }
    else
	return;
    ItemStack newStack = heldItem.copy();
    newStack.setCount(1);
    mainHandler.setStackInSlot(heldItem.isItemEnchanted() ? SLOT_ENCH_ITEM : 1, newStack);
    heldItem.shrink(1);
}
   }
 
Example 18
Project: ToughExpansion   File: BlockTempRegulator.java   Source Code and License Vote up 4 votes
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
	world.notifyBlockUpdate(pos, state, state, 2);
}
 
Example 19
Project: Clef   File: BlockInstrumentPlayer.java   Source Code and License Vote up 4 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    TileEntity te = worldIn.getTileEntity(pos);
    if(te instanceof TileEntityInstrumentPlayer)
    {
        TileEntityInstrumentPlayer player = (TileEntityInstrumentPlayer)te;
        boolean hasSlot = false;
        ItemStack is = playerIn.getHeldItemMainhand();
        if(is.getItem() == Clef.itemInstrument && !playerIn.isSneaking())
        {
            if(is.getTagCompound() == null && !worldIn.isRemote)
            {
                InstrumentLibrary.assignRandomInstrument(is);
            }
            //Find a free slot
            for(int i = 0; i < player.getSizeInventory(); i++)
            {
                ItemStack is1 = player.getStackInSlot(i);
                if(is1.isEmpty())
                {
                    hasSlot = true;
                    worldIn.playSound(null, pos.getX() + 0.5D, pos.getY() + 1D, pos.getZ() + 0.5D, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                    if(!worldIn.isRemote)
                    {
                        player.setInventorySlotContents(i, is);
                        player.markDirty();
                        playerIn.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
                        playerIn.inventory.markDirty();
                        worldIn.notifyBlockUpdate(pos, state, state, 3);
                    }
                    break;
                }
            }
        }
        else if(is.getItem() == Items.NAME_TAG && is.hasDisplayName())
        {
            boolean full = true;
            for(int i = 0; i < 9 ; i++)
            {
                if(player.getStackInSlot(i).isEmpty())
                {
                    full = false;
                    break;
                }
            }
            if(!full)
            {
                return false;
            }
            if(worldIn.isRemote)
            {
                for(Instrument instrument : InstrumentLibrary.instruments)
                {
                    if(instrument.info.itemName.equalsIgnoreCase(is.getDisplayName()))
                    {
                        Clef.channel.sendToServer(new PacketCreateInstrument(instrument.info.itemName, pos));
                        break;
                    }
                }
            }
            return true;
        }
        if(!hasSlot && !player.justCreatedInstrument)
        {
            FMLNetworkHandler.openGui(playerIn, Clef.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }
    return false;
}
 
Example 20
Project: Thermionics   File: ToolHelper.java   Source Code and License Vote up 4 votes
/**
 * Destroys and tries to harvest a block with the currently active tool, except that instead of calling
 * onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
 */
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
	if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!
	
	GameType gameType = player.interactionManager.getGameType();
	
	int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
       if (exp == -1) {
           return false;
       } else {
           IBlockState iblockstate = world.getBlockState(pos);
           if (iblockstate.getBlockHardness(world, pos)<0) return false;
           TileEntity tileentity = world.getTileEntity(pos);
           Block block = iblockstate.getBlock();

           if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
               world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
               return false;
           } else {
               ItemStack stack = player.getHeldItemMainhand();
               if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;

               world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
               boolean removed = false;

               if (gameType==GameType.CREATIVE) {
                   removed = removeBlock(world, pos, player, false);
                   player.connection.sendPacket(new SPacketBlockChange(world, pos));
               } else {
                   ItemStack itemstack1 = player.getHeldItemMainhand();
                   ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                   boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);

                   if (!itemstack1.isEmpty()) {
                   //    itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                    if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
                    	((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
                    }
                   }
                   
                   removed = removeBlock(world, pos, player, canHarvest);
                   if (removed && canHarvest) {
                       iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                   }
               }

               // Drop experience
               if (gameType!=GameType.CREATIVE && removed && exp > 0) {
                   iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
               }
               return removed;
           }
       }
}