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

The following are Jave code examples for showing how to use getTileEntity() 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: ArcaneMagic   File: BlockAnimusMaterializer.java   Source Code and License Vote up 6 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;
	}
	TileEntity te = world.getTileEntity(pos);
	if (!(te instanceof TileEntityAnimusMaterializer))
	{
		return false;
	}
	player.openGui(ArcaneMagic.instance, GUI_ID, world, pos.getX(), pos.getY(), pos.getZ());
	return true;
}
 
Example 2
Project: Got-Wood   File: BlockTreeTap.java   Source Code and License Vote up 6 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
	if (worldIn.isRemote) {
		return false;
	}
	if (this.hasTileEntity(this.getDefaultState())) {
		ItemStack stack = playerIn.getHeldItem(hand);
		if (!stack.isEmpty()) {
			System.out.println("yep");
			if (stack.getItem() == Items.BUCKET && !stack.isEmpty()) {
				stack.shrink(1);
				TileEntity te = worldIn.getTileEntity(pos);
				if (te instanceof TileEntityTreeTap) {
					((TileEntityTreeTap) te).hasBucket = true;
					worldIn.setBlockState(pos, worldIn.getBlockState(pos).withProperty(HASBUCKET, true), 3);
					return true;
				}
			}
		}

	}
	return false;
}
 
Example 3
Project: BetterBeginningsReborn   File: BlockSpecializedFurnace.java   Source Code and License Vote up 6 votes
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer,
        ItemStack stack)
{
    world.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);

    if (stack.hasDisplayName())
    {
        TileEntity teBase = world.getTileEntity(pos);
        if (teBase instanceof TileEntitySpecializedFurnace)
        {
            TileEntitySpecializedFurnace tileEntity = (TileEntitySpecializedFurnace)teBase;
            tileEntity.setBlockName(stack.getDisplayName());
        }
    }
}
 
Example 4
Project: Backmemed   File: BlockFurnace.java   Source Code and License Vote up 6 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY)
{
    if (worldIn.isRemote)
    {
        return true;
    }
    else
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityFurnace)
        {
            playerIn.displayGUIChest((TileEntityFurnace)tileentity);
            playerIn.addStat(StatList.FURNACE_INTERACTION);
        }

        return true;
    }
}
 
Example 5
Project: ExSartagine   File: BlockSmelter.java   Source Code and License Vote up 6 votes
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
	double d0 = (double)pos.getX() + 0.5D;
	double d1 = (double)pos.getY() + 0.75D;
	double d2 = (double)pos.getZ() + 0.5D;
	double d3 = 0.22D;
	double d4 = 0.27D;

	if(worldIn.getTileEntity(pos) instanceof TileEntitySmelter)
	{
		if(((TileEntitySmelter)worldIn.getTileEntity(pos)).isCooking() && !((TileEntitySmelter)worldIn.getTileEntity(pos)).getInventory().getStackInSlot(0).isEmpty())
		{
			for(int i = 0; i < 25; i++)
			{
				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0+(RANDOM.nextDouble()/5 - 0.1), d1, d2+(RANDOM.nextDouble()/5 - 0.1), 0.0D, 0.0D, 0.0D, new int[0]);
				worldIn.spawnParticle(EnumParticleTypes.FLAME, d0+(RANDOM.nextDouble()/5 - 0.1), d1, d2+(RANDOM.nextDouble()/5 - 0.1), 0.0D, 0.02D, 0.0D, new int[0]);

				worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0+(RANDOM.nextDouble()/5 - 0.1), d1, d2+(RANDOM.nextDouble()/5 - 0.1), 0.0D, 0.0D, 0.0D, new int[0]);
			}
			worldIn.spawnParticle(EnumParticleTypes.FLAME, d0+(RANDOM.nextDouble()/5 - 0.1), d1, d2+(RANDOM.nextDouble()/5 - 0.1), 0.0D, 0.05D, 0.0D, new int[0]);
		}
	}
}
 
