From e243c8e9a2e788bd76667789daf60cc15ba5265d Mon Sep 17 00:00:00 2001 From: yueh Date: Thu, 21 Dec 2017 17:29:39 +0100 Subject: [PATCH] Adds a debug generator for ForgeEnergy. (#3259) * Adds a debug generator for ForgeEnergy. This adds a simple debug block to test external energy injection via ForgeEnergy and not rely solely on creative cells. The energy has two functions. The first is acting as an infinite ForgEnergy battery, this is unused by AE2 itself as nothing pulls energy. The second one is injecting energy every tick into any adjacent block accepting ForgeEnergy. The base generation is 8 per tick, but this is increased by the power of adjacent TileEnergyGenerators. --- .../core/api/definitions/ApiBlocks.java | 13 ++ .../appeng/debug/BlockEnergyGenerator.java | 35 +++++ .../appeng/debug/TileEnergyGenerator.java | 139 ++++++++++++++++++ .../java/appeng/me/cache/EnergyGridCache.java | 14 +- .../blockstates/debug_energy_gen.json | 7 + .../models/block/debug/energy_gen.json | 6 + .../models/item/debug_energy_gen.json | 6 + .../textures/blocks/debug/energy_gen.png | Bin 0 -> 791 bytes .../textures/items/debug/energy_gen.png | Bin 0 -> 246 bytes 9 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 src/main/java/appeng/debug/BlockEnergyGenerator.java create mode 100644 src/main/java/appeng/debug/TileEnergyGenerator.java create mode 100644 src/main/resources/assets/appliedenergistics2/blockstates/debug_energy_gen.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/block/debug/energy_gen.json create mode 100644 src/main/resources/assets/appliedenergistics2/models/item/debug_energy_gen.json create mode 100644 src/main/resources/assets/appliedenergistics2/textures/blocks/debug/energy_gen.png create mode 100644 src/main/resources/assets/appliedenergistics2/textures/items/debug/energy_gen.png 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 0000000000000000000000000000000000000000..d0448874f79105da921da323ee0343d30724d972 GIT binary patch literal 791 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4kiW$hCdQ-7c($0Fct^7J29*~C-ahlfq^C6 z(btiIVPik{pF~y$1_sUokH}&M2EM}}%y>M1MG6B0gJg+oL`iUdT1k0gQ7S`0VrE{6 zUS4X6f{C7io}uNHYnxIS7?|2UT^vI^y!TFv48EKo(K=Zzck(vRdbaB^Kj*tRI>fL!EkYCyr9Q$al-t)VM*Hyd6@;AM6SG@i>@B3xB?%o~9yV8^cGpA`ZOtv#x6j;!+jXQGDC+r{5P~EpVT9N|kGdYv%3=sxK?uMNB@Xceg6B%J`@@q@I}c>5L%j z2NPbyrpRT7QzSQeRX^`!stEhslQ8Y2L1fz+qj{{07Thc}oP9dzfQ}ZU!V(u<1B+*| zDqK-5osQK{|9XgQ;hJu|P3!q@9}yXmb<5Zmd4f~EJzK>}(_xhQOb^r2dYIwUiE-%)S>Q+op+ShsGk7e{B;VFv+G&E1U z98`S%*3M_ct&$lZ1b&`9IK!N0#ga7wtRI5j_PPjc5cz&=S>l8Xafbu;tyv?)`r#B` zd$r((DR-ARG20xeb^YrqB2#$py&~&s-|y!ia|-P~6X5#SSA^vbzw^R8E{g*Kvl{}M z-n+(qUN6Y%cztq$MvC&R|NMar^Surx9B?aHrSN7R-wmz1`~Ac`j6bZrqJH++lIMm$ zLu2aZPPo6!=KbY)I~m_Q9oud3;_rm7wWogWJFx%8gim`{=!j08uUfiu%{rdds|(H_ y2)%m6)WUeyu64i7SN-E%w4m(Djs^SP=_{*oOI_N!mz#lsfx*+&&t;ucLK6Tqcv%eq literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..8f677990c415e4d3e4901619d9a2165cf0854a4b GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=qM&(QM9wM`&JX`U{QAr}5idmM!hC~z=Wmi+hMs(K|WE$2m|WUSMfyY-Gs znWl1uXx%y7XLhfJ{qsC=hbFlrdiT7`!V7+~^-VtGb8txr1LuR^jt%u`SDRFKYoCbS smdKI;Vst05{K58UO$Q literal 0 HcmV?d00001