Added Registry for customized charger rates. (#3139)

* Added Registry for customized charger rates.
* Added rates for all chargable items/block.
* Charger and Inscriber now store 1.6k AE each instead of 1.5k
* A crank applies 160 AE instead of 150
* Charged certus now requires 1.6k instead of 1.5k
This commit is contained in:
yueh
2017-10-08 17:33:06 +02:00
committed by GitHub
parent 6032c0328e
commit 95b27f490c
7 changed files with 257 additions and 50 deletions
+12 -4
View File
@@ -460,10 +460,18 @@ final class Registration
// Inscriber
Upgrades.SPEED.registerItem( blocks.inscriber(), 3 );
items.wirelessTerminal().maybeItem().ifPresent( terminal ->
{
registries.wireless().registerWirelessHandler( (IWirelessTermHandler) terminal );
} );
// Wireless Terminal Handler
items.wirelessTerminal().maybeItem().ifPresent( terminal -> registries.wireless().registerWirelessHandler( (IWirelessTermHandler) terminal ) );
// Charge Rates
items.chargedStaff().maybeItem().ifPresent( chargedStaff -> registries.charger().addChargeRate( chargedStaff, 320d ) );
items.portableCell().maybeItem().ifPresent( chargedStaff -> registries.charger().addChargeRate( chargedStaff, 800d ) );
items.colorApplicator().maybeItem().ifPresent( colorApplicator -> registries.charger().addChargeRate( colorApplicator, 800d ) );
items.wirelessTerminal().maybeItem().ifPresent( terminal -> registries.charger().addChargeRate( terminal, 8000d ) );
items.entropyManipulator().maybeItem().ifPresent( entropyManipulator -> registries.charger().addChargeRate( entropyManipulator, 8000d ) );
items.massCannon().maybeItem().ifPresent( massCannon -> registries.charger().addChargeRate( massCannon, 8000d ) );
blocks.energyCell().maybeItem().ifPresent( cell -> registries.charger().addChargeRate( cell, 8000d ) );
blocks.energyCellDense().maybeItem().ifPresent( cell -> registries.charger().addChargeRate( cell, 16000d ) );
// add villager trading to black smiths for a few basic materials
if( AEConfig.instance().isFeatureEnabled( AEFeature.VILLAGER_TRADING ) )
@@ -19,6 +19,7 @@
package appeng.core.features.registries;
import appeng.api.features.IChargerRegistry;
import appeng.api.features.IGrinderRegistry;
import appeng.api.features.IInscriberRegistry;
import appeng.api.features.ILocatableRegistry;
@@ -35,6 +36,7 @@ import appeng.api.networking.IGridCacheRegistry;
import appeng.api.parts.IPartModels;
import appeng.api.storage.ICellRegistry;
import appeng.core.features.registries.cell.CellRegistry;
import appeng.core.features.registries.charger.ChargerRegistry;
import appeng.core.features.registries.grinder.GrinderRecipeManager;
import appeng.core.features.registries.inscriber.InscriberRegistry;
@@ -44,13 +46,15 @@ import appeng.core.features.registries.inscriber.InscriberRegistry;
*
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @author yueh
* @version rv5
* @since rv0
*/
public class RegistryContainer implements IRegistryContainer
{
private final IGrinderRegistry grinder = new GrinderRecipeManager();
private final IInscriberRegistry inscriber = new InscriberRegistry();
private final IChargerRegistry charger = new ChargerRegistry();
private final ICellRegistry cell = new CellRegistry();
private final ILocatableRegistry locatable = new LocatableRegistry();
private final ISpecialComparisonRegistry comparison = new SpecialComparisonRegistry();
@@ -105,6 +109,12 @@ public class RegistryContainer implements IRegistryContainer
return this.inscriber;
}
@Override
public IChargerRegistry charger()
{
return this.charger;
}
@Override
public ILocatableRegistry locatable()
{
@@ -0,0 +1,75 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2017, 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 <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.features.registries.charger;
import java.util.IdentityHashMap;
import java.util.Map;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
import net.minecraft.item.Item;
import appeng.api.features.IChargerRegistry;
public class ChargerRegistry implements IChargerRegistry
{
private static final double DEFAULT_CHARGE_RATE = 160d;
private static final double CAPPED_CHARGE_RATE = 16000d;
private final Map<Item, Double> chargeRates;
public ChargerRegistry()
{
this.chargeRates = new IdentityHashMap<>();
}
@Override
@Nonnegative
public double getChargeRate( @Nonnull Item item )
{
Preconditions.checkNotNull( item );
return this.chargeRates.getOrDefault( item, DEFAULT_CHARGE_RATE );
}
@Override
public void addChargeRate( @Nonnull Item item, @Nonnegative double value )
{
Preconditions.checkNotNull( item );
Preconditions.checkArgument( value > 0d );
final double cappedValue = Math.min( value, CAPPED_CHARGE_RATE );
this.chargeRates.put( item, cappedValue );
}
@Override
public void removeChargeRate( @Nonnull Item item )
{
Preconditions.checkNotNull( item );
this.chargeRates.remove( item );
}
}
+67 -43
View File
@@ -59,17 +59,17 @@ import appeng.util.item.AEItemStack;
public class TileCharger extends AENetworkPowerTile implements ICrankable, IGridTickable
{
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1, 1, new ChargerInvFilter() );
private int tickTickTimer = 0;
private static final int POWER_MAXIMUM_AMOUNT = 1600;
private static final int POWER_THRESHOLD = POWER_MAXIMUM_AMOUNT - 1;
private static final int POWER_PER_CRANK_TURN = 160;
private int lastUpdate = 0;
private boolean requiresUpdate = false;
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1, 1, new ChargerInvFilter() );
public TileCharger()
{
this.getProxy().setValidSides( EnumSet.noneOf( EnumFacing.class ) );
this.getProxy().setFlags();
this.setInternalMaxPower( 1500 );
this.setInternalMaxPower( POWER_MAXIMUM_AMOUNT );
this.getProxy().setIdlePowerUsage( 0 );
}
@@ -130,16 +130,16 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
@Override
public void applyTurn()
{
this.injectExternalPower( PowerUnits.AE, 150, Actionable.MODULATE );
this.injectExternalPower( PowerUnits.AE, POWER_PER_CRANK_TURN, Actionable.MODULATE );
final ItemStack myItem = this.inv.getStackInSlot( 0 );
if( this.getInternalCurrentPower() > 1499 )
if( this.getInternalCurrentPower() > POWER_THRESHOLD )
{
final IMaterials materials = AEApi.instance().definitions().materials();
if( materials.certusQuartzCrystal().isSameAs( myItem ) )
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
}
@@ -215,55 +215,79 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
private boolean doWork()
{
final ItemStack myItem = this.inv.getStackInSlot( 0 );
boolean changed = false;
if( !myItem.isEmpty() )
{
final IMaterials materials = AEApi.instance().definitions().materials();
if( Platform.isChargeable( myItem ) )
{
final IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
if( ps.getAEMaxPower( myItem ) > ps.getAECurrentPower( myItem ) )
{
final double chargeRate = AEApi.instance().registries().charger().getChargeRate( myItem.getItem() );
double extractedAmount = this.extractAEPower( chargeRate, Actionable.MODULATE, PowerMultiplier.CONFIG );
final double missingChargeRate = chargeRate - extractedAmount;
final double missingAEPower = ps.getAEMaxPower( myItem ) - ps.getAECurrentPower( myItem );
final double toExtract = Math.min( missingChargeRate, missingAEPower );
try
{
extractedAmount += this.getProxy().getEnergy().extractAEPower( toExtract, Actionable.MODULATE, PowerMultiplier.ONE );
}
catch( GridAccessException e1 )
{
// Ignore.
}
if( extractedAmount > 0 )
{
final double adjustment = ps.injectAEPower( myItem, extractedAmount, Actionable.MODULATE );
this.setInternalCurrentPower( this.getInternalCurrentPower() + adjustment );
changed = true;
}
}
}
else if( this.getInternalCurrentPower() > POWER_THRESHOLD && materials.certusQuartzCrystal().isSameAs( myItem ) )
{
if( Platform.getRandomFloat() > 0.8f ) // simulate wait
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
changed = true;
}
}
}
// charge from the network!
if( this.getInternalCurrentPower() < 1499 )
if( this.getInternalCurrentPower() < POWER_THRESHOLD )
{
try
{
this.injectExternalPower( PowerUnits.AE, this.getProxy().getEnergy().extractAEPower( Math.min( 500.0, 1500.0 - this.getInternalCurrentPower() ),
Actionable.MODULATE, PowerMultiplier.ONE ), Actionable.MODULATE );
final double toExtract = Math.min( 800.0, this.getInternalMaxPower() - this.getInternalCurrentPower() );
final double extracted = this.getProxy().getEnergy().extractAEPower( toExtract, Actionable.MODULATE, PowerMultiplier.ONE );
this.injectExternalPower( PowerUnits.AE, extracted, Actionable.MODULATE );
}
catch( final GridAccessException e )
{
// continue!
}
return true;
changed = true;
}
if( myItem.isEmpty() )
if( changed )
{
return false;
}
final IMaterials materials = AEApi.instance().definitions().materials();
if( this.getInternalCurrentPower() > 149 && Platform.isChargeable( myItem ) )
{
final IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
if( ps.getAEMaxPower( myItem ) > ps.getAECurrentPower( myItem ) )
{
final double oldPower = this.getInternalCurrentPower();
final double adjustment = ps.injectAEPower( myItem, this.extractAEPower( 150.0, Actionable.MODULATE, PowerMultiplier.CONFIG ),
Actionable.MODULATE );
this.setInternalCurrentPower( this.getInternalCurrentPower() + adjustment );
if( oldPower > this.getInternalCurrentPower() )
{
this.markForUpdate();
}
}
}
else if( this.getInternalCurrentPower() > 1499 && materials.certusQuartzCrystal().isSameAs( myItem ) )
{
if( Platform.getRandomFloat() > 0.8f ) // simulate wait
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
}
this.markForUpdate();
}
return true;
@@ -103,7 +103,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
public TileInscriber()
{
this.getProxy().setValidSides( EnumSet.noneOf( EnumFacing.class ) );
this.setInternalMaxPower( 1500 );
this.setInternalMaxPower( 1600 );
this.getProxy().setIdlePowerUsage( 0 );
this.settings = new ConfigManager( this );