net.minecraftforge.energy.CapabilityEnergy Java Examples
The following examples show how to use
net.minecraftforge.energy.CapabilityEnergy.
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: BatteryTileEntity.java From EmergingTechnology with MIT License | 6 votes |
private void spreadEnergy() { for (EnumFacing side : EnumFacing.VALUES) { if (side == getFacing()) { continue; } TileEntity tileEntity = world.getTileEntity(pos.offset(side)); if (tileEntity != null) { IEnergyStorage otherStorage = tileEntity.getCapability(CapabilityEnergy.ENERGY, side.getOpposite()); if (otherStorage != null) { if (otherStorage.canReceive()) { if (this.getEnergy() > 0) { int energySpread = otherStorage.receiveEnergy(this.getEnergy(), false); this.energyHandler.extractEnergy(energySpread, false); } } } } } }
Example #2
Source File: TileFastFurnace.java From YouTubeModdingTutorial with MIT License | 6 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (facing == null) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(combinedHandler); } else if (facing == EnumFacing.UP) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inputHandler); } else { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(outputHandler); } } if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(energyStorage); } return super.getCapability(capability, facing); }
Example #3
Source File: RenderBlockTileEntity.java From MiningGadgets with MIT License | 6 votes |
private void freeze(ItemStack stack) { for (Direction side : Direction.values()) { BlockPos sidePos = pos.offset(side); IFluidState state = world.getFluidState(sidePos); int freezeCost = Config.UPGRADECOST_FREEZE.get() * -1; if (state.getFluid().isEquivalentTo(Fluids.LAVA) && state.getFluid().isSource(state)) { world.setBlockState(sidePos, Blocks.OBSIDIAN.getDefaultState()); stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(freezeCost, false)); } else if (state.getFluid().isEquivalentTo(Fluids.WATER) && state.getFluid().isSource(state)) { world.setBlockState(sidePos, Blocks.PACKED_ICE.getDefaultState()); stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(freezeCost, false)); } else if ((state.getFluid().isEquivalentTo(Fluids.WATER) || state.getFluid().isEquivalentTo(Fluids.LAVA)) && !state.getFluid().isSource(state)) { world.setBlockState(sidePos, Blocks.COBBLESTONE.getDefaultState()); stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(freezeCost, false)); } } }
Example #4
Source File: TileGenerator.java From YouTubeModdingTutorial with MIT License | 6 votes |
private void sendEnergy() { if (energyStorage.getEnergyStored() > 0) { for (EnumFacing facing : EnumFacing.VALUES) { TileEntity tileEntity = world.getTileEntity(pos.offset(facing)); if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite())) { IEnergyStorage handler = tileEntity.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()); if (handler != null && handler.canReceive()) { int accepted = handler.receiveEnergy(energyStorage.getEnergyStored(), false); energyStorage.consumePower(accepted); if (energyStorage.getEnergyStored() <= 0) { break; } } } } markDirty(); } }
Example #5
Source File: ShredderTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #6
Source File: HydroponicTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return true; if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #7
Source File: PiezoelectricTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #8
Source File: BatteryTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) { if (facing == getFacing()) { return CapabilityEnergy.ENERGY.cast(this.consumerStorageHandler); } else { return CapabilityEnergy.ENERGY.cast(this.generatorStorageHandler); } } return super.getCapability(capability, facing); }
Example #9
Source File: BatteryTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #10
Source File: ShredderTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.automationItemHandler); if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.consumerEnergyHandler); return super.getCapability(capability, facing); }
Example #11
Source File: ModificationTableCommands.java From MiningGadgets with MIT License | 5 votes |
public static void extractButton(ModificationTableContainer container, ServerPlayerEntity player, String upgradeName) { Slot laserSlot = container.inventorySlots.get(0); ItemStack laser = laserSlot.getStack(); if (!(laser.getItem() instanceof MiningGadget)) return; if (!UpgradeTools.containsUpgrades(laser)) return; UpgradeTools.getUpgrades(laser).forEach(upgrade -> { if( !upgrade.getName().equals(upgradeName) ) return; UpgradeTools.removeUpgrade(laser, upgrade); boolean success = player.inventory.addItemStackToInventory(new ItemStack(upgrade.getCard(), 1)); if (!success) { player.dropItem(new ItemStack(upgrade.getCard(), 1), true); } if (upgrade == Upgrade.THREE_BY_THREE) MiningProperties.setRange(laser, 1); // Set both max and default range to MIN_RANGE. if (upgrade.getBaseName().equals(Upgrade.RANGE_1.getBaseName())) { MiningProperties.setBeamRange(laser, MiningProperties.MIN_RANGE); MiningProperties.setBeamMaxRange(laser, UpgradeTools.getMaxBeamRange(0)); } if (upgrade.getBaseName().equals(Upgrade.BATTERY_1.getBaseName())) laser.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> ((EnergisedItem) e).updatedMaxEnergy(UpgradeBatteryLevels.BATTERY.getPower())); }); }
Example #12
Source File: WindTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.generatorEnergyHandler); if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) return CapabilityAnimation.ANIMATION_CAPABILITY.cast(getAnimator()); return super.getCapability(capability, facing); }
Example #13
Source File: AlgaeBioreactorTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(this.automationFluidHandler); if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.automationItemHandler); if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.consumerEnergyHandler); return super.getCapability(capability, facing); }
Example #14
Source File: AlgaeBioreactorTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return true; if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #15
Source File: HarvesterTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; if (capability == CapabilityEnergy.ENERGY) return true; if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) return true; return super.hasCapability(capability, facing); }
Example #16
Source File: HarvesterTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.automationItemHandler); if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.consumerEnergyHandler); if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) return CapabilityAnimation.ANIMATION_CAPABILITY.cast(getAnimator()); return super.getCapability(capability, facing); }
Example #17
Source File: SolarTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #18
Source File: HydroponicTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(this.fluidHandler); if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.itemHandler); if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.consumerEnergyHandler); return super.getCapability(capability, facing); }
Example #19
Source File: WindTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) return true; if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) return true; return super.hasCapability(capability, facing); }
Example #20
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
@Override public double getDurabilityForDisplay(ItemStack stack) { IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); if (energy == null) return 0; return 1D - (energy.getEnergyStored() / (double) energy.getMaxEnergyStored()); }
Example #21
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
@Override public int getRGBDurabilityForDisplay(ItemStack stack) { IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); if (energy == null) return super.getRGBDurabilityForDisplay(stack); return MathHelper.hsvToRGB(Math.max(0.0F, (float) energy.getEnergyStored() / (float) energy.getMaxEnergyStored()) / 3.0F, 1.0F, 1.0F); }
Example #22
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
@Override public void addInformation(ItemStack stack, @Nullable World world, List<ITextComponent> tooltip, ITooltipFlag flag) { super.addInformation(stack, world, tooltip, flag); List<Upgrade> upgrades = UpgradeTools.getUpgrades(stack); Minecraft mc = Minecraft.getInstance(); if (!InputMappings.isKeyDown(mc.getMainWindow().getHandle(), mc.gameSettings.keyBindSneak.getKey().getKeyCode())) { tooltip.add(new TranslationTextComponent("mininggadgets.tooltip.item.show_upgrades", mc.gameSettings.keyBindSneak.getLocalizedName().toLowerCase()) .applyTextStyle(TextFormatting.GRAY)); } else { tooltip.add(new TranslationTextComponent("mininggadgets.tooltip.item.break_cost", getEnergyCost(stack)).applyTextStyle(TextFormatting.RED)); if (!(upgrades.isEmpty())) { tooltip.add(new TranslationTextComponent("mininggadgets.tooltip.item.upgrades").applyTextStyle(TextFormatting.AQUA)); for (Upgrade upgrade : upgrades) { tooltip.add(new StringTextComponent(" - " + I18n.format(upgrade.getLocal()) ).applyTextStyle(TextFormatting.GRAY)); } } } stack.getCapability(CapabilityEnergy.ENERGY, null) .ifPresent(energy -> tooltip.add( new TranslationTextComponent("mininggadgets.gadget.energy", MagicHelpers.tidyValue(energy.getEnergyStored()), MagicHelpers.tidyValue(energy.getMaxEnergyStored())).applyTextStyles(TextFormatting.GREEN))); }
Example #23
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
public static boolean canMine(ItemStack tool) { IEnergyStorage energy = tool.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); int cost = getEnergyCost(tool); if (MiningProperties.getRange(tool) == 3) cost = cost * 9; return energy.getEnergyStored() > cost; }
Example #24
Source File: TileGenerator.java From YouTubeModdingTutorial with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) { return true; } if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) { return true; } return super.hasCapability(capability, facing); }
Example #25
Source File: TileGenerator.java From YouTubeModdingTutorial with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(energyStorage); } if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) { return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm); } return super.getCapability(capability, facing); }
Example #26
Source File: TileFastFurnace.java From YouTubeModdingTutorial with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } if (capability == CapabilityEnergy.ENERGY) { return true; } return super.hasCapability(capability, facing); }
Example #27
Source File: TileEnergyPipe.java From AdvancedRocketry with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability == CapabilityEnergy.ENERGY || TeslaHandler.hasTeslaCapability(this, capability)) return true; return false; }
Example #28
Source File: TileEnergyPipe.java From AdvancedRocketry with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityEnergy.ENERGY ) return (T)(new ForgePowerCapability(this)); else if(TeslaHandler.hasTeslaCapability(this, capability)) return (T)(TeslaHandler.getHandler(this)); return super.getCapability(capability, facing); }
Example #29
Source File: UpgradeCharging.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
private static boolean chargeItem(ItemStack stack, IBetterChest chest) { IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null); if (storage != null) { int maxCharge = chest.getEnergyStorage().getEnergyStored(); maxCharge = storage.receiveEnergy(maxCharge, false); if (maxCharge > 0) { chest.getEnergyStorage().extractEnergy(maxCharge, false); return true; } } return false; }
Example #30
Source File: BasicBagInventory.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityEnergy.ENERGY) { return (T) external; } return null; }