当前位置: 首页>>代码示例>>Java>>正文


Java TileEntity.getCapability方法代码示例

本文整理汇总了Java中net.minecraft.tileentity.TileEntity.getCapability方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntity.getCapability方法的具体用法?Java TileEntity.getCapability怎么用?Java TileEntity.getCapability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.tileentity.TileEntity的用法示例。


在下文中一共展示了TileEntity.getCapability方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEvaluator

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(BlockPos pos) {
            TileEntity te = drone.world().getTileEntity(pos);
            int count = 0;
            if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null) ) {
                IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
                for (IFluidTankProperties prop : handler.getTankProperties()) {
                    FluidStack stack = prop.getContents();
                    if (stack != null) {
                        if (ProgWidgetLiquidFilter.isLiquidValid(stack.getFluid(), widget, 1)) {
                            count += stack.amount;
                        }
                    }
                }
            } else {
                Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock());
                if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.world(), pos)) {
                    count += 1000;
                }
            }
            return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ?
                    count == ((ICondition) widget).getRequiredCount() :
                    count >= ((ICondition) widget).getRequiredCount();
        }

    };
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:32,代码来源:ProgWidgetLiquidInventoryCondition.java

示例2: getFluidHandler

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * Helper method to get an IFluidHandler for at a block position.
 *
 * Returns null if there is no valid fluid handler.
 */
@Nullable
public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side)
{
    IBlockState state = world.getBlockState(blockPos);
    Block block = state.getBlock();

    if (block.hasTileEntity(state))
    {
        TileEntity tileEntity = world.getTileEntity(blockPos);
        if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side))
        {
            return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        }
    }
    else if (block instanceof IFluidBlock)
    {
        return new FluidBlockWrapper((IFluidBlock) block, world, blockPos);
    }
    else if (block instanceof BlockLiquid)
    {
        return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos);
    }

    return null;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:31,代码来源:FluidUtil.java

示例3: extract

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public static ItemStack extract(TileEntity tile, EnumFacing from, boolean fullStack) {

		if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from)) {
			IItemHandlerModifiable handler = (IItemHandlerModifiable) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from);
			if (handler != null) {
				int invSize = handler.getSlots();

				for (int i = 0; i < invSize; i++) {
					ItemStack current = handler.getStackInSlot(i);

					if (current != null && !current.isEmpty() && current.getItem() != Items.AIR) {
						ItemStack stack = handler.extractItem(i, !fullStack ? 1 : current.getCount(), false);
						return stack;
					}
				}
			}
		} // TODO: TileEntities that don't have capabilities - needs testing

		return null;
	}
 
开发者ID:oMilkyy,项目名称:SimpleTubes,代码行数:21,代码来源:TubeUtil.java

示例4: update

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public void update() {
    this.ticksExisted ++;
    EnumFacing facing = world.getBlockState(pos).getValue(BlockEmberEmitter.facing);
    BlockPos attachPos = pos.offset(facing, -1);
    TileEntity attachTile = world.getTileEntity(attachPos);
    if (ticksExisted % 2 == 0 && attachTile != null){
        if (attachTile.hasCapability(EmberCapabilityProvider.emberCapability, null)){
            IEmberCapability cap = attachTile.getCapability(EmberCapabilityProvider.emberCapability, null);
            if (cap != null){
                if (cap.getEmber() < cap.getEmberCapacity() && capability.getEmber() > 0){
                    double added = cap.addAmount(Math.min(TRANSFER_SPEED,capability.getEmber()), true);
                    double removed = capability.removeAmount(added, true);
                    markDirty();
                    attachTile.markDirty();
                    if (!(attachTile instanceof ITileEntityBase) && !world.isRemote){
                        attachTile.markDirty(); //Idk why this is duplicated but the github source has it, so I carried it over.
                        EventManager.markTEForUpdate(attachPos, attachTile);
                    }
                }
            }
        }
    }
}
 
开发者ID:DaedalusGame,项目名称:Soot,代码行数:25,代码来源:TileEntityEmberFunnel.java

