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

The following examples show how to use net.minecraft.world.World#getTileEntity() . 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: PipeBasic.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player){
	super.onBlockHarvested(world, pos, state, player);
	if (world.getTileEntity(pos.up()) instanceof TileGenericPipe){
		((TileGenericPipe)world.getTileEntity(pos.up())).getAdjacentPipes(world);
	}
	if (world.getTileEntity(pos.down()) instanceof TileGenericPipe){
		((TileGenericPipe)world.getTileEntity(pos.down())).getAdjacentPipes(world);
	}
	if (world.getTileEntity(pos.north()) instanceof TileGenericPipe){
		((TileGenericPipe)world.getTileEntity(pos.north())).getAdjacentPipes(world);
	}
	if (world.getTileEntity(pos.south()) instanceof TileGenericPipe){
		((TileGenericPipe)world.getTileEntity(pos.south())).getAdjacentPipes(world);
	}
	if (world.getTileEntity(pos.west()) instanceof TileGenericPipe){
		((TileGenericPipe)world.getTileEntity(pos.west())).getAdjacentPipes(world);
	}
	if (world.getTileEntity(pos.east()) instanceof TileGenericPipe){
		((TileGenericPipe)world.getTileEntity(pos.east())).getAdjacentPipes(world);
	}
}
 
Example 2
Source File: ItemChestPickup.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ItemStack getDrop(BlockPos pos, World world) {

		IBlockState state = world.getBlockState(pos);

		Block block = state.getBlock();
		ItemStack stack = block.getItem(world, pos, state);
		TileEntity te = world.getTileEntity(pos);
		if (te == null) {
			return stack;
		}

		if (!stack.hasTagCompound()) {
			stack.setTagCompound(new NBTTagCompound());
		}
		NBTTagCompound nbt = stack.getTagCompound();
		nbt.setTag("BlockEntityTag", te.writeToNBT(new NBTTagCompound()));
		return stack;
	}
 
Example 3
Source File: ItemQuickStacker.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (player.isSneaking())
    {
        TileEntity te = world.getTileEntity(pos);

        if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
        {
            IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);

            if (world.isRemote == false && inv != null)
            {
                quickStackItems(player, player.getHeldItem(hand), inv);
            }

            return EnumActionResult.SUCCESS;
        }
    }

    return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
}
 
Example 4
Source File: BlockBabyChest.java    From NewHorizonsCoreMod with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World pWorld, int pX, int pY, int pZ, EntityPlayer pPlayer, int pSide, float pSubX, float pSubY, float pSubZ)
{
    if (pWorld.isRemote) 
    {
        return true;
    } 
    else 
    {
        if (pWorld.getTileEntity(pX, pY, pZ) instanceof TileEntityBabyChest)
        {
            TileEntityBabyChest tileEntity = (TileEntityBabyChest) pWorld.getTileEntity(pX, pY, pZ);
            pPlayer.openGui(MainRegistry.instance, GuiHandler.GUI_BABYCHEST, pWorld, pX, pY, pZ);
        }
        return true;
    }
}
 
Example 5
Source File: SawmillBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving)
{
    if (state.getBlock() != newState.getBlock())
    {
        TileEntity te = worldIn.getTileEntity(pos);

        if (te instanceof SawmillTileEntity)
        {
            dropInventoryItems(worldIn, pos, ((SawmillTileEntity) te).getInventory());
            worldIn.updateComparatorOutputLevel(pos, this);
        }

        super.onReplaced(state, worldIn, pos, newState, isMoving);
    }
}
 
Example 6
Source File: FMP.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public TMultiPart convert(World world, BlockCoord pos){
    if(!Config.convertMultipartsToBlocks) {
        if(world.getBlock(pos.x, pos.y, pos.z) == Blockss.pressureTube) return new PartPressureTube((TileEntityPressureTube)world.getTileEntity(pos.x, pos.y, pos.z));
        if(world.getBlock(pos.x, pos.y, pos.z) == Blockss.advancedPressureTube) return new PartAdvancedPressureTube((TileEntityPressureTube)world.getTileEntity(pos.x, pos.y, pos.z));
    }
    return null;
}
 
Example 7
Source File: BlockMotor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockAdded(World world, int x, int y, int z) {

    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile == null || !(tile instanceof TileMotor))
        return;

    ((TileMotor) tile).onBlockUpdate();
}
 
