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 );
}
}