示例5: onItemUse

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if(player.getHeldItem(hand).getCount() == 1){
        TileEntity tile = world.getTileEntity(pos);
        if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, facing)){
            if(!world.isRemote){
                IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, facing);
                if(energy != null && energy.canExtract()){
                    IEnergyStorage storage = player.getHeldItem(hand).getCapability(CapabilityEnergy.ENERGY, null);
                    if(storage != null && storage.canReceive()){
                        storage.receiveEnergy(energy.extractEnergy(storage.receiveEnergy(Integer.MAX_VALUE, true), false), false);
                    }
                }
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
 
开发者ID:canitzp,项目名称:Metalworks,代码行数:21,代码来源:ItemBattery.java

示例6: transmitEnergy

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public int transmitEnergy(BlockPos from, int energy, boolean simulate){
    int oldEnergy = energy;
    for(Map.Entry<BlockPos, EnumFacing> entry : this.receiver.entrySet()){
        TileEntity tile = this.world.getTileEntity(entry.getKey());
        if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, entry.getValue())){
            IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, entry.getValue());
            if(storage != null && storage.canReceive()){
                energy -= storage.receiveEnergy(energy, simulate);
            }
        }
        if(energy <= 0){
            return oldEnergy;
        }
    }
    return oldEnergy - energy;
}
 
开发者ID:canitzp,项目名称:Metalworks,代码行数:17,代码来源:Network.java

示例7: attemptFETransfer

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private int attemptFETransfer(EnumFacing face, int maxTransferLeft) {
    BlockPos at = this.getPos().offset(face);
    EnumFacing accessingSide = face.getOpposite();

    int receivedEnergy = 0;
    TileEntity te = world.getTileEntity(at);
    if(te != null && !(te instanceof TileEnergyHatch)) {
        if(te.hasCapability(CapabilityEnergy.ENERGY, accessingSide)) {
            net.minecraftforge.energy.IEnergyStorage ce = te.getCapability(CapabilityEnergy.ENERGY, accessingSide);
            if(ce != null && ce.canReceive()) {
                receivedEnergy = ce.receiveEnergy(maxTransferLeft, false);
            }
        }
    }
    return receivedEnergy;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:17,代码来源:TileEnergyOutputHatch.java

示例8: putInventoryInChestWithMessage

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private void putInventoryInChestWithMessage(BlockPos pos, String message, String... parameters) {
    if (!InventoryTools.isInventory(entity.getEntityWorld(), pos)) {
        // No longer an inventory here. Just drop the items on the ground here
        if (message != null) {
            showMessage("message.meecreeps.inventory_missing");
        }
        entity.dropInventory();
    } else {
        if (message != null) {
            showMessage(message, parameters);
        }
        TileEntity te = entity.getEntityWorld().getTileEntity(pos);
        IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
        for (ItemStack stack : entity.getInventory()) {
            if (!stack.isEmpty()) {
                ItemStack remaining = ItemHandlerHelper.insertItem(handler, stack, false);
                if (!remaining.isEmpty()) {
                    entity.entityDropItem(remaining, 0.0f);
                }
            }
        }
        entity.getInventory().clear();
    }
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:25,代码来源:WorkerHelper.java

示例9: breakBlock

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
       TileEntity tileentity = worldIn.getTileEntity(pos);
       
       if (tileentity!=null && tileentity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
       	IItemHandler inventory = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
       	for (int i=0; i<inventory.getSlots(); i++) {
               ItemStack itemstack = inventory.getStackInSlot(i);

               if (!itemstack.isEmpty()) {
                   InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), itemstack);
               }
           }
       	worldIn.updateComparatorOutputLevel(pos, this);
       }
       super.breakBlock(worldIn, pos, state);
   }
 
开发者ID:elytra,项目名称:Thermionics,代码行数:18,代码来源:BlockMachineBase.java

示例10: pushEnergy

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
protected boolean pushEnergy() {
    boolean pushed = false;
    for(EnumFacing dir : EnumFacing.VALUES) {
        TileEntity tile = world.getTileEntity(getPos().offset(dir));
        if(tile != null)
            if(tile.hasCapability(TeslaCapabilities.CAPABILITY_CONSUMER, dir.getOpposite())) {
                BaseTeslaContainer cont = (BaseTeslaContainer) tile.getCapability(TeslaCapabilities.CAPABILITY_CONSUMER, dir.getOpposite());
                container.takePower(cont.givePower(container.takePower(container.getOutputRate(), true), false), false);
                if(!world.isRemote) {
                    tile.markDirty();
                    markDirty();
                    pushed = true;
                }
            }
    }
    return pushed;
}
 
