diff --git a/src/main/java/appeng/core/api/definitions/ApiBlocks.java b/src/main/java/appeng/core/api/definitions/ApiBlocks.java index 421edb500..953bf3d47 100644 --- a/src/main/java/appeng/core/api/definitions/ApiBlocks.java +++ b/src/main/java/appeng/core/api/definitions/ApiBlocks.java @@ -106,10 +106,12 @@ import appeng.core.features.BlockDefinition; import appeng.core.features.registries.PartModels; import appeng.debug.BlockChunkloader; import appeng.debug.BlockCubeGenerator; +import appeng.debug.BlockEnergyGenerator; import appeng.debug.BlockItemGen; import appeng.debug.BlockPhantomNode; import appeng.debug.TileChunkLoader; import appeng.debug.TileCubeGenerator; +import appeng.debug.TileEnergyGenerator; import appeng.debug.TileItemGen; import appeng.debug.TilePhantomNode; import appeng.decorative.slab.BlockSlabCommon; @@ -236,6 +238,7 @@ public final class ApiBlocks implements IBlocks private final IBlockDefinition chunkLoader; private final IBlockDefinition phantomNode; private final IBlockDefinition cubeGenerator; + private final IBlockDefinition energyGenerator; public ApiBlocks( FeatureFactory registry, PartModels partModels ) { @@ -526,6 +529,11 @@ public final class ApiBlocks implements IBlocks .tileEntity( new TileEntityDefinition( TileCubeGenerator.class ) ) .useCustomItemModel() .build(); + this.energyGenerator = registry.block( "debug_energy_gen", BlockEnergyGenerator::new ) + .features( AEFeature.UNSUPPORTED_DEVELOPER_TOOLS, AEFeature.CREATIVE ) + .tileEntity( new TileEntityDefinition( TileEnergyGenerator.class ) ) + .useCustomItemModel() + .build(); } private static IBlockDefinition makeSlab( String slabId, String doubleSlabId, FeatureFactory registry, IBlockDefinition blockDef ) @@ -1014,4 +1022,9 @@ public final class ApiBlocks implements IBlocks { return this.cubeGenerator; } + + public IBlockDefinition energyGenerator() + { + return energyGenerator; + } } diff --git a/src/main/java/appeng/debug/BlockEnergyGenerator.java b/src/main/java/appeng/debug/BlockEnergyGenerator.java new file mode 100644 index 000000000..6aca39706 --- /dev/null +++ b/src/main/java/appeng/debug/BlockEnergyGenerator.java @@ -0,0 +1,35 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.debug; + + +import net.minecraft.block.material.Material; + +import appeng.block.AEBaseTileBlock; + + +public class BlockEnergyGenerator extends AEBaseTileBlock +{ + + public BlockEnergyGenerator() + { + super( Material.IRON ); + } + +} diff --git a/src/main/java/appeng/debug/TileEnergyGenerator.java b/src/main/java/appeng/debug/TileEnergyGenerator.java new file mode 100644 index 000000000..ce78a78fc --- /dev/null +++ b/src/main/java/appeng/debug/TileEnergyGenerator.java @@ -0,0 +1,139 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.debug; + + +import java.util.EnumSet; + +import javax.annotation.Nullable; + +import com.google.common.math.IntMath; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; + +import appeng.tile.AEBaseTile; + + +public class TileEnergyGenerator extends AEBaseTile implements ITickable, IEnergyStorage +{ + /** + * The base energy injected each tick. + * Adjacent TileEnergyGenerators will increase it to pow(base, #generators). + */ + private static final int BASE_ENERGY = 8; + + @Override + public void update() + { + int tier = 1; + final EnumSet validEnergyReceivers = EnumSet.noneOf( EnumFacing.class ); + + for( EnumFacing facing : EnumFacing.values() ) + { + final TileEntity te = this.getWorld().getTileEntity( this.getPos().offset( facing ) ); + + if( te instanceof TileEnergyGenerator ) + { + tier++; + } + + if( te != null && te.hasCapability( CapabilityEnergy.ENERGY, facing.getOpposite() ) ) + { + validEnergyReceivers.add( facing ); + } + + } + + final int energyToInsert = IntMath.pow( BASE_ENERGY, tier ); + + for( EnumFacing facing : validEnergyReceivers ) + { + final TileEntity te = this.getWorld().getTileEntity( this.getPos().offset( facing ) ); + final IEnergyStorage cap = te.getCapability( CapabilityEnergy.ENERGY, facing.getOpposite() ); + + if( cap.canReceive() ) + { + + cap.receiveEnergy( energyToInsert, false ); + } + } + } + + @Override + public boolean hasCapability( Capability capability, @Nullable EnumFacing facing ) + { + if( capability == CapabilityEnergy.ENERGY ) + { + return true; + } + return super.hasCapability( capability, facing ); + } + + @Override + @Nullable + public T getCapability( Capability capability, @Nullable EnumFacing facing ) + { + if( capability == CapabilityEnergy.ENERGY ) + { + return (T) this; + } + return super.getCapability( capability, facing ); + } + + @Override + public int receiveEnergy( int maxReceive, boolean simulate ) + { + return 0; + } + + @Override + public int extractEnergy( int maxExtract, boolean simulate ) + { + return maxExtract; + } + + @Override + public int getEnergyStored() + { + return Integer.MAX_VALUE; + } + + @Override + public int getMaxEnergyStored() + { + return Integer.MAX_VALUE; + } + + @Override + public boolean canExtract() + { + return true; + } + + @Override + public boolean canReceive() + { + return false; + } +} diff --git a/src/main/java/appeng/me/cache/EnergyGridCache.java b/src/main/java/appeng/me/cache/EnergyGridCache.java index 2b4656623..7c5e3b68f 100644 --- a/src/main/java/appeng/me/cache/EnergyGridCache.java +++ b/src/main/java/appeng/me/cache/EnergyGridCache.java @@ -336,10 +336,7 @@ public class EnergyGridCache implements IEnergyGrid @Override public double injectProviderPower( double amt, final Actionable mode ) { - if( mode == Actionable.MODULATE ) - { - this.tickInjectionPerTick += amt; - } + final double originalAmount = amt; final Iterator it = this.requesters.iterator(); @@ -354,7 +351,14 @@ public class EnergyGridCache implements IEnergyGrid } } - return Math.max( 0.0, amt ); + final double overflow = Math.max( 0.0, amt ); + + if( mode == Actionable.MODULATE ) + { + this.tickInjectionPerTick += originalAmount - overflow; + } + + return overflow; } @Override diff --git a/src/main/resources/assets/appliedenergistics2/blockstates/debug_energy_gen.json b/src/main/resources/assets/appliedenergistics2/blockstates/debug_energy_gen.json new file mode 100644 index 000000000..1d386d2a6 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/blockstates/debug_energy_gen.json @@ -0,0 +1,7 @@ +{ + "variants": { + "normal": { + "model": "appliedenergistics2:debug/energy_gen" + } + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/block/debug/energy_gen.json b/src/main/resources/assets/appliedenergistics2/models/block/debug/energy_gen.json new file mode 100644 index 000000000..17eab73b1 --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/block/debug/energy_gen.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "appliedenergistics2:blocks/debug/energy_gen" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/models/item/debug_energy_gen.json b/src/main/resources/assets/appliedenergistics2/models/item/debug_energy_gen.json new file mode 100644 index 000000000..325c66eaa --- /dev/null +++ b/src/main/resources/assets/appliedenergistics2/models/item/debug_energy_gen.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "appliedenergistics2:items/debug/energy_gen" + } +} diff --git a/src/main/resources/assets/appliedenergistics2/textures/blocks/debug/energy_gen.png b/src/main/resources/assets/appliedenergistics2/textures/blocks/debug/energy_gen.png new file mode 100644 index 000000000..d0448874f Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/blocks/debug/energy_gen.png differ diff --git a/src/main/resources/assets/appliedenergistics2/textures/items/debug/energy_gen.png b/src/main/resources/assets/appliedenergistics2/textures/items/debug/energy_gen.png new file mode 100644 index 000000000..8f677990c Binary files /dev/null and b/src/main/resources/assets/appliedenergistics2/textures/items/debug/energy_gen.png differ