本文整理汇总了Java中net.minecraft.tileentity.TileEntity.hasCapability方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntity.hasCapability方法的具体用法?Java TileEntity.hasCapability怎么用?Java TileEntity.hasCapability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.tileentity.TileEntity
的用法示例。
在下文中一共展示了TileEntity.hasCapability方法的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();
}
};
}
示例2: getSearchedItemCount
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private int getSearchedItemCount() {
TileEntity te = world.getTileEntity(pos);
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
// if (world.getTileEntity(pos) instanceof IInventory) {
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
int itemCount = 0;
// IInventory inventory = (IInventory) world.getTileEntity(pos);
ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().player.getItemStackFromSlot(EntityEquipmentSlot.HEAD));
if (searchStack.isEmpty()) return 0;
for (int l = 0; l < handler.getSlots(); l++) {
if (!handler.getStackInSlot(l).isEmpty()) {
itemCount += getSearchedItemCount(handler.getStackInSlot(l), searchStack);
}
}
return itemCount;
}
return 0;
}
示例3: amountRequested
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public int amountRequested(FluidStack stack) {
int totalRequestingAmount = getTotalRequestedAmount(stack);
if (totalRequestingAmount > 0) {
TileEntity te = getTileEntity();
int count = 0;
for (EnumFacing facing : EnumFacing.VALUES) {
if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) {
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
for (IFluidTankProperties properties : handler.getTankProperties()) {
FluidStack contents = properties.getContents();
if (contents != null && contents.getFluid() == stack.getFluid()) {
count += contents.amount;
}
}
if (count > 0) break;
}
}
if (count == 0) return 0;
count += getIncomingFluid(stack.getFluid());
return Math.max(0, Math.min(stack.amount, totalRequestingAmount - count));
}
return 0;
}
示例4: 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;
}
示例5: addProbeInfo
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
@Optional.Method(modid = "theoneprobe")
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
TileEntity te = world.getTileEntity(data.getPos());
if(te instanceof IInfoForwarder){
te = ((IInfoForwarder)te).getInfoTileEntity();
}
if (te instanceof IPneumaticMachine) {
TOPCallback.handlePneumatic(mode, probeInfo, (IPneumaticMachine)te);
}
if (te instanceof IHeatExchanger) {
TOPCallback.handleHeat(mode, probeInfo, (IHeatExchanger) te);
}
if (ConfigHandler.client.topShowsFluids && te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit())) {
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit());
TOPCallback.handleFluidTanks(mode, probeInfo, handler);
}
if (te instanceof TileEntityBase) {
TOPCallback.handleRedstoneMode(mode, probeInfo, (TileEntityBase) te);
}
if (te instanceof TileEntityPressureTube) {
TOPCallback.handlePressureTube(mode, probeInfo, (TileEntityPressureTube) te, data.getSideHit());
}
}
示例6: 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);
}
}
}
}
}
}
示例7: isSideValid
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private List<EnumFacing> isSideValid(IBlockAccess world, BlockPos pos){
List<EnumFacing> sides = new ArrayList<>();
for(EnumFacing side : EnumFacing.values()){
TileEntity tile = world.getTileEntity(pos.offset(side));
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, side)){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side);
if(storage != null && (storage.canReceive() || storage.canExtract())){
sides.add(side);
}
}
}
return sides;
}
示例8: shouldTrackWithThisEntry
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public boolean shouldTrackWithThisEntry(IBlockAccess world, BlockPos pos, IBlockState state, TileEntity te) {
if (te instanceof TileEntityChest) {
TileEntityChest chest = (TileEntityChest) te;
if (chest.adjacentChestXNeg != null || chest.adjacentChestZNeg != null) return false;
}
return te != null
&& !invBlackList.contains(TileEntity.getKey(te.getClass()))
&& te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)
&& !MinecraftForge.EVENT_BUS.post(new InventoryTrackEvent(te));
}
示例9: emptyTank
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private boolean emptyTank(BlockPos pos, boolean simulate) {
if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
abort();
return false;
} else {
TileEntity te = drone.world().getTileEntity(pos);
if (te != null) {
for (int i = 0; i < 6; i++) {
if (((ISidedWidget) widget).getSides()[i] && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i))) {
IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i));
FluidStack importedFluid = handler.drain(Integer.MAX_VALUE, false);
if (importedFluid != null && ((ILiquidFiltered) widget).isFluidValid(importedFluid.getFluid())) {
int filledAmount = drone.getTank().fill(importedFluid, false);
if (filledAmount > 0) {
if (((ICountWidget) widget).useCount())
filledAmount = Math.min(filledAmount, getRemainingCount());
if (!simulate) {
decreaseCount(drone.getTank().fill(handler.drain(filledAmount, true), true));
}
return true;
}
}
}
}
drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos);
} else if (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000) {
Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock());
if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.world(), pos)) {
if (!simulate) {
decreaseCount(1000);
drone.getTank().fill(new FluidStack(fluid, 1000), true);
drone.world().setBlockToAir(pos);
}
return true;
}
}
return false;
}
}
示例10: update
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public void update() {
if (hasFuel()) {
ItemStack melt = inventory.getStackInSlot(0);
MeltingRecipe recipe = MelteryHandler.getMelteryRecipe(melt);
if (recipe != null) {
if (progress > recipe.getUsableTemperature()) {
FluidStack fluidStack = recipe.getResult();
if ((tank.getCapacity() - tank.getFluidAmount()) >= tank.fill(fluidStack, false)) {
tank.fill(fluidStack, true);
world.playSound(null, pos, SoundEvents.ITEM_BUCKET_FILL_LAVA, SoundCategory.BLOCKS, 1.0f, 0.75f);
melt.shrink(1);
} else {
world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 0.75f);
}
setProgress(0);
}
incrementProcress();
}
}
if(tank.getFluidAmount() > 0) {
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
BlockPos side = pos.offset(facing);
if (!world.isAirBlock(side)) {
if (world.getTileEntity(side) != null) {
TileEntity tile = world.getTileEntity(side);
if (!(tile instanceof TileMeltery) && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) {
IFluidHandler fluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
if (fluidHandler instanceof IFluidTank) {
FluidUtil.tryFluidTransfer(fluidHandler, tank, 140, true);
}
}
}
}
}
}
}
示例11: extract
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public static Pair<ItemStack, Integer> extract(TileEntity tile, EnumFacing from, int[] col, IInventory inv, 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);
for (int j = 0; j < inv.getSizeInventory(); j++) {
ItemStack stack = inv.getStackInSlot(j);
int color = -1;
if (stack != null && stack != ItemStack.EMPTY && stack.getItem() != Items.AIR) {
if (areItemStacksEqual(stack, current)) {
int column = j >= 0 && j <= 3 ? 0 : j >= 4 && j <= 7 ? 1 : j >= 8 && j <= 11 ? 2 : j >= 12 && j <= 15 ? 3 : j >= 16 || j <= 19 ? 4 : -1;
if (column == -1)
return null;
color = col[column];
if (current != null && !current.isEmpty() && current.getItem() != Items.AIR) {
ItemStack extracted = handler.extractItem(i, !fullStack ? 1 : current.getCount(), false);
return Pair.of(extracted, color);
}
}
}
}
}
}
} // TODO: TileEntities that don't have capabilities - needs testing
return Pair.of(ItemStack.EMPTY, -1);
}
示例12: isValidPosition
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
protected boolean isValidPosition(BlockPos pos) {
if (traversedPositions.add(pos)) {
curSlot = 0;
TileEntity te = drone.world().getTileEntity(pos);
return te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
}
return false;
}
示例13: getStorage
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public static IHeatStorage getStorage(World world, BlockPos pos, EnumFacing side) {
TileEntity te = world.getTileEntity(pos);
if (te==null) return NULL_HEAT; //If it can't Capabilities, it can't IHeatStorage
if (te.hasCapability(Thermionics.CAPABILITY_HEATSTORAGE, side)) {
return te.getCapability(Thermionics.CAPABILITY_HEATSTORAGE, side);
} else {
return NULL_HEAT; //Some day we might support other APIs. Not today.
}
}
示例14: getConnectedInventory
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private IItemHandler getConnectedInventory() {
if (connectedInventory == null) {
connectedInventory = new TileEntityCache(pressureTube.world(), pressureTube.pos().offset(dir));
}
TileEntity te = connectedInventory.getTileEntity();
return te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite()) ?
te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite()) :
null;
}
示例15: detectAndSendChanges
import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (te.getWorld().getTotalWorldTime() % 20 == 0) {
for (EnumFacing d : EnumFacing.VALUES) {
TileEntity neighbor = te.getWorld().getTileEntity(te.getPos().offset(d));
if (neighbor != null && neighbor.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d.getOpposite())) {
sendToContainerListeners(new PacketSendNBTPacket(neighbor));
}
}
}
}