开发者ID:jaredlll08,项目名称:Machines-and-Stuff,代码行数:18,代码来源:GeneratorBase.java

示例11: getInventory

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private Pair<IItemHandler, ISidedInventory> getInventory(BlockPos target, EnumFacing facing) {
	if(world.isBlockLoaded(target, false)) {
		TileEntity tile = world.getTileEntity(target);
		if(tile != null) {
			IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
			if(handler == null) handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
			return Pair.of(handler, tile instanceof ISidedInventory ? (ISidedInventory) tile : null);
		}
	}
	return Pair.of(null, null);
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:12,代码来源:TileGravityHopper.java

示例12: onBlockActivated

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer p, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    TileEntity te = worldIn.getTileEntity(pos);
    if (te != null && te instanceof TileAbstractSingleItem)
    {
        TileAbstractSingleItem tasi = (TileAbstractSingleItem) te;
        IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        ItemStack held = p.getHeldItem(hand);
        if (!p.isSneaking() && (tasi.isItemValid(held)))
        {
            ItemStack st = handler.insertItem(0, held, false);
            if(!ItemStack.areItemStacksEqualUsingNBTShareTag(st, held))
            {
                p.setHeldItem(hand, st);
                return true;
            }
        }
        if (p.isSneaking() && !handler.getStackInSlot(0).isEmpty())
        {
            p.inventory.addItemStackToInventory(handler.getStackInSlot(0));
            ItemStackUtils.extractAll(handler, 0);
            return true;
        }
        openClientGui(worldIn, pos, state, p, hand, facing, hitX, hitY, hitZ, tasi);
        return true;
    }
    return false;
}
 
开发者ID:PearXTeam,项目名称:PurificatiMagicae,代码行数:30,代码来源:BlockAbstractSingleItemHorizontal.java

示例13: attemptInsert

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private void attemptInsert(TileEntity te, EnumFacing facing)
{
	IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
	ItemStack returned = ItemHandlerHelper.insertItem(itemHandler, getItem(), false);
	if(!returned.isEmpty())
	{
		onInvalidArrival(returned);
	}
	this.setDead();
}
 
开发者ID:Lemonszz,项目名称:Anima-Mundi,代码行数:11,代码来源:EntityNodeItem.java

示例14: doInteract

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public boolean doInteract(BlockPos pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate) {
    if (!drone.hasCapability(CapabilityEnergy.ENERGY, null)) return false;

    IEnergyStorage droneStorage = drone.getCapability(CapabilityEnergy.ENERGY, null);
    if (droneStorage.getEnergyStored() == droneStorage.getMaxEnergyStored()) {
        interactHandler.abort();
        return false;
    } else {
        TileEntity te = drone.world().getTileEntity(pos);
        if (te == null) return false;
        for (EnumFacing face : EnumFacing.values()) {
            if (te.hasCapability(CapabilityEnergy.ENERGY, face)) {
                IEnergyStorage teStorage = te.getCapability(CapabilityEnergy.ENERGY, face);
                int transferredEnergy = droneStorage.receiveEnergy(
                        teStorage.extractEnergy(interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
                if (transferredEnergy > 0) {
                    if (!simulate) {
                        interactHandler.decreaseCount(transferredEnergy);
                        droneStorage.receiveEnergy(transferredEnergy, false);
                        teStorage.extractEnergy(transferredEnergy, false);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:30,代码来源:DroneInteractRFImport.java

示例15: getInventory

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private Pair<IItemHandler, ISidedInventory> getInventory(EnumFacing facing) {
	BlockPos target = getPos().offset(facing);
	if(world.isBlockLoaded(target, false)) {
		TileEntity tile = world.getTileEntity(target);
		if(tile != null) {
			IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
			if(handler == null) handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
			return Pair.of(handler, tile instanceof ISidedInventory ? (ISidedInventory) tile : null);
		}
	}
	return Pair.of(null, null);
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:13,代码来源:TileVacuumConveyor.java


注:本文中的net.minecraft.tileentity.TileEntity.getCapability方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。