Example 6
Project: pnc-repressurized   File: BlockSecurityStation.java   Source Code and License Vote up 6 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float par7, float par8, float par9) {
    if (player.isSneaking()) return false;
    else {
        if (!world.isRemote) {
            TileEntitySecurityStation te = (TileEntitySecurityStation) world.getTileEntity(pos);
            if (te != null) {
                if (te.isPlayerOnWhiteList(player)) {
                    player.openGui(PneumaticCraftRepressurized.instance, EnumGuiId.SECURITY_STATION_INVENTORY.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
                } else if (!te.hasValidNetwork()) {
                    player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "This Security Station is out of order: Its network hasn't been properly configured."), false);
                } else if (te.hasPlayerHacked(player)) {
                    player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "You've already hacked this Security Station!"), false);
                } else if (getPlayerHackLevel(player) < te.getSecurityLevel()) {
                    player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You can't access or hack this Security Station. To hack it you need at least a Pneumatic Helmet upgraded with " + te.getSecurityLevel() + " Security upgrade(s)."), false);
                } else {
                    player.openGui(PneumaticCraftRepressurized.instance, EnumGuiId.HACKING.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
                }
            }
        }
        return true;
    }
}
 
Example 7
Project: MineCamera   File: BlockPictureFrame.java   Source Code and License Vote up 6 votes
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
	// System.out.println("123");
	if (!worldIn.isRemote) {
		TileEntityPictureFrame te = (TileEntityPictureFrame) worldIn.getTileEntity(pos);
		if (!te.imagename.equals("")) {
			ItemStack picture = new ItemStack(ItemLoader.itemPicture);
			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setString("pid", te.imagename);
			picture.setTagCompound(nbt);
			// worldIn.spawnEntityInWorld(new EntityItem(worldIn,
			// pos.getX(), pos.getY(), pos.getZ(), picture));
			Block.spawnAsEntity(worldIn, pos, picture);
		}
	}
	super.breakBlock(worldIn, pos, state);

}
 
Example 8
Project: SimpleTubes   File: PacketItemAdd.java   Source Code and License Vote up 5 votes
@Override
public void fromBytes(ByteBuf buf) {
	int dim = buf.readInt();
	BlockPos pos = BlockPos.fromLong(buf.readLong());

	World world = SimpleTubes.proxy.getWorld(dim);
	this.tile = world.getTileEntity(pos);

	this.id = buf.readInt();
	this.stack = ByteBufUtils.readItemStack(buf);
	this.progress = buf.readFloat();
	this.direction = buf.readByte();
	this.color = buf.readInt();
}
 
Example 9
Project: Backmemed   File: Bootstrap.java   Source Code and License Vote up 5 votes
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
{
    Block block = Block.getBlockFromItem(stack.getItem());
    World world = source.getWorld();
    EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
    BlockPos blockpos = source.getBlockPos().offset(enumfacing);
    this.field_190911_b = world.func_190527_a(block, blockpos, false, EnumFacing.DOWN, (Entity)null);

    if (this.field_190911_b)
    {
        EnumFacing enumfacing1 = world.isAirBlock(blockpos.down()) ? enumfacing : EnumFacing.UP;
        IBlockState iblockstate = block.getDefaultState().withProperty(BlockShulkerBox.field_190957_a, enumfacing1);
        world.setBlockState(blockpos, iblockstate);
        TileEntity tileentity = world.getTileEntity(blockpos);
        ItemStack itemstack = stack.splitStack(1);

        if (itemstack.hasTagCompound())
        {
            ((TileEntityShulkerBox)tileentity).func_190586_e(itemstack.getTagCompound().getCompoundTag("BlockEntityTag"));
        }

        if (itemstack.hasDisplayName())
        {
            ((TileEntityShulkerBox)tileentity).func_190575_a(itemstack.getDisplayName());
        }

        world.updateComparatorOutputLevel(blockpos, iblockstate.getBlock());
    }

    return stack;
}
 
