本文整理汇总了Java中net.minecraftforge.energy.IEnergyStorage类的典型用法代码示例。如果您正苦于以下问题:Java IEnergyStorage类的具体用法?Java IEnergyStorage怎么用?Java IEnergyStorage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IEnergyStorage类属于net.minecraftforge.energy包,在下文中一共展示了IEnergyStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEvaluator
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的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: protectedUpdate
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的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();
}
}
}
示例3: onItemUse
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的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);
}
示例4: update
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的package包/类
@Override
public void update() {
super.updateBase();
if(!world.isRemote){
if(this.energy.getEnergyStored() > 0){
IEnergyStorage itemEnergy = this.getItemEnergy();
if(itemEnergy != null && itemEnergy.getEnergyStored() < itemEnergy.getMaxEnergyStored()){
this.isWorking = true;
this.energy.extractEnergy(itemEnergy.receiveEnergy(this.energy.extractEnergy(this.energy.getExtractTransfer(), true), false), false);
} else {
this.isWorking = false;
this.syncToClients();
}
} else {
this.isWorking = false;
this.syncToClients();
}
}
}
示例5: getCapability
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的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.IEnergyStorage; //导入依赖的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.IEnergyStorage; //导入依赖的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.IEnergyStorage; //导入依赖的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: drawGuiContainerBackgroundLayer
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的package包/类
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.pushMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawDefaultBackground();
Pair<Integer, Integer> invCoords = this.machineInterface.getInventoryLocation(this.tile, this.player);
if(invCoords != null){
this.texture.bindTexture(INVENTORY_LOCATION);
this.drawTexturedModalRect(invCoords.getLeft() + this.guiLeft, invCoords.getRight() + this.guiTop, 0, 0, 176, 85);
}
this.machineInterface.drawBackground(this.tile, this, this.texture, this.guiLeft, this.guiTop, mouseX, mouseY, partialTicks);
if(this.energyBar != null){
IEnergyStorage energy = this.tile.getEnergy(EnumFacing.NORTH);
if(energy != null && energy.getMaxEnergyStored() > 0){
this.energyBar.draw(energy.getEnergyStored(), energy.getMaxEnergyStored(), -1);
}
}
GlStateManager.popMatrix();
}
示例10: drawScreen
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的package包/类
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
super.renderHoveredToolTip(mouseX, mouseY);
this.machineInterface.drawScreen(this.tile, this, this.guiLeft, this.guiTop, mouseX, mouseY, partialTicks);
if(this.energyBar != null){
IEnergyStorage energy = this.tile.getEnergy(EnumFacing.NORTH);
if(energy != null && energy.getMaxEnergyStored() > 0){
if(this.tile.getCurrentEnergyUsage() > 0){
this.energyBar.mouseDrawUsage(this, mouseX, mouseY, energy.getEnergyStored(), this.tile.getCurrentEnergyUsage());
} else {
this.energyBar.mouseDrawTank(this, mouseX, mouseY, energy.getEnergyStored(), energy.getMaxEnergyStored());
}
}
}
if(this.jeiStuff != null){
IMachineInterface.JEIData data = this.jeiStuff;
if(mouseX >= data.x + this.guiLeft && mouseX <= data.x + this.guiLeft + data.width && mouseY >= data.y + this.guiTop && mouseY <= data.y + this.guiTop + data.height){
this.drawHoveringText(I18n.format("jei.tooltip.show.recipes"), mouseX, mouseY);
}
}
}
示例11: chargeItem
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的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;
}
示例12: getAdjacentStorage
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的package包/类
public static ArrayList<IEnergyStorage> getAdjacentStorage(World world, BlockPos pos) {
ArrayList<IEnergyStorage> consumers = new ArrayList<>();
if (pos.getY()<255) {
IEnergyStorage up = getStorage(world,pos.up(),EnumFacing.DOWN);
if (up.canReceive()) consumers.add(up);
}
if (pos.getY()>0) {
IEnergyStorage down = getStorage(world, pos.down(), EnumFacing.UP);
if (down.canReceive()) consumers.add(down);
}
IEnergyStorage north = getStorage(world, pos.north(), EnumFacing.SOUTH);
if (north.canReceive()) consumers.add(north);
IEnergyStorage south = getStorage(world, pos.south(), EnumFacing.NORTH);
if (south.canReceive()) consumers.add(south);
IEnergyStorage east = getStorage(world, pos.east(), EnumFacing.WEST);
if (east.canReceive()) consumers.add(east);
IEnergyStorage west = getStorage(world, pos.west(), EnumFacing.EAST);
if (west.canReceive()) consumers.add(west);
return consumers;
}
示例13: chargeItem
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的package包/类
@Override
public void chargeItem(ItemStack stack) {
if(!canChargeItem(stack))return;
IEnergyStorage cap = stack.getCapability(CapabilityEnergy.ENERGY, null);
if(cap == null)return;
int max = cap.getMaxEnergyStored();
int cur = cap.getEnergyStored();
int canUse = Math.min(energyStorage.getEnergyStored(), max - cur);
if(cur < max) {
int used = cap.receiveEnergy(canUse, true);
if(used > 0) {
if(energyStorage.extractEnergy(used, false) >=used){
cap.receiveEnergy(used, false);
}
}
}
}
示例14: forgeFactorize
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的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");
}
示例15: sendPower
import net.minecraftforge.energy.IEnergyStorage; //导入依赖的package包/类
protected void sendPower() {
if (orientation == null) {
resetPowerDirection();
return;
}
feOutput = 0;
TileEntity tile = world.getTileEntity(new BlockPos(pos.getX() + orientation.getFrontOffsetX(),
pos.getY() + orientation.getFrontOffsetY(), pos.getZ() + orientation.getFrontOffsetZ()));
if (tile != null) {
IEnergyStorage energyStorage = tile.getCapability(CapabilityEnergy.ENERGY, orientation);
if (energyStorage != null) {
int maxFE = energyStorage.receiveEnergy(Math.min(1000, feLevel), true);
feOutput = maxFE;
feLevel -= energyStorage.receiveEnergy(maxFE, false);
} else {
orientation = null;
}
} else {
orientation = null;
}
}