本文整理汇总了Java中net.minecraftforge.energy.CapabilityEnergy类的典型用法代码示例。如果您正苦于以下问题:Java CapabilityEnergy类的具体用法?Java CapabilityEnergy怎么用?Java CapabilityEnergy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CapabilityEnergy类属于net.minecraftforge.energy包,在下文中一共展示了CapabilityEnergy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEvaluator
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的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);
if (te == null) return false;
int energy = 0;
for (EnumFacing face : EnumFacing.values()) {
if (te.hasCapability(CapabilityEnergy.ENERGY, face)) {
IEnergyStorage storage = te.getCapability(CapabilityEnergy.ENERGY, face);
energy = Math.max(storage.getEnergyStored(), energy);
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ?
energy == ((ICondition) widget).getRequiredCount() :
energy >= ((ICondition) widget).getRequiredCount();
}
};
}
示例2: getCapability
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@Nullable
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
if (facing == null) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler);
switch (facing) {
case UP:
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerArmorInvHandler);
case DOWN:
return super.getCapability(capability, facing);
default:
return dispenserUpgradeInserted ?
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerFoodHandler) :
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(playerMainInvHandler);
}
} else if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && dispenserUpgradeInserted) {
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(playerExperienceHandler);
} else if (capability == CapabilityEnergy.ENERGY) {
return CapabilityEnergy.ENERGY.cast(energyRF);
}
return super.getCapability(capability, facing);
}
示例3: protectedUpdate
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@Override
public void protectedUpdate() {
super.protectedUpdate();
if (hasAddon(EnergyFieldAddon.class)) {
ItemStack addon = getAddonStack(EnergyFieldAddon.class);
if (addon.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage storage = addon.getCapability(CapabilityEnergy.ENERGY, null);
storage.extractEnergy((int) this.getEnergyStorage().givePower(storage.extractEnergy(512, true)), false);
BlockPos pos = ItemRegistry.energyFieldAddon.getLinkedBlockPos(addon);
if (this.world.getBlockState(pos).getBlock() instanceof EnergyFieldProviderBlock && this.world.isAreaLoaded(pos, pos)) {
EnergyFieldProviderTile tile = (EnergyFieldProviderTile) this.world.getTileEntity(pos);
if (tile.getWorkingArea().grow(1).contains(new Vec3d(this.pos.getX(), this.pos.getY(), this.pos.getZ()))) {
float pull = tile.consumeWorkEnergy(Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), 1000));
storage.receiveEnergy((int) pull, false);
}
}
this.forceSync();
}
}
}
示例4: onItemUse
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的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);
}
示例5: getCapability
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){
IItemHandler inventory = getInventory(facing);
if(inventory != null){
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory);
}
}
if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
IFluidHandler tank = getTank(facing);
if(tank != null){
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank);
}
}
if(capability == CapabilityEnergy.ENERGY){
IEnergyStorage energy = getEnergy(facing);
if(energy != null){
return CapabilityEnergy.ENERGY.cast(energy);
}
}
return null;
}
示例6: readCapabilities
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
protected void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){
IItemHandler inventory = this.getInventory(side);
if(inventory != null && inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")){
for(int i = 0; i < inventory.getSlots(); i++){ // clear the inventory, otherwise empty stacks doesn't get overriden while syncing. Forge Bug?
((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY);
}
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory"));
}
IFluidHandler tank = getTank(side);
if(tank != null && tank instanceof IFluidTank && nbt.hasKey("FluidTank")){
CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank"));
}
IEnergyStorage energy = getEnergy(side);
if(energy != null && energy instanceof EnergyStorage && nbt.hasKey("Energy")){
CapabilityEnergy.ENERGY.readNBT(energy, side, nbt.getTag("Energy"));
}
}
示例7: recursive
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
private void recursive(BlockPos from, List<BlockPos> searched, List<BlockPos> found, Map<BlockPos, EnumFacing> receivers){
for(EnumFacing side : EnumFacing.values()){
BlockPos newPos = from.offset(side);
if(!searched.contains(newPos)){
searched.add(newPos);
TileEntity tile = this.world.getTileEntity(newPos);
if(tile != null){
if(tile instanceof TileCableBasic){
found.add(newPos);
((TileCableBasic) tile).network = this;
recursive(newPos, searched, found, receivers);
} else if(tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
if(storage != null && storage.canReceive()){
receivers.put(newPos, side.getOpposite());
}
}
}
}
}
}
示例8: transmitEnergy
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的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;
}
示例9: chargeItem
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
/**
*
* @param stack Inputstack
* @param energy Energy the item should receive
* @param simulate If true will only simulate
* @param tier IC2 charge tier
* @param ignoreChargeLimit IC2 ignore charge limit
* @return The amount of energy accepted
*/
public static int chargeItem(ItemStack stack, int energy, boolean simulate, int tier, boolean ignoreChargeLimit) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage cap = stack.getCapability(CapabilityEnergy.ENERGY, null);
return cap.receiveEnergy(energy, simulate);
} else if (Main.teslaLoaded && TeslaCompat.hasTesla(stack)) {
return TeslaCompat.chargeItem(stack, energy, simulate);
} else if (Main.redstonefluxLoaded && FluxCompat.hasFlux(stack)) {
return FluxCompat.chargeItem(stack, energy, simulate);
} else if (Main.immersiveLoaded && IECompat.hasIE(stack)) {
return IECompat.chargeItem(stack, energy, simulate);
} else if (Main.ic2Loaded && Config.allowIC2 && IC2Compat.hasIC2(stack)) {
return IC2Compat.chargeItem(stack, energy, simulate, tier, ignoreChargeLimit);
}
return 0;
}
示例10: internalExtractEnergy
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
private boolean internalExtractEnergy(ItemStack stack, int amount)
{
// check fuel type
if (UniversalRemoteConfiguration.fuel.fuelType.equals(UniversalRemoteConfiguration.FuelType.Energy.toString()) &&
UniversalRemoteConfiguration.fuel.energy.energyCapacity > 0)
{
ItemNBTEnergyStorage storage = (ItemNBTEnergyStorage) CapabilityHelper.tryGetCapability(stack, CapabilityEnergy.ENERGY, null);
int extractableAmount = storage.limitlessExtractEnergy(amount, true);
if (extractableAmount >= amount) {
storage.limitlessExtractEnergy(amount, false);
return true;
}
return false;
} else {
return true;
}
}
示例11: getTabIconItem
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@Override
public ItemStack getTabIconItem() {
// surely there is a better way to do this...
ItemStack stack = new ItemStack(ItemRegistry.Items().UniveralRemote, 1, 1);
// fill up the energy for the photo
ItemNBTEnergyStorage storage = (ItemNBTEnergyStorage) CapabilityHelper.tryGetCapability(stack, CapabilityEnergy.ENERGY, null);
// energy might be disabled!
if (storage != null)
{
storage.setEnergyStored(storage.getMaxEnergyStored());
}
return stack;
}
示例12: onPlayerPickup
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
public void onPlayerPickup(EntityItemPickupEvent e, ItemStack stack) {
applyNetwork(stack, n -> {
if (RSAddons.INSTANCE.config.networkBagUsesEnergy && stack.getItemDamage() != ItemNetworkBag.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RSAddons.INSTANCE.config.networkBagUsage) {
return;
}
if (!n.getSecurityManager().hasPermission(Permission.INSERT, e.getEntityPlayer())) {
return;
}
if (n.insertItem(e.getItem().getItem(), e.getItem().getItem().getCount(), true) == null) {
e.setResult(Event.Result.ALLOW);
e.setCanceled(true);
n.insertItem(e.getItem().getItem(), e.getItem().getItem().getCount(), false);
e.getItem().setDead();
if (RSAddons.INSTANCE.config.networkBagUsesEnergy && stack.getItemDamage() != ItemNetworkBag.TYPE_CREATIVE) {
stack.getCapability(CapabilityEnergy.ENERGY, null).extractEnergy(RSAddons.INSTANCE.config.networkBagUsage, false);
}
}
}, error -> {
// NO OP
});
}
示例13: onOpen
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@Override
public boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand) {
if (RSAddons.INSTANCE.config.wirelessCraftingGridUsesEnergy && stack.getItemDamage() != ItemWirelessCraftingGrid.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RSAddons.INSTANCE.config.wirelessCraftingGridOpenUsage) {
return false;
}
if (!network.getSecurityManager().hasPermission(Permission.MODIFY, player)) {
WorldUtils.sendNoPermissionMessage(player);
return false;
}
RSAddons.RSAPI.openWirelessGrid(player, hand, network.world().provider.getDimension(), WirelessCraftingGrid.ID);
network.sendItemStorageToClient((EntityPlayerMP) player);
drainEnergy(RSAddons.INSTANCE.config.wirelessCraftingGridOpenUsage);
return true;
}
示例14: preInit
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@Subscribe
public void preInit(FMLPreInitializationEvent evt)
{
CapabilityItemHandler.register();
CapabilityFluidHandler.register();
CapabilityAnimation.register();
CapabilityEnergy.register();
MinecraftForge.EVENT_BUS.register(MinecraftForge.INTERNAL_HANDLER);
ForgeChunkManager.captureConfig(evt.getModConfigurationDirectory());
MinecraftForge.EVENT_BUS.register(this);
if (!ForgeModContainer.disableVersionCheck)
{
ForgeVersion.startVersionCheck();
}
// Add and register the forge universal bucket, if it's enabled
if(FluidRegistry.isUniversalBucketEnabled())
{
universalBucket = new UniversalBucket();
universalBucket.setUnlocalizedName("forge.bucketFilled");
GameRegistry.registerItem(universalBucket, "bucketFilled");
MinecraftForge.EVENT_BUS.register(universalBucket);
}
}
示例15: getCapability
import net.minecraftforge.energy.CapabilityEnergy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY) return (T) energyStorage;
else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
if (facing == null)
return (T) itemHandler;
switch (facing) {
case UP:
return (T) new ItemStackHandler(NonNullList.withSize(1, itemHandler.getStackInSlot(0)));
case DOWN:
return (T) new ItemStackHandler(NonNullList.withSize(1, itemHandler.getStackInSlot(1)));
default:
return (T) itemHandler;
}
}
else return super.getCapability(capability, facing);
}