Example 8
Source File: BlockElevatorBase.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void dropInventory(World world, int x, int y, int z){

    TileEntity tileEntity = world.getTileEntity(x, y, z);

    if(!(tileEntity instanceof TileEntityElevatorBase)) return;

    TileEntityElevatorBase inventory = (TileEntityElevatorBase)tileEntity;
    Random rand = new Random();
    for(int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {

        ItemStack itemStack = inventory.getRealStackInSlot(i);

        if(itemStack != null && itemStack.stackSize > 0) {
            float dX = rand.nextFloat() * 0.8F + 0.1F;
            float dY = rand.nextFloat() * 0.8F + 0.1F;
            float dZ = rand.nextFloat() * 0.8F + 0.1F;

            EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

            if(itemStack.hasTagCompound()) {
                entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
            }

            float factor = 0.05F;
            entityItem.motionX = rand.nextGaussian() * factor;
            entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
            entityItem.motionZ = rand.nextGaussian() * factor;
            world.spawnEntityInWorld(entityItem);
            itemStack.stackSize = 0;
        }
    }
}
 
Example 9
Source File: BlockAphorismTile.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when the block is placed in the world.
 */
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack iStack){
    super.onBlockPlacedBy(world, x, y, z, entityLiving, iStack);
    int meta = world.getBlockMetadata(x, y, z);
    if(meta < 2) {
        TileEntity te = world.getTileEntity(x, y, z);
        if(te instanceof TileEntityAphorismTile) {
            ((TileEntityAphorismTile)te).textRotation = (((int)entityLiving.rotationYaw + 45) / 90 + 2) % 4;
        }
    }
    if(world.isRemote && entityLiving instanceof EntityPlayer) {
        ((EntityPlayer)entityLiving).openGui(PneumaticCraft.instance, EnumGuiId.APHORISM_TILE.ordinal(), world, x, y, z);
    }
}
 
Example 10
Source File: GuiHandlerWrapper.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

    TileEntity te = world.getTileEntity(x, y, z);
    if (te != null && te instanceof TileMoving) {
        MovingObjectPosition mop = ((TileMoving) te).rayTrace(player);
        if (mop != null) {
            MovingBlock b = (MovingBlock) ((Entry<?, ?>) mop.hitInfo).getKey();
            return handler.getClientGuiElement(ID, player, FakeWorld.getFakeWorld(b), b.getX(), b.getY(), b.getZ());
        }
    }

    return handler.getClientGuiElement(ID, player, world, x, y, z);
}
 
Example 11
Source File: BlockPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
    if(player.isSneaking() || getGuiID() == null || isRotatable() && player.getCurrentEquippedItem() != null && (player.getCurrentEquippedItem().getItem() == Itemss.manometer || ModInteractionUtils.getInstance().isModdedWrench(player.getCurrentEquippedItem().getItem()))) return false;
    else {
        if(!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);

            List<ItemStack> returnedItems = new ArrayList<ItemStack>();
            if(te != null && !FluidUtils.tryInsertingLiquid(te, player.getCurrentEquippedItem(), player.capabilities.isCreativeMode, returnedItems)) {
                player.openGui(PneumaticCraft.instance, getGuiID().ordinal(), world, x, y, z);
            } else {
                if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().stackSize <= 0) {
                    player.setCurrentItemOrArmor(0, null);
                }
                for(ItemStack returnedItem : returnedItems) {
                    returnedItem = returnedItem.copy();
                    if(player.getCurrentEquippedItem() == null) {
                        player.setCurrentItemOrArmor(0, returnedItem);
                    } else {
                        player.inventory.addItemStackToInventory(returnedItem);
                    }
                }
            }
        }

        return true;
    }
}
 
Example 12
Source File: ModificationTable.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof INamedContainerProvider) {
            NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
        } else {
            throw new IllegalStateException("Our named container provider is missing!");
        }
        return ActionResultType.SUCCESS;
    }
    return ActionResultType.SUCCESS;
}
 
Example 13
Source File: GuiHandler.java    From AdvancedMod with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){
    switch(GuiIDs.values()[ID]){
        case CAMO_MINE:
            return new ContainerCamoMine(player.inventory, (TileEntityCamoMine)world.getTileEntity(x, y, z));
    }
    throw new IllegalArgumentException("No gui with id " + ID);
}
 
Example 14
Source File: MessageSyncTileEntity.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void processMessage(final MessageSyncTileEntity message, EntityPlayer player)
{
    World world = player.getEntityWorld();
    TileEntity te = world.getTileEntity(message.pos);

    if (te instanceof ISyncableTile)
    {
        ISyncableTile syncable = (ISyncableTile) te;
        syncable.syncTile(message.intValues, message.stacks);
    }
}
 
