Flattening part 1

This commit is contained in:
Sebastian Hartte
2020-06-05 22:47:29 +02:00
parent c411a800f6
commit bb453b0d35
43 changed files with 492 additions and 594 deletions
@@ -72,16 +72,14 @@ import appeng.util.inv.AdaptorItemHandler;
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
{
public static ItemMaterial instance;
private static final int KILO_SCALAR = 1024;
private final Map<Integer, MaterialType> dmgToMaterial = new HashMap<>();
private final MaterialType materialType;
public ItemMaterial(Properties properties) {
public ItemMaterial(Properties properties, MaterialType materialType) {
super(properties);
// FIXME this.setHasSubtypes( true );
instance = this;
this.materialType = materialType;
}
@OnlyIn( Dist.CLIENT )
@@ -90,13 +88,7 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
{
super.addInformation( stack, world, lines, advancedTooltips );
final MaterialType mt = this.getTypeByStack( stack );
if( mt == null )
{
return;
}
if( mt == MaterialType.NAME_PRESS )
if( materialType == MaterialType.NAME_PRESS )
{
final CompoundNBT c = stack.getOrCreateTag();
lines.add( new StringTextComponent( c.getString( "InscribeName" ) ) );
@@ -141,16 +133,10 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
}
}
public MaterialType getTypeByStack( final ItemStack is )
{
MaterialType type = this.dmgToMaterial.get( is.getDamage() );
return ( type != null ) ? type : MaterialType.INVALID_TYPE;
}
@Override
public Upgrades getType( final ItemStack itemstack )
{
switch( this.getTypeByStack( itemstack ) )
switch( materialType )
{
case CARD_CAPACITY:
return Upgrades.CAPACITY;
@@ -169,59 +155,6 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
}
}
public IStackSrc createMaterial( final MaterialType mat )
{
Preconditions.checkState( !mat.isRegistered(), "Cannot create the same material twice." );
boolean enabled = true;
for( final AEFeature f : mat.getFeature() )
{
enabled = enabled && AEConfig.instance().isFeatureEnabled( f );
}
mat.setStackSrc( new MaterialStackSrc( mat, enabled ) );
if( enabled )
{
mat.setItemInstance( this );
mat.markReady();
final int newMaterialNum = mat.getDamageValue();
if( this.dmgToMaterial.get( newMaterialNum ) == null )
{
this.dmgToMaterial.put( newMaterialNum, mat );
}
else
{
throw new IllegalStateException( "Meta Overlap detected." );
}
}
return mat.getStackSrc();
}
@Override
public String getTranslationKey( final ItemStack is )
{
return "item.appliedenergistics2.material." + this.nameOf( is ).toLowerCase();
}
@Override
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
final List<MaterialType> types = Arrays.asList( MaterialType.values() );
Collections.sort( types, ( o1, o2 ) -> o1.name().compareTo( o2.name() ) );
for( final MaterialType mat : types )
{
if( mat.getDamageValue() >= 0 && mat.isRegistered() && mat.getItemInstance() == this )
{
items.add( new ItemStack( this, 1/* FIXME, mat.getDamageValue() */ ) );
}
}
}
@Override
public ActionResultType onItemUseFirst( ItemStack stack, ItemUseContext context )
{
@@ -270,13 +203,13 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
@Override
public boolean hasCustomEntity( final ItemStack is )
{
return this.getTypeByStack( is ).hasCustomEntity();
return materialType.hasCustomEntity();
}
@Override
public Entity createEntity( final World w, final Entity location, final ItemStack itemstack )
{
final Class<? extends Entity> droppedEntity = this.getTypeByStack( itemstack ).getCustomEntityClass();
final Class<? extends Entity> droppedEntity = materialType.getCustomEntityClass();
final Entity eqi;
try
@@ -298,26 +231,10 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
return eqi;
}
private String nameOf( final ItemStack is )
{
if( is.isEmpty() )
{
return "null";
}
final MaterialType mt = this.getTypeByStack( is );
if( mt == null )
{
return "null";
}
return mt.name();
}
@Override
public int getBytes( final ItemStack is )
{
switch( this.getTypeByStack( is ) )
switch( materialType )
{
case CELL1K_PART:
return KILO_SCALAR;
@@ -335,7 +252,7 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
@Override
public boolean isStorageComponent( final ItemStack is )
{
switch( this.getTypeByStack( is ) )
switch( materialType )
{
case CELL1K_PART:
case CELL4K_PART:
@@ -37,137 +37,132 @@ import appeng.entity.EntitySingularity;
public enum MaterialType
{
INVALID_TYPE( -1, "material_invalid_type" ),
CERTUS_QUARTZ_CRYSTAL("material_certus_quartz_crystal", EnumSet.of( AEFeature.CERTUS ), "crystalCertusQuartz" ),
CERTUS_QUARTZ_CRYSTAL_CHARGED("material_certus_quartz_crystal_charged", EnumSet.of( AEFeature.CERTUS ), EntityChargedQuartz.class ),
CERTUS_QUARTZ_CRYSTAL( 0, "material_certus_quartz_crystal", EnumSet.of( AEFeature.CERTUS ), "crystalCertusQuartz" ),
CERTUS_QUARTZ_CRYSTAL_CHARGED( 1, "material_certus_quartz_crystal_charged", EnumSet.of( AEFeature.CERTUS ), EntityChargedQuartz.class ),
CERTUS_QUARTZ_DUST("material_certus_quartz_dust", EnumSet.of( AEFeature.DUSTS, AEFeature.CERTUS ), "dustCertusQuartz" ),
NETHER_QUARTZ_DUST("material_nether_quartz_dust", EnumSet.of( AEFeature.DUSTS ), "dustNetherQuartz,dustQuartz" ),
FLOUR("material_flour", EnumSet.of( AEFeature.FLOUR ), "dustWheat" ),
GOLD_DUST("material_gold_dust", EnumSet.of( AEFeature.DUSTS ), "dustGold" ),
IRON_DUST("material_iron_dust", EnumSet.of( AEFeature.DUSTS ), "dustIron" ),
CERTUS_QUARTZ_DUST( 2, "material_certus_quartz_dust", EnumSet.of( AEFeature.DUSTS, AEFeature.CERTUS ), "dustCertusQuartz" ),
NETHER_QUARTZ_DUST( 3, "material_nether_quartz_dust", EnumSet.of( AEFeature.DUSTS ), "dustNetherQuartz,dustQuartz" ),
FLOUR( 4, "material_flour", EnumSet.of( AEFeature.FLOUR ), "dustWheat" ),
GOLD_DUST( 51, "material_gold_dust", EnumSet.of( AEFeature.DUSTS ), "dustGold" ),
IRON_DUST( 49, "material_iron_dust", EnumSet.of( AEFeature.DUSTS ), "dustIron" ),
SILICON("material_silicon", EnumSet.of( AEFeature.SILICON ), "itemSilicon" ),
MATTER_BALL("material_matter_ball", EnumSet.of( AEFeature.MATTER_BALL ) ),
SILICON( 5, "material_silicon", EnumSet.of( AEFeature.SILICON ), "itemSilicon" ),
MATTER_BALL( 6, "material_matter_ball", EnumSet.of( AEFeature.MATTER_BALL ) ),
FLUIX_CRYSTAL("material_fluix_crystal", EnumSet.of( AEFeature.FLUIX ), "crystalFluix" ),
FLUIX_DUST("material_fluix_dust", EnumSet.of( AEFeature.FLUIX, AEFeature.DUSTS ), "dustFluix" ),
FLUIX_PEARL("material_fluix_pearl", EnumSet.of( AEFeature.FLUIX ), "pearlFluix" ),
FLUIX_CRYSTAL( 7, "material_fluix_crystal", EnumSet.of( AEFeature.FLUIX ), "crystalFluix" ),
FLUIX_DUST( 8, "material_fluix_dust", EnumSet.of( AEFeature.FLUIX, AEFeature.DUSTS ), "dustFluix" ),
FLUIX_PEARL( 9, "material_fluix_pearl", EnumSet.of( AEFeature.FLUIX ), "pearlFluix" ),
PURIFIED_CERTUS_QUARTZ_CRYSTAL( 10, "material_purified_certus_quartz_crystal", EnumSet.of( AEFeature.CERTUS,
PURIFIED_CERTUS_QUARTZ_CRYSTAL("material_purified_certus_quartz_crystal", EnumSet.of( AEFeature.CERTUS,
AEFeature.PURE_CRYSTALS ), "crystalPureCertusQuartz" ),
PURIFIED_NETHER_QUARTZ_CRYSTAL( 11, "material_purified_nether_quartz_crystal", EnumSet.of( AEFeature.PURE_CRYSTALS ), "crystalPureNetherQuartz" ),
PURIFIED_FLUIX_CRYSTAL( 12, "material_purified_fluix_crystal", EnumSet.of( AEFeature.FLUIX, AEFeature.PURE_CRYSTALS ), "crystalPureFluix" ),
PURIFIED_NETHER_QUARTZ_CRYSTAL("material_purified_nether_quartz_crystal", EnumSet.of( AEFeature.PURE_CRYSTALS ), "crystalPureNetherQuartz" ),
PURIFIED_FLUIX_CRYSTAL("material_purified_fluix_crystal", EnumSet.of( AEFeature.FLUIX, AEFeature.PURE_CRYSTALS ), "crystalPureFluix" ),
CALCULATION_PROCESSOR_PRESS( 13, "material_calculation_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
ENGINEERING_PROCESSOR_PRESS( 14, "material_engineering_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
LOGIC_PROCESSOR_PRESS( 15, "material_logic_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
CALCULATION_PROCESSOR_PRESS("material_calculation_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
ENGINEERING_PROCESSOR_PRESS("material_engineering_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
LOGIC_PROCESSOR_PRESS("material_logic_processor_press", EnumSet.of( AEFeature.PRESSES ) ),
CALCULATION_PROCESSOR_PRINT( 16, "material_calculation_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
ENGINEERING_PROCESSOR_PRINT( 17, "material_engineering_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
LOGIC_PROCESSOR_PRINT( 18, "material_logic_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
CALCULATION_PROCESSOR_PRINT("material_calculation_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
ENGINEERING_PROCESSOR_PRINT("material_engineering_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
LOGIC_PROCESSOR_PRINT("material_logic_processor_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
SILICON_PRESS( 19, "material_silicon_press", EnumSet.of( AEFeature.PRESSES ) ),
SILICON_PRINT( 20, "material_silicon_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
SILICON_PRESS("material_silicon_press", EnumSet.of( AEFeature.PRESSES ) ),
SILICON_PRINT("material_silicon_print", EnumSet.of( AEFeature.PRINTED_CIRCUITS ) ),
NAME_PRESS( 21, "material_name_press", EnumSet.of( AEFeature.PRESSES ) ),
NAME_PRESS("material_name_press", EnumSet.of( AEFeature.PRESSES ) ),
LOGIC_PROCESSOR( 22, "material_logic_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
CALCULATION_PROCESSOR( 23, "material_calculation_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
ENGINEERING_PROCESSOR( 24, "material_engineering_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
LOGIC_PROCESSOR("material_logic_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
CALCULATION_PROCESSOR("material_calculation_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
ENGINEERING_PROCESSOR("material_engineering_processor", EnumSet.of( AEFeature.PROCESSORS ) ),
// Basic Cards
BASIC_CARD( 25, "material_basic_card", EnumSet.of( AEFeature.BASIC_CARDS ) ),
CARD_REDSTONE( 26, "material_card_redstone", EnumSet.of( AEFeature.BASIC_CARDS ) ),
CARD_CAPACITY( 27, "material_card_capacity", EnumSet.of( AEFeature.BASIC_CARDS ) ),
BASIC_CARD("material_basic_card", EnumSet.of( AEFeature.BASIC_CARDS ) ),
CARD_REDSTONE("material_card_redstone", EnumSet.of( AEFeature.BASIC_CARDS ) ),
CARD_CAPACITY("material_card_capacity", EnumSet.of( AEFeature.BASIC_CARDS ) ),
// Adv Cards
ADVANCED_CARD( 28, "material_advanced_card", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_FUZZY( 29, "material_card_fuzzy", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_SPEED( 30, "material_card_speed", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_INVERTER( 31, "material_card_inverter", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
ADVANCED_CARD("material_advanced_card", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_FUZZY("material_card_fuzzy", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_SPEED("material_card_speed", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CARD_INVERTER("material_card_inverter", EnumSet.of( AEFeature.ADVANCED_CARDS ) ),
CELL2_SPATIAL_PART( 32, "material_cell2_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL16_SPATIAL_PART( 33, "material_cell16_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL128_SPATIAL_PART( 34, "material_cell128_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL2_SPATIAL_PART("material_cell2_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL16_SPATIAL_PART("material_cell16_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL128_SPATIAL_PART("material_cell128_spatial_part", EnumSet.of( AEFeature.SPATIAL_IO ) ),
CELL1K_PART( 35, "material_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL4K_PART( 36, "material_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL16K_PART( 37, "material_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL64K_PART( 38, "material_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
EMPTY_STORAGE_CELL( 39, "material_empty_storage_cell", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL1K_PART("material_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL4K_PART("material_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL16K_PART("material_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
CELL64K_PART("material_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
EMPTY_STORAGE_CELL("material_empty_storage_cell", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
WOODEN_GEAR( 40, "material_wooden_gear", EnumSet.of( AEFeature.GRIND_STONE ), "gearWood" ),
WOODEN_GEAR("material_wooden_gear", EnumSet.of( AEFeature.GRIND_STONE ), "gearWood" ),
WIRELESS( 41, "material_wireless", EnumSet.of( AEFeature.WIRELESS_ACCESS_TERMINAL ) ),
WIRELESS_BOOSTER( 42, "material_wireless_booster", EnumSet.of( AEFeature.WIRELESS_ACCESS_TERMINAL ) ),
WIRELESS("material_wireless", EnumSet.of( AEFeature.WIRELESS_ACCESS_TERMINAL ) ),
WIRELESS_BOOSTER("material_wireless_booster", EnumSet.of( AEFeature.WIRELESS_ACCESS_TERMINAL ) ),
FORMATION_CORE( 43, "material_formation_core", EnumSet.of( AEFeature.CORES ) ),
ANNIHILATION_CORE( 44, "material_annihilation_core", EnumSet.of( AEFeature.CORES ) ),
FORMATION_CORE("material_formation_core", EnumSet.of( AEFeature.CORES ) ),
ANNIHILATION_CORE("material_annihilation_core", EnumSet.of( AEFeature.CORES ) ),
SKY_DUST( 45, "material_sky_dust", EnumSet.of( AEFeature.DUSTS ) ),
SKY_DUST("material_sky_dust", EnumSet.of( AEFeature.DUSTS ) ),
ENDER_DUST( 46, "material_ender_dust", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), "dustEnder,dustEnderPearl", EntitySingularity.class ),
SINGULARITY( 47, "material_singularity", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), EntitySingularity.class ),
QUANTUM_ENTANGLED_SINGULARITY( 48, "material_quantum_entangled_singularity", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), EntitySingularity.class ),
ENDER_DUST("material_ender_dust", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), "dustEnder,dustEnderPearl", EntitySingularity.class ),
SINGULARITY("material_singularity", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), EntitySingularity.class ),
QUANTUM_ENTANGLED_SINGULARITY("material_quantum_entangled_singularity", EnumSet.of( AEFeature.QUANTUM_NETWORK_BRIDGE ), EntitySingularity.class ),
BLANK_PATTERN( 52, "material_blank_pattern", EnumSet.of( AEFeature.PATTERNS ) ),
CARD_CRAFTING( 53, "material_card_crafting", EnumSet.of( AEFeature.ADVANCED_CARDS, AEFeature.CRAFTING_CPU ) ),
BLANK_PATTERN("material_blank_pattern", EnumSet.of( AEFeature.PATTERNS ) ),
CARD_CRAFTING("material_card_crafting", EnumSet.of( AEFeature.ADVANCED_CARDS, AEFeature.CRAFTING_CPU ) ),
FLUID_CELL1K_PART( 54, "material_fluid_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL4K_PART( 55, "material_fluid_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL16K_PART( 56, "material_fluid_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL64K_PART( 57, "material_fluid_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) );
FLUID_CELL1K_PART("material_fluid_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL4K_PART("material_fluid_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL16K_PART("material_fluid_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
FLUID_CELL64K_PART("material_fluid_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) );
private final Set<AEFeature> features;
private final ModelResourceLocation model;
private Item itemInstance;
private int damageValue;
// stack!
private MaterialStackSrc stackSrc;
private String oreName;
private Class<? extends Entity> droppedEntity;
private boolean isRegistered = false;
MaterialType( final int metaValue, String modelName )
MaterialType(String modelName)
{
this( metaValue, modelName, EnumSet.of( AEFeature.CORE ) );
this(modelName, EnumSet.of( AEFeature.CORE ) );
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features )
MaterialType(String modelName, final Set<AEFeature> features)
{
this.setDamageValue( metaValue );
this.features = features;
this.model = new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, modelName ), "inventory" );
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features, final Class<? extends Entity> c )
MaterialType(String modelName, final Set<AEFeature> features, final Class<? extends Entity> c)
{
this( metaValue, modelName, features );
this(modelName, features );
this.droppedEntity = c;
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features, final String oreDictionary, final Class<? extends Entity> c )
MaterialType(String modelName, final Set<AEFeature> features, final String oreDictionary, final Class<? extends Entity> c)
{
this( metaValue, modelName, features );
this(modelName, features );
this.oreName = oreDictionary;
this.droppedEntity = c;
}
MaterialType( final int metaValue, String modelName, final Set<AEFeature> features, final String oreDictionary )
MaterialType(String modelName, final Set<AEFeature> features, final String oreDictionary)
{
this( metaValue, modelName, features );
this(modelName, features );
this.oreName = oreDictionary;
}
public ItemStack stack( final int size )
{
//FIXME
return new ItemStack( this.getItemInstance(), size/*, this.getDamageValue()*/ );
return new ItemStack( this.getItemInstance(), size );
}
Set<AEFeature> getFeature()
public Set<AEFeature> getFeature()
{
return this.features;
}
@@ -192,37 +187,27 @@ public enum MaterialType
return this.isRegistered;
}
void markReady()
public void markReady()
{
this.isRegistered = true;
}
public int getDamageValue()
{
return this.damageValue;
}
void setDamageValue( final int damageValue )
{
this.damageValue = damageValue;
}
public Item getItemInstance()
{
return this.itemInstance;
}
void setItemInstance( final Item itemInstance )
public void setItemInstance( final Item itemInstance )
{
this.itemInstance = itemInstance;
}
MaterialStackSrc getStackSrc()
public MaterialStackSrc getStackSrc()
{
return this.stackSrc;
}
void setStackSrc( final MaterialStackSrc stackSrc )
public void setStackSrc( final MaterialStackSrc stackSrc )
{
this.stackSrc = stackSrc;
}
@@ -19,11 +19,11 @@
package appeng.items.misc;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import appeng.api.implementations.items.IGrowableCrystal;
import appeng.core.localization.ButtonToolTips;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.AEBaseItem;
import com.google.common.base.Preconditions;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.util.ITooltipFlag;
@@ -31,127 +31,68 @@ import net.minecraft.entity.Entity;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.api.AEApi;
import appeng.api.definitions.IMaterials;
import appeng.api.implementations.items.IGrowableCrystal;
import appeng.api.recipes.ResolverResult;
import appeng.core.Api;
import appeng.core.localization.ButtonToolTips;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.AEBaseItem;
import javax.annotation.Nullable;
import java.util.List;
/**
* This item reprents one of the seeds used to grow various forms of quartz by
* throwing them into water (for that behavior, see the linked entity)
*/
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
{
static final int LEVEL_OFFSET = 200;
static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
/**
* Name of NBT tag used to store the growth progress value.
*/
private static final String TAG_GROWTH_TICKS = "p";
public static final int CERTUS = 0;
public static final int NETHER = SINGLE_OFFSET;
public static final int FLUIX = SINGLE_OFFSET * 2;
public static final int FINAL_STAGE = SINGLE_OFFSET * 3;
/**
* The number of growth ticks required to finish growing.
*/
private static final int GROWTH_TICKS_REQUIRED = 600;
public ItemCrystalSeed(Properties properties) {
/**
* The item to convert to, when growth finishes.
*/
private final IItemProvider grownItem;
public ItemCrystalSeed(Properties properties, IItemProvider grownItem) {
super(properties);
// FIXME this.setHasSubtypes( true );
}
@Nullable
public static ResolverResult getResolver( final int certus2 )
{
return Api.INSTANCE
.definitions()
.items()
.crystalSeed()
.maybeStack( 1 )
.map( crystalSeedStack ->
{
// FIXME crystalSeedStack.setItemDamage( certus2 );
crystalSeedStack = newStyle( crystalSeedStack );
String itemName = crystalSeedStack.getItem().getRegistryName().getPath();
return new ResolverResult( itemName, crystalSeedStack.getDamage(), crystalSeedStack.getTag() );
} )
.orElse( null );
}
private static ItemStack newStyle( final ItemStack itemStack )
{
getProgress( itemStack );
return itemStack;
}
static int getProgress( final ItemStack is )
{
if( is.hasTag() )
{
return is.getTag().getInt( "progress" );
}
else
{
final int progress;
final CompoundNBT comp = is.getOrCreateTag();
comp.putInt( "progress", progress = is.getDamage() );
// FIXME is.setItemDamage( ( is.getDamage() / SINGLE_OFFSET ) * SINGLE_OFFSET );
return progress;
}
this.grownItem = Preconditions.checkNotNull(grownItem);
}
@Nullable
@Override
public ItemStack triggerGrowth( final ItemStack is )
{
final int newDamage = getProgress( is ) + 1;
final IMaterials materials = Api.INSTANCE.definitions().materials();
final int size = is.getCount();
if( newDamage == CERTUS + SINGLE_OFFSET )
{
Optional<ItemStack> quartzStack = materials.purifiedCertusQuartzCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack.get();
}
final int growthTicks = getGrowthTicks( is ) + 1;
if (growthTicks >= GROWTH_TICKS_REQUIRED) {
return new ItemStack(grownItem, is.getCount());
} else {
this.setGrowthTicks(is, growthTicks);
return is;
}
if( newDamage == NETHER + SINGLE_OFFSET )
{
Optional<ItemStack> quartzStack = materials.purifiedNetherQuartzCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack.get();
}
}
if( newDamage == FLUIX + SINGLE_OFFSET )
{
Optional<ItemStack> quartzStack = materials.purifiedFluixCrystal().maybeStack( size );
if( quartzStack.isPresent() )
{
return quartzStack.get();
}
}
if( newDamage > FINAL_STAGE )
{
return ItemStack.EMPTY;
}
this.setProgress( is, newDamage );
return is;
}
private void setProgress( final ItemStack is, final int newDamage )
private static int getGrowthTicks(final ItemStack is )
{
final CompoundNBT comp = is.getOrCreateTag();
comp.putInt( "progress", newDamage );
// FIXME is.setItemDamage( is.getDamage() / LEVEL_OFFSET * LEVEL_OFFSET );
CompoundNBT tag = is.getTag();
return tag != null ? tag.getInt(TAG_GROWTH_TICKS) : 0;
}
private void setGrowthTicks(final ItemStack is, int ticks)
{
ticks = MathHelper.clamp(ticks, 0, GROWTH_TICKS_REQUIRED);
is.getOrCreateTag().putInt(TAG_GROWTH_TICKS, ticks);
}
@Override
@@ -165,8 +106,8 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
{
lines.add( ButtonToolTips.DoesntDespawn.getTranslationKey() );
final int progress = getProgress( stack ) % SINGLE_OFFSET;
lines.add( new StringTextComponent( Math.floor( (float) progress / (float) ( SINGLE_OFFSET / 100 ) ) + "%" ) );
final int progress = getGrowthTicks( stack );
lines.add( new StringTextComponent( Math.round( 100 * progress / (float) GROWTH_TICKS_REQUIRED ) + "%" ) );
super.addInformation( stack, world, lines, advancedTooltips );
}
@@ -177,47 +118,6 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
return Integer.MAX_VALUE;
}
@Override
public String getTranslationKey( final ItemStack is )
{
final int damage = getProgress( is );
if( damage < CERTUS + SINGLE_OFFSET )
{
return this.getTranslationKey() + ".certus";
}
if( damage < NETHER + SINGLE_OFFSET )
{
return this.getTranslationKey() + ".nether";
}
if( damage < FLUIX + SINGLE_OFFSET )
{
return this.getTranslationKey() + ".fluix";
}
return this.getTranslationKey();
}
@Override
public boolean isDamageable()
{
return false;
}
@Override
public boolean isDamaged( final ItemStack stack )
{
return false;
}
@Override
public int getMaxDamage( final ItemStack stack )
{
return FINAL_STAGE;
}
@Override
public boolean hasCustomEntity( final ItemStack stack )
{
@@ -240,20 +140,14 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
@Override
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
// lvl 0
items.add( newStyle( new ItemStack( this, 1 /* FIXME , CERTUS */ ) ) );
items.add( newStyle( new ItemStack( this, 1 /* FIXME , NETHER */ ) ) );
items.add( newStyle( new ItemStack( this, 1 /* FIXME , FLUIX */ ) ) );
// lvl 1
items.add( newStyle( new ItemStack( this, 1 /* FIXME , LEVEL_OFFSET + CERTUS */ ) ) );
items.add( newStyle( new ItemStack( this, 1 /* FIXME , LEVEL_OFFSET + NETHER */ ) ) );
items.add( newStyle( new ItemStack( this, 1 /* FIXME , LEVEL_OFFSET + FLUIX */ ) ) );
// lvl 2
items.add( newStyle( new ItemStack( this, 1 /* FIXME , LEVEL_OFFSET * 2 + CERTUS */ ) ) );
items.add( newStyle( new ItemStack( this, 1 /* FIXME , LEVEL_OFFSET * 2 + NETHER */ ) ) );
items.add( newStyle( new ItemStack( this, 1 /* FIXME , LEVEL_OFFSET * 2 + FLUIX */ ) ) );
if (this.isInGroup(group)) {
// lvl 0
items.add(new ItemStack(this, 1));
// one tick before maturity
ItemStack almostFullGrown = new ItemStack(this, 1);
setGrowthTicks(almostFullGrown, GROWTH_TICKS_REQUIRED - 1);
items.add(almostFullGrown);
}
}
}