Example 10
Project: CustomWorldGen   File: BlockChest.java   Source Code and License Vote up 5 votes
/**
 * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
 * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
 * block, etc.
 */
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
{
    super.neighborChanged(state, worldIn, pos, blockIn);
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof TileEntityChest)
    {
        tileentity.updateContainingBlockInfo();
    }
}
 
Example 11
Project: Backmemed   File: BlockJukebox.java   Source Code and License Vote up 5 votes
public void insertRecord(World worldIn, BlockPos pos, IBlockState state, ItemStack recordStack)
{
    if (!worldIn.isRemote)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof BlockJukebox.TileEntityJukebox)
        {
            ((BlockJukebox.TileEntityJukebox)tileentity).setRecord(recordStack.copy());
            worldIn.setBlockState(pos, state.withProperty(HAS_RECORD, Boolean.valueOf(true)), 2);
        }
    }
}
 
Example 12
Project: ExPetrum   File: BlockFarmland.java   Source Code and License Vote up 5 votes
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
	super.updateTick(worldIn, pos, state, rand);
	if (worldIn.getTileEntity(pos) != null && worldIn.getTileEntity(pos).hasCapability(ExPFarmlandCapability.farmlandCap, EnumFacing.UP))
	{
		IFarmland.of(worldIn.getTileEntity(pos)).onWorldTick();
	}
}
 
Example 13
Project: MiningWells   File: BlockBase.java   Source Code and License Vote up 5 votes
public void breakBlock(World world, BlockPos pos, IBlockState state) {
	if (!world.isRemote) {
		TileEntity atPos = world.getTileEntity(pos);
		if (atPos != null && atPos instanceof IInventory) {
			InventoryHelper.dropInventoryItems(world, pos, (IInventory) atPos);
		}
	}
}
 
Example 14
Project: WirelessCharger   File: BlockPersonalCharger.java   Source Code and License Vote up 5 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
        return true;
    }
    TileEntity te = worldIn.getTileEntity(pos);

    if (!(te instanceof TilePersonalCharger)) {
        return false;
    }
    playerIn.openGui(Main.instance, GUI_ID, worldIn, pos.getX(), pos.getY(), pos.getZ());
    return true;
}
 
Example 15
Project: Backmemed   File: BlockBeacon.java   Source Code and License Vote up 5 votes
/**
 * Called by ItemBlocks after a block is set in the world, to allow post-place logic
 */
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);

    if (stack.hasDisplayName())
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityBeacon)
        {
            ((TileEntityBeacon)tileentity).setName(stack.getDisplayName());
        }
    }
}
 
Example 16
Project: CustomWorldGen   File: BlockBrewingStand.java   Source Code and License Vote up 5 votes
/**
 * Called by ItemBlocks after a block is set in the world, to allow post-place logic
 */
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
    if (stack.hasDisplayName())
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityBrewingStand)
        {
            ((TileEntityBrewingStand)tileentity).setName(stack.getDisplayName());
        }
    }
}
 
Example 17
Project: Backmemed   File: BlockStructure.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)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);
    return tileentity instanceof TileEntityStructure ? ((TileEntityStructure)tileentity).usedBy(playerIn) : false;
}
 
