本文整理汇总了Java中net.minecraftforge.common.capabilities.ICapabilityProvider类的典型用法代码示例。如果您正苦于以下问题:Java ICapabilityProvider类的具体用法?Java ICapabilityProvider怎么用?Java ICapabilityProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ICapabilityProvider类属于net.minecraftforge.common.capabilities包,在下文中一共展示了ICapabilityProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAttach
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@SubscribeEvent
public void onAttach(AttachCapabilitiesEvent event)
{
Map<ResourceLocation, ICapabilityProvider> map = Maps.newHashMap();
if (event instanceof AttachCapabilitiesEvent.Item)
handle(map, event.getObject(), ((AttachCapabilitiesEvent.Item) event).getItemStack());
else if (event instanceof AttachCapabilitiesEvent.Entity)
handle(map, event.getObject(), ((AttachCapabilitiesEvent.Entity) event).getEntity());
else if (event instanceof AttachCapabilitiesEvent.TileEntity)
handle(map, event.getObject(), ((AttachCapabilitiesEvent.TileEntity) event).getTileEntity());
else
handle(map, event.getObject(), event.getObject());
for (ICapabilityProvider iCapabilityProvider : event.getCapabilities().values())
handle(map, iCapabilityProvider, event.getObject());
for (Map.Entry<ResourceLocation, ICapabilityProvider> entry : map.entrySet())
event.addCapability(entry.getKey(), entry.getValue());
}
示例2: lookFor
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public void lookFor(LazyEnergyCapProvider lecp, FluxCompat.Registry r) {
final ICapabilityProvider icp = lecp.getObject();
if (icp == null) return;
EnumFacing f = null;
try {
for (int i = 0; i < U.FANCY_FACING.length; i++) {
f = U.FANCY_FACING[i];
if (TeslaUtils.hasTeslaSupport(icp, f)) {
r.register(EnergyType.TESLA, TeslaFluxCompat::factorize);
}
}
} catch (Exception e) {
MCFluxReport.addErrMsg(new ErrMsg.BadImplementation("TESLA", icp.getClass(), e, f));
}
}
示例3: lookFor
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public void lookFor(LazyEnergyCapProvider lecp, FluxCompat.Registry r) {
final ICapabilityProvider icp = lecp.getObject();
if (icp == null || icp instanceof TileEntityFluxGen || blacklist(icp)) return;
EnumFacing f = null;
try {
for (int i = 0; i < U.FANCY_FACING.length; i++) {
f = U.FANCY_FACING[i];
if (icp.hasCapability(CapabilityEnergy.ENERGY, f)) {
r.register(EnergyType.FORGE_ENERGY, ForgeFluxCompat::forgeFactorize);
}
}
} catch (Exception e) {
MCFluxReport.addErrMsg(new ErrMsg.BadImplementation("Forge Energy", icp.getClass(), e, f));
}
}
示例4: forgeFactorize
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
private static void forgeFactorize(LazyEnergyCapProvider lecp) {
final ICapabilityProvider icp = lecp.getObject();
Energy[] es = new Energy[7];
EnumFacing f;
int[] s = new int[7];
int x = 0, i;
M:
for (i = 0; i < U.FANCY_FACING.length; i++) {
f = U.FANCY_FACING[i];
IEnergyStorage ies = icp.getCapability(CapabilityEnergy.ENERGY, f);
for (int j = 0; j < x; j++) {
if (es[j].storage == ies) {
s[i] = j;
continue M;
}
}
es[x] = new Energy(ies);
s[i] = x++;
}
lecp.update(es, s, null, false);
if (es[0] != null && es[0].storage != null)
CloudUtils.reportEnergy(icp.getClass(), es[0].storage.getClass(), "forge");
}
示例5: onPlayerClone
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@SubscribeEvent
@SuppressWarnings("unused")
public void onPlayerClone(PlayerEvent.Clone event) {
EntityPlayer oldPlayer = event.getOriginal();
EntityPlayer newPlayer = event.getEntityPlayer();
if(oldPlayer != null && newPlayer != null && !oldPlayer.getEntityWorld().isRemote) {
List<ICapabilityImplementation<ICapabilityProvider, ? extends ISerializable>> list = this.map.get(oldPlayer.getClass());
if(list == null) {
return;
}
list.stream()
.filter(impl -> EntityPlayer.class.isAssignableFrom(impl.getCarrierClass()))
.filter(impl -> oldPlayer.hasCapability(impl.getCapability(), null))
.forEach(impl -> {
ISerializable oldProps = oldPlayer.getCapability(impl.getCapability(), null);
ISerializable newProps = oldPlayer.getCapability(impl.getCapability(), null);
if(newProps != null && oldProps != null) {
newProps.readFromNBT(oldProps.writeToNBT());
}
});
}
}
示例6: onTileEntityCapabilityAttachEvent
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
public void onTileEntityCapabilityAttachEvent(AttachCapabilitiesEvent<TileEntity> event){
ICapabilityProvider provider = new CapabilityDestinationProvider.Provider();
boolean requiresCap = false;
CapabilityDestinationProvider cap = provider.getCapability(CapabilityDestinationProvider.INSTANCE, null);
for(IDestinationProvider destinationProvider : destinationProviders) {
if(destinationProvider.isTileEntityApplicable(event.getObject())) {
try {
cap.addDestinationProvider(destinationProvider.getClass().newInstance());
if(!requiresCap) {
requiresCap = true;
event.addCapability(new ResourceLocation(Constants.MOD_ID, "destinationProviderCapability"), provider);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
示例7: exportStackToInventory
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Nonnull
public static ItemStack exportStackToInventory(ICapabilityProvider provider, ItemStack stack, EnumFacing side) {
if (provider.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
IItemHandler handler = provider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
return ItemHandlerHelper.insertItem(handler, stack, false);
}
return stack;
}
示例8: insert
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Nonnull
public static ItemStack insert(ICapabilityProvider provider, ItemStack itemStack, EnumFacing side, boolean simulate) {
if (provider.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
IItemHandler handler = provider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
return ItemHandlerHelper.insertItem(handler, itemStack, simulate);
}
return ItemStack.EMPTY;
}
示例9: initCapabilities
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public ICapabilityProvider initCapabilities(@Nonnull ItemStack stack, @Nullable NBTTagCompound nbt) {
return new FluidHandlerItemStack(stack,capacity)
{
@Override
public int fill(FluidStack resource, boolean doFill) {
if(resource == null || resource.amount < capacity)
return 0;
return super.fill(resource, doFill);
}
};
}
示例10: initCapabilities
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Nullable
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
FluidHandlerItemStack handlerItemStack = new FluidHandlerItemStack(stack, 128000) {
@Override
public boolean canFillFluidType(FluidStack fluid) {
return fluid.getFluid().equals(FluidsRegistry.MEAT);
}
};
handlerItemStack.fill(new FluidStack(FluidsRegistry.MEAT, 0), true);
return handlerItemStack;
}
示例11: initCapabilities
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
return new CapProviderItem(Pair.of(CapabilityEnergy.ENERGY, new ItemEnergyStorage(stack, this.maxEnergy, this.maxReceive, this.maxTransmit)));
}
示例12: initCapabilities
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public ICapabilityProvider initCapabilities() {
if(m_realProvider != null) {
return m_realProvider.initCapabilities();
} else {
return super.initCapabilities();
}
}
示例13: initCapabilities
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public ICapabilityProvider initCapabilities() {
if (m_proxyProvider != null && Util.isPrefixInCallStack(m_modPrefix)) {
return m_proxyProvider.initCapabilities();
} else if (m_realProvider != null) {
return m_realProvider.initCapabilities();
} else {
return super.initCapabilities();
}
}
示例14: copyInventory
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
private void copyInventory(ICapabilityProvider from, int[][] fromSlotIds, TileEntityIronFurnace to)
{
FurnaceType type = to.getType();
int[][] toSlotIds = new int[][] {type.inputSlotIds, type.fuelSlotIds, type.outputSlotIds};
IItemHandlerModifiable fromHandler = (IItemHandlerModifiable) from.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
IItemHandlerModifiable toHandler = (IItemHandlerModifiable) to.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
copyInventory(fromHandler, fromSlotIds, toHandler, toSlotIds);
}
示例15: hasCapability
import net.minecraftforge.common.capabilities.ICapabilityProvider; //导入依赖的package包/类
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{
return sender instanceof ICapabilityProvider
&& ((ICapabilityProvider) sender).hasCapability(capability, facing);
}