Flattening part 1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user