Example 18
Project: Backmemed   File: BlockCommandBlock.java   Source Code and License Vote up 4 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityCommandBlock)
        {
            TileEntityCommandBlock tileentitycommandblock = (TileEntityCommandBlock)tileentity;
            CommandBlockBaseLogic commandblockbaselogic = tileentitycommandblock.getCommandBlockLogic();
            boolean flag = !StringUtils.isNullOrEmpty(commandblockbaselogic.getCommand());
            TileEntityCommandBlock.Mode tileentitycommandblock$mode = tileentitycommandblock.getMode();
            boolean flag1 = !tileentitycommandblock.isConditional() || this.isNextToSuccessfulCommandBlock(worldIn, pos, state);
            boolean flag2 = tileentitycommandblock.isConditionMet();
            boolean flag3 = false;

            if (tileentitycommandblock$mode != TileEntityCommandBlock.Mode.SEQUENCE && flag2 && flag)
            {
                commandblockbaselogic.trigger(worldIn);
                flag3 = true;
            }

            if (tileentitycommandblock.isPowered() || tileentitycommandblock.isAuto())
            {
                if (tileentitycommandblock$mode == TileEntityCommandBlock.Mode.SEQUENCE && flag1 && flag)
                {
                    commandblockbaselogic.trigger(worldIn);
                    flag3 = true;
                }

                if (tileentitycommandblock$mode == TileEntityCommandBlock.Mode.AUTO)
                {
                    worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));

                    if (flag1)
                    {
                        this.propagateUpdate(worldIn, pos);
                    }
                }
            }

            if (!flag3)
            {
                commandblockbaselogic.setSuccessCount(0);
            }

            tileentitycommandblock.setConditionMet(flag1);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }
}
 
Example 19
Project: DecompiledMinecraft   File: BlockChest.java   Source Code and License Vote up 4 votes
/**
 * Called by ItemBlocks after a block is set in the world, to allow post-place logic
 */
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
    EnumFacing enumfacing = EnumFacing.getHorizontal(MathHelper.floor_double((double)(placer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3).getOpposite();
    state = state.withProperty(FACING, enumfacing);
    BlockPos blockpos = pos.north();
    BlockPos blockpos1 = pos.south();
    BlockPos blockpos2 = pos.west();
    BlockPos blockpos3 = pos.east();
    boolean flag = this == worldIn.getBlockState(blockpos).getBlock();
    boolean flag1 = this == worldIn.getBlockState(blockpos1).getBlock();
    boolean flag2 = this == worldIn.getBlockState(blockpos2).getBlock();
    boolean flag3 = this == worldIn.getBlockState(blockpos3).getBlock();

    if (!flag && !flag1 && !flag2 && !flag3)
    {
        worldIn.setBlockState(pos, state, 3);
    }
    else if (enumfacing.getAxis() != EnumFacing.Axis.X || !flag && !flag1)
    {
        if (enumfacing.getAxis() == EnumFacing.Axis.Z && (flag2 || flag3))
        {
            if (flag2)
            {
                worldIn.setBlockState(blockpos2, state, 3);
            }
            else
            {
                worldIn.setBlockState(blockpos3, state, 3);
            }

            worldIn.setBlockState(pos, state, 3);
        }
    }
    else
    {
        if (flag)
        {
            worldIn.setBlockState(blockpos, state, 3);
        }
        else
        {
            worldIn.setBlockState(blockpos1, state, 3);
        }

        worldIn.setBlockState(pos, state, 3);
    }

    if (stack.hasDisplayName())
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityChest)
        {
            ((TileEntityChest)tileentity).setCustomName(stack.getDisplayName());
        }
    }
}
 
Example 20
Project: ArcaneMagic   File: BlockAnimaConjurer.java   Source Code and License Vote up 4 votes
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
		EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (!player.isSneaking())
	{
		if (!world.isRemote)
		{
			TileEntityAnimaConjurer te = (TileEntityAnimaConjurer) world.getTileEntity(pos);
			if (te.getStack().isEmpty())
			{
				if (!player.getHeldItem(hand).isEmpty())
				{
					ItemStack heldItemClone = player.getHeldItem(hand).copy();
					heldItemClone.setCount(1);

					if (player.getHeldItem(hand).getCount() > 1)
					{
						player.getHeldItem(hand).shrink(1);
					} else
					{
						player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
					}
					te.setStack(heldItemClone);

					player.openContainer.detectAndSendChanges();
				}
			} else
			{
				ItemStack stack = te.getStack();
				te.setStack(ItemStack.EMPTY);
				if (!player.inventory.addItemStackToInventory(stack))
				{
					EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
					world.spawnEntity(entityItem);
				} else
				{
					player.openContainer.detectAndSendChanges();
				}
			}
		}

		return true;
	}
	return false;
}