Example 15
Source File: OpenBlock.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, BlockPos blockPos, IBlockState state, EntityLivingBase placer, @Nonnull ItemStack stack) {
	super.onBlockPlacedBy(world, blockPos, state, placer, stack);

	if (hasCapability(TileEntityCapability.PLACE_LISTENER)) {
		final TileEntity te = world.getTileEntity(blockPos);
		if (te instanceof IPlaceAwareTile)
			((IPlaceAwareTile)te).onBlockPlacedBy(state, placer, stack);
	}
}
 
Example 16
Source File: BlockInfestedLeaves.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
public static void infestLeafBlock(World world, BlockPos pos) {
	IBlockState block = world.getBlockState(pos);

	if (block.getBlock().isLeaves(block, world, pos) && !block.getBlock().equals(ENBlocks.infestedLeaves)) {
		world.setBlockState(pos, ENBlocks.infestedLeaves.getDefaultState());

		TileInfestedLeaves tile = (TileInfestedLeaves) world.getTileEntity(pos);

		if (tile != null) {
			tile.setLeafBlock(block);
		}
	}
}
 
Example 17
Source File: BlockBaseContainer.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
    int facing = MathHelper.floor_double(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
    TileEntityEMT tile = (TileEntityEMT) world.getTileEntity(x, y, z);

    if (facing == 0)
        tile.facing = 2;
    else if (facing == 1)
        tile.facing = 5;
    else if (facing == 2)
        tile.facing = 3;
    else if (facing == 3)
        tile.facing = 4;
}
 
Example 18
Source File: ClientProxy.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    switch (ID) {
        case 0:
            return new GuiGolem(player, (EntityGolemBase) world.getEntityByID(x));
            //return new AdditionalGolemGui(player, (EntityGolemBase)world.getEntityByID(x));
        case 1:
            return new InfusionClawGui(player.inventory, (IInventory) world.getTileEntity(x, y, z));
        case 2:
            return new ArcanePackagerGui(player.inventory, (IInventory) world.getTileEntity(x, y, z));
    }
    return null;
}
 
Example 19
Source File: MonolithGenerator.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void placeChest(World world, BlockPos placementPos) {
	setBlockAndNotifyAdequately(world, placementPos, Blocks.CHEST.getDefaultState());
	TileEntity tileentity = world.getTileEntity(placementPos);
	if (tileentity instanceof TileEntityChest) {
		((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_END_CITY_TREASURE, world.rand.nextLong());
	}
}
 
Example 20
Source File: ItemWrench.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos,
    EnumHand hand,
    EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
        return EnumActionResult.SUCCESS;
    }

    if (player.isSneaking() && !VSConfig.wrenchModeless) {
        this.mode = EnumWrenchMode.values()[(this.mode.ordinal() + 1) % EnumWrenchMode.values().length]; // Switch to the next mode
        player.sendMessage(new TextComponentString(
            TextFormatting.BLUE + I18n.format("tooltip.vs_control.wrench_switched", this.mode.toString()))); // Say in chat
        return EnumActionResult.SUCCESS;
    }

    TileEntity blockTile = worldIn.getTileEntity(pos);
    boolean shouldConstruct = this.mode == EnumWrenchMode.CONSTRUCT || VSConfig.wrenchModeless;
    boolean shouldDeconstruct = this.mode == EnumWrenchMode.DECONSTRUCT || VSConfig.wrenchModeless;
    if (blockTile instanceof ITileEntityMultiblockPart) {
        ITileEntityMultiblockPart part = (ITileEntityMultiblockPart) blockTile;
        shouldConstruct = shouldConstruct && !part.isPartOfAssembledMultiblock();
        shouldDeconstruct = shouldDeconstruct && part.isPartOfAssembledMultiblock();
    } else if (blockTile instanceof TileEntityGearbox) {
        shouldConstruct = true;
    } else {
        return EnumActionResult.PASS;
    }
    if (shouldConstruct) {
        if (blockTile instanceof ITileEntityMultiblockPart) {
            if (((ITileEntityMultiblockPart) blockTile).attemptToAssembleMultiblock(worldIn, pos, facing)) {
                return EnumActionResult.SUCCESS;
            }
        } else if (blockTile instanceof TileEntityGearbox) {
            ((TileEntityGearbox) blockTile).setInputFacing(
                player.isSneaking() ? facing.getOpposite() : facing);
        }
    } else if (shouldDeconstruct) {
        ((ITileEntityMultiblockPart) blockTile).disassembleMultiblock();
        return EnumActionResult.SUCCESS;
    }

    return EnumActionResult.PASS;
}