reformatted all src files (#141)
This commit is contained in:
@@ -19,11 +19,14 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.items.IGrowableCrystal;
|
||||
import appeng.api.recipes.ResolverResult;
|
||||
import appeng.core.localization.ButtonToolTips;
|
||||
import appeng.entity.EntityGrowingCrystal;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
@@ -36,225 +39,190 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.items.IGrowableCrystal;
|
||||
import appeng.api.recipes.ResolverResult;
|
||||
import appeng.core.localization.ButtonToolTips;
|
||||
import appeng.entity.EntityGrowingCrystal;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
|
||||
{
|
||||
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal {
|
||||
|
||||
static final int LEVEL_OFFSET = 200;
|
||||
static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
|
||||
static final int LEVEL_OFFSET = 200;
|
||||
static final int SINGLE_OFFSET = LEVEL_OFFSET * 3;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
public ItemCrystalSeed()
|
||||
{
|
||||
this.setHasSubtypes( true );
|
||||
}
|
||||
public ItemCrystalSeed() {
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResolverResult getResolver( final int certus2 )
|
||||
{
|
||||
@Nullable
|
||||
public static ResolverResult getResolver(final int certus2) {
|
||||
|
||||
return AEApi.instance()
|
||||
.definitions()
|
||||
.items()
|
||||
.crystalSeed()
|
||||
.maybeStack( 1 )
|
||||
.map( crystalSeedStack ->
|
||||
{
|
||||
crystalSeedStack.setItemDamage( certus2 );
|
||||
crystalSeedStack = newStyle( crystalSeedStack );
|
||||
String itemName = crystalSeedStack.getItem().getRegistryName().getResourcePath();
|
||||
return new ResolverResult( itemName, crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound() );
|
||||
} )
|
||||
.orElse( null );
|
||||
return AEApi.instance()
|
||||
.definitions()
|
||||
.items()
|
||||
.crystalSeed()
|
||||
.maybeStack(1)
|
||||
.map(crystalSeedStack ->
|
||||
{
|
||||
crystalSeedStack.setItemDamage(certus2);
|
||||
crystalSeedStack = newStyle(crystalSeedStack);
|
||||
String itemName = crystalSeedStack.getItem().getRegistryName().getResourcePath();
|
||||
return new ResolverResult(itemName, crystalSeedStack.getItemDamage(), crystalSeedStack.getTagCompound());
|
||||
})
|
||||
.orElse(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemStack newStyle( final ItemStack itemStack )
|
||||
{
|
||||
getProgress( itemStack );
|
||||
return itemStack;
|
||||
}
|
||||
private static ItemStack newStyle(final ItemStack itemStack) {
|
||||
getProgress(itemStack);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
static int getProgress( final ItemStack is )
|
||||
{
|
||||
if( is.hasTagCompound() )
|
||||
{
|
||||
return is.getTagCompound().getInteger( "progress" );
|
||||
}
|
||||
else
|
||||
{
|
||||
final int progress;
|
||||
final NBTTagCompound comp = Platform.openNbtData( is );
|
||||
comp.setInteger( "progress", progress = is.getItemDamage() );
|
||||
is.setItemDamage( ( is.getItemDamage() / SINGLE_OFFSET ) * SINGLE_OFFSET );
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
static int getProgress(final ItemStack is) {
|
||||
if (is.hasTagCompound()) {
|
||||
return is.getTagCompound().getInteger("progress");
|
||||
} else {
|
||||
final int progress;
|
||||
final NBTTagCompound comp = Platform.openNbtData(is);
|
||||
comp.setInteger("progress", progress = is.getItemDamage());
|
||||
is.setItemDamage((is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET);
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack triggerGrowth( final ItemStack is )
|
||||
{
|
||||
final int newDamage = getProgress( is ) + 1;
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
final int size = is.getCount();
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack triggerGrowth(final ItemStack is) {
|
||||
final int newDamage = getProgress(is) + 1;
|
||||
final IMaterials materials = AEApi.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();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (newDamage == CERTUS + SINGLE_OFFSET) {
|
||||
Optional<ItemStack> quartzStack = materials.purifiedCertusQuartzCrystal().maybeStack(size);
|
||||
if (quartzStack.isPresent()) {
|
||||
return quartzStack.get();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
this.setProgress(is, newDamage);
|
||||
return is;
|
||||
}
|
||||
|
||||
private void setProgress( final ItemStack is, final int newDamage )
|
||||
{
|
||||
final NBTTagCompound comp = Platform.openNbtData( is );
|
||||
comp.setInteger( "progress", newDamage );
|
||||
is.setItemDamage( is.getItemDamage() / LEVEL_OFFSET * LEVEL_OFFSET );
|
||||
}
|
||||
private void setProgress(final ItemStack is, final int newDamage) {
|
||||
final NBTTagCompound comp = Platform.openNbtData(is);
|
||||
comp.setInteger("progress", newDamage);
|
||||
is.setItemDamage(is.getItemDamage() / LEVEL_OFFSET * LEVEL_OFFSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMultiplier( final Block blk, final Material mat )
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
@Override
|
||||
public float getMultiplier(final Block blk, final Material mat) {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
lines.add( ButtonToolTips.DoesntDespawn.getLocal() );
|
||||
final int progress = getProgress( stack ) % SINGLE_OFFSET;
|
||||
lines.add( Math.floor( (float) progress / (float) ( SINGLE_OFFSET / 100 ) ) + "%" );
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
|
||||
lines.add(ButtonToolTips.DoesntDespawn.getLocal());
|
||||
final int progress = getProgress(stack) % SINGLE_OFFSET;
|
||||
lines.add(Math.floor((float) progress / (float) (SINGLE_OFFSET / 100)) + "%");
|
||||
|
||||
super.addCheckedInformation( stack, world, lines, advancedTooltips );
|
||||
}
|
||||
super.addCheckedInformation(stack, world, lines, advancedTooltips);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntityLifespan( final ItemStack itemStack, final World world )
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
@Override
|
||||
public int getEntityLifespan(final ItemStack itemStack, final World world) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName( final ItemStack is )
|
||||
{
|
||||
final int damage = getProgress( is );
|
||||
@Override
|
||||
public String getUnlocalizedName(final ItemStack is) {
|
||||
final int damage = getProgress(is);
|
||||
|
||||
if( damage < CERTUS + SINGLE_OFFSET )
|
||||
{
|
||||
return this.getUnlocalizedName() + ".certus";
|
||||
}
|
||||
if (damage < CERTUS + SINGLE_OFFSET) {
|
||||
return this.getUnlocalizedName() + ".certus";
|
||||
}
|
||||
|
||||
if( damage < NETHER + SINGLE_OFFSET )
|
||||
{
|
||||
return this.getUnlocalizedName() + ".nether";
|
||||
}
|
||||
if (damage < NETHER + SINGLE_OFFSET) {
|
||||
return this.getUnlocalizedName() + ".nether";
|
||||
}
|
||||
|
||||
if( damage < FLUIX + SINGLE_OFFSET )
|
||||
{
|
||||
return this.getUnlocalizedName() + ".fluix";
|
||||
}
|
||||
if (damage < FLUIX + SINGLE_OFFSET) {
|
||||
return this.getUnlocalizedName() + ".fluix";
|
||||
}
|
||||
|
||||
return this.getUnlocalizedName();
|
||||
}
|
||||
return this.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged( final ItemStack stack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isDamaged(final ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage( final ItemStack stack )
|
||||
{
|
||||
return FINAL_STAGE;
|
||||
}
|
||||
@Override
|
||||
public int getMaxDamage(final ItemStack stack) {
|
||||
return FINAL_STAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEntity( final ItemStack stack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomEntity(final ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity createEntity( final World world, final Entity location, final ItemStack itemstack )
|
||||
{
|
||||
final EntityGrowingCrystal egc = new EntityGrowingCrystal( world, location.posX, location.posY, location.posZ, itemstack );
|
||||
@Override
|
||||
public Entity createEntity(final World world, final Entity location, final ItemStack itemstack) {
|
||||
final EntityGrowingCrystal egc = new EntityGrowingCrystal(world, location.posX, location.posY, location.posZ, itemstack);
|
||||
|
||||
egc.motionX = location.motionX;
|
||||
egc.motionY = location.motionY;
|
||||
egc.motionZ = location.motionZ;
|
||||
egc.motionX = location.motionX;
|
||||
egc.motionY = location.motionY;
|
||||
egc.motionZ = location.motionZ;
|
||||
|
||||
// Cannot read the pickup delay of the original item, so we
|
||||
// use the pickup delay used for items dropped by a player instead
|
||||
egc.setPickupDelay( 40 );
|
||||
// Cannot read the pickup delay of the original item, so we
|
||||
// use the pickup delay used for items dropped by a player instead
|
||||
egc.setPickupDelay(40);
|
||||
|
||||
return egc;
|
||||
}
|
||||
return egc;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
|
||||
{
|
||||
// lvl 0
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, CERTUS ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, NETHER ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, FLUIX ) ) );
|
||||
@Override
|
||||
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
|
||||
// lvl 0
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, CERTUS)));
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, NETHER)));
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, FLUIX)));
|
||||
|
||||
// lvl 1
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + CERTUS ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + NETHER ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + FLUIX ) ) );
|
||||
// lvl 1
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET + CERTUS)));
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET + NETHER)));
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET + FLUIX)));
|
||||
|
||||
// lvl 2
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + CERTUS ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + NETHER ) ) );
|
||||
itemStacks.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + FLUIX ) ) );
|
||||
}
|
||||
// lvl 2
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET * 2 + CERTUS)));
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET * 2 + NETHER)));
|
||||
itemStacks.add(newStyle(new ItemStack(this, 1, LEVEL_OFFSET * 2 + FLUIX)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,85 +19,76 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
|
||||
public class ItemCrystalSeedRendering extends ItemRenderingCustomizer {
|
||||
|
||||
public class ItemCrystalSeedRendering extends ItemRenderingCustomizer
|
||||
{
|
||||
private static final ModelResourceLocation[] MODELS_CERTUS = {
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_certus"),
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_certus2"),
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_certus3")
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_FLUIX = {
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_fluix"),
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_fluix2"),
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_fluix3")
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_NETHER = {
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_nether"),
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_nether2"),
|
||||
new ModelResourceLocation("appliedenergistics2:crystal_seed_nether3")
|
||||
};
|
||||
|
||||
private static final ModelResourceLocation[] MODELS_CERTUS = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_certus3" )
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_FLUIX = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_fluix3" )
|
||||
};
|
||||
private static final ModelResourceLocation[] MODELS_NETHER = {
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether2" ),
|
||||
new ModelResourceLocation( "appliedenergistics2:crystal_seed_nether3" )
|
||||
};
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void customize(IItemRendering rendering) {
|
||||
rendering.variants(ImmutableList.<ResourceLocation>builder().add(MODELS_CERTUS).add(MODELS_FLUIX).add(MODELS_NETHER).build());
|
||||
rendering.meshDefinition(this.getItemMeshDefinition());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
rendering.variants( ImmutableList.<ResourceLocation>builder().add( MODELS_CERTUS ).add( MODELS_FLUIX ).add( MODELS_NETHER ).build() );
|
||||
rendering.meshDefinition( this.getItemMeshDefinition() );
|
||||
}
|
||||
private ItemMeshDefinition getItemMeshDefinition() {
|
||||
return is ->
|
||||
{
|
||||
int damage = ItemCrystalSeed.getProgress(is);
|
||||
|
||||
private ItemMeshDefinition getItemMeshDefinition()
|
||||
{
|
||||
return is ->
|
||||
{
|
||||
int damage = ItemCrystalSeed.getProgress( is );
|
||||
// Split the damage value into crystal type and growth level
|
||||
int type = damage / ItemCrystalSeed.SINGLE_OFFSET;
|
||||
int level = (damage % ItemCrystalSeed.SINGLE_OFFSET) / ItemCrystalSeed.LEVEL_OFFSET;
|
||||
|
||||
// Split the damage value into crystal type and growth level
|
||||
int type = damage / ItemCrystalSeed.SINGLE_OFFSET;
|
||||
int level = ( damage % ItemCrystalSeed.SINGLE_OFFSET ) / ItemCrystalSeed.LEVEL_OFFSET;
|
||||
// Determine which list of models to use based on the type of crystal
|
||||
ModelResourceLocation[] models;
|
||||
switch (type) {
|
||||
case 0:
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
case 1:
|
||||
models = MODELS_NETHER;
|
||||
break;
|
||||
case 2:
|
||||
models = MODELS_FLUIX;
|
||||
break;
|
||||
default:
|
||||
// We use this as the fallback for broken items
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
}
|
||||
|
||||
// Determine which list of models to use based on the type of crystal
|
||||
ModelResourceLocation[] models;
|
||||
switch( type )
|
||||
{
|
||||
case 0:
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
case 1:
|
||||
models = MODELS_NETHER;
|
||||
break;
|
||||
case 2:
|
||||
models = MODELS_FLUIX;
|
||||
break;
|
||||
default:
|
||||
// We use this as the fallback for broken items
|
||||
models = MODELS_CERTUS;
|
||||
break;
|
||||
}
|
||||
// Return one of the 3 models based on the level
|
||||
if (level < 0) {
|
||||
level = 0;
|
||||
} else if (level >= models.length) {
|
||||
level = models.length - 1;
|
||||
}
|
||||
|
||||
// Return one of the 3 models based on the level
|
||||
if( level < 0 )
|
||||
{
|
||||
level = 0;
|
||||
}
|
||||
else if( level >= models.length )
|
||||
{
|
||||
level = models.length - 1;
|
||||
}
|
||||
|
||||
return models[level];
|
||||
};
|
||||
}
|
||||
return models[level];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,16 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.helpers.InvalidPatternHelper;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -37,197 +43,161 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.helpers.InvalidPatternHelper;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
|
||||
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem
|
||||
{
|
||||
// rather simple client side caching.
|
||||
private static final Map<ItemStack, ItemStack> SIMPLE_CACHE = new WeakHashMap<>();
|
||||
public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternItem {
|
||||
// rather simple client side caching.
|
||||
private static final Map<ItemStack, ItemStack> SIMPLE_CACHE = new WeakHashMap<>();
|
||||
|
||||
public ItemEncodedPattern()
|
||||
{
|
||||
this.setMaxStackSize( 64 );
|
||||
}
|
||||
public ItemEncodedPattern() {
|
||||
this.setMaxStackSize(64);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick( final World w, final EntityPlayer player, final EnumHand hand )
|
||||
{
|
||||
this.clearPattern( player.getHeldItem( hand ), player );
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(final World w, final EntityPlayer player, final EnumHand hand) {
|
||||
this.clearPattern(player.getHeldItem(hand), player);
|
||||
|
||||
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
|
||||
}
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand )
|
||||
{
|
||||
return this.clearPattern( player.getHeldItem( hand ), player ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
|
||||
}
|
||||
@Override
|
||||
public EnumActionResult onItemUseFirst(final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) {
|
||||
return this.clearPattern(player.getHeldItem(hand), player) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
private boolean clearPattern( final ItemStack stack, final EntityPlayer player )
|
||||
{
|
||||
if( player.isSneaking() )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
private boolean clearPattern(final ItemStack stack, final EntityPlayer player) {
|
||||
if (player.isSneaking()) {
|
||||
if (Platform.isClient()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final InventoryPlayer inv = player.inventory;
|
||||
final InventoryPlayer inv = player.inventory;
|
||||
|
||||
ItemStack is = AEApi.instance().definitions().materials().blankPattern().maybeStack( stack.getCount() ).orElse( ItemStack.EMPTY );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
for( int s = 0; s < player.inventory.getSizeInventory(); s++ )
|
||||
{
|
||||
if( inv.getStackInSlot( s ) == stack )
|
||||
{
|
||||
inv.setInventorySlotContents( s, is );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStack is = AEApi.instance().definitions().materials().blankPattern().maybeStack(stack.getCount()).orElse(ItemStack.EMPTY);
|
||||
if (!is.isEmpty()) {
|
||||
for (int s = 0; s < player.inventory.getSizeInventory(); s++) {
|
||||
if (inv.getStackInSlot(s) == stack) {
|
||||
inv.setInventorySlotContents(s, is);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void addCheckedInformation( final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final ICraftingPatternDetails details = this.getPatternForItem( stack, world );
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addCheckedInformation(final ItemStack stack, final World world, final List<String> lines, final ITooltipFlag advancedTooltips) {
|
||||
final ICraftingPatternDetails details = this.getPatternForItem(stack, world);
|
||||
|
||||
if( details == null )
|
||||
{
|
||||
if( !stack.hasTagCompound() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (details == null) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
return;
|
||||
}
|
||||
|
||||
stack.setStackDisplayName( TextFormatting.RED + GuiText.InvalidPattern.getLocal() );
|
||||
stack.setStackDisplayName(TextFormatting.RED + GuiText.InvalidPattern.getLocal());
|
||||
|
||||
InvalidPatternHelper invalid = new InvalidPatternHelper( stack );
|
||||
InvalidPatternHelper invalid = new InvalidPatternHelper(stack);
|
||||
|
||||
final String label = ( invalid.isCraftable() ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal() ) + ": ";
|
||||
final String and = ' ' + GuiText.And.getLocal() + ' ';
|
||||
final String with = GuiText.With.getLocal() + ": ";
|
||||
final String label = (invalid.isCraftable() ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
|
||||
final String and = ' ' + GuiText.And.getLocal() + ' ';
|
||||
final String with = GuiText.With.getLocal() + ": ";
|
||||
|
||||
boolean first = true;
|
||||
for( final InvalidPatternHelper.PatternIngredient output : invalid.getOutputs() )
|
||||
{
|
||||
lines.add( ( first ? label : and ) + output.getFormattedToolTip() );
|
||||
first = false;
|
||||
}
|
||||
boolean first = true;
|
||||
for (final InvalidPatternHelper.PatternIngredient output : invalid.getOutputs()) {
|
||||
lines.add((first ? label : and) + output.getFormattedToolTip());
|
||||
first = false;
|
||||
}
|
||||
|
||||
first = true;
|
||||
for( final InvalidPatternHelper.PatternIngredient input : invalid.getInputs() )
|
||||
{
|
||||
lines.add( ( first ? with : and ) + input.getFormattedToolTip() );
|
||||
first = false;
|
||||
}
|
||||
first = true;
|
||||
for (final InvalidPatternHelper.PatternIngredient input : invalid.getInputs()) {
|
||||
lines.add((first ? with : and) + input.getFormattedToolTip());
|
||||
first = false;
|
||||
}
|
||||
|
||||
if( invalid.isCraftable() )
|
||||
{
|
||||
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
|
||||
final String canSubstitute = invalid.canSubstitute() ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
|
||||
if (invalid.isCraftable()) {
|
||||
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
|
||||
final String canSubstitute = invalid.canSubstitute() ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
|
||||
|
||||
lines.add( substitutionLabel + canSubstitute );
|
||||
}
|
||||
lines.add(substitutionLabel + canSubstitute);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if( stack.hasDisplayName() )
|
||||
{
|
||||
stack.removeSubCompound( "display" );
|
||||
}
|
||||
if (stack.hasDisplayName()) {
|
||||
stack.removeSubCompound("display");
|
||||
}
|
||||
|
||||
final boolean isCrafting = details.isCraftable();
|
||||
final boolean substitute = details.canSubstitute();
|
||||
final boolean isCrafting = details.isCraftable();
|
||||
final boolean substitute = details.canSubstitute();
|
||||
|
||||
final IAEItemStack[] in = details.getCondensedInputs();
|
||||
final IAEItemStack[] out = details.getCondensedOutputs();
|
||||
final IAEItemStack[] in = details.getCondensedInputs();
|
||||
final IAEItemStack[] out = details.getCondensedOutputs();
|
||||
|
||||
final String label = ( isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal() ) + ": ";
|
||||
final String and = ' ' + GuiText.And.getLocal() + ' ';
|
||||
final String with = GuiText.With.getLocal() + ": ";
|
||||
final String label = (isCrafting ? GuiText.Crafts.getLocal() : GuiText.Creates.getLocal()) + ": ";
|
||||
final String and = ' ' + GuiText.And.getLocal() + ' ';
|
||||
final String with = GuiText.With.getLocal() + ": ";
|
||||
|
||||
boolean first = true;
|
||||
for( final IAEItemStack anOut : out )
|
||||
{
|
||||
if( anOut == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
boolean first = true;
|
||||
for (final IAEItemStack anOut : out) {
|
||||
if (anOut == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lines.add( ( first ? label : and ) + anOut.getStackSize() + ' ' + Platform.getItemDisplayName( anOut ) );
|
||||
first = false;
|
||||
}
|
||||
lines.add((first ? label : and) + anOut.getStackSize() + ' ' + Platform.getItemDisplayName(anOut));
|
||||
first = false;
|
||||
}
|
||||
|
||||
first = true;
|
||||
for( final IAEItemStack anIn : in )
|
||||
{
|
||||
if( anIn == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
first = true;
|
||||
for (final IAEItemStack anIn : in) {
|
||||
if (anIn == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lines.add( ( first ? with : and ) + anIn.getStackSize() + ' ' + Platform.getItemDisplayName( anIn ) );
|
||||
first = false;
|
||||
}
|
||||
lines.add((first ? with : and) + anIn.getStackSize() + ' ' + Platform.getItemDisplayName(anIn));
|
||||
first = false;
|
||||
}
|
||||
|
||||
if( isCrafting )
|
||||
{
|
||||
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
|
||||
final String canSubstitute = substitute ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
|
||||
if (isCrafting) {
|
||||
final String substitutionLabel = GuiText.Substitute.getLocal() + " ";
|
||||
final String canSubstitute = substitute ? GuiText.Yes.getLocal() : GuiText.No.getLocal();
|
||||
|
||||
lines.add( substitutionLabel + canSubstitute );
|
||||
}
|
||||
}
|
||||
lines.add(substitutionLabel + canSubstitute);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPatternDetails getPatternForItem( final ItemStack is, final World w )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new PatternHelper( is, w );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public ICraftingPatternDetails getPatternForItem(final ItemStack is, final World w) {
|
||||
try {
|
||||
return new PatternHelper(is, w);
|
||||
} catch (final Throwable t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getOutput( final ItemStack item )
|
||||
{
|
||||
ItemStack out = SIMPLE_CACHE.get( item );
|
||||
public ItemStack getOutput(final ItemStack item) {
|
||||
ItemStack out = SIMPLE_CACHE.get(item);
|
||||
|
||||
if( out != null )
|
||||
{
|
||||
return out;
|
||||
}
|
||||
if (out != null) {
|
||||
return out;
|
||||
}
|
||||
|
||||
final World w = AppEng.proxy.getWorld();
|
||||
if( w == null )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
final World w = AppEng.proxy.getWorld();
|
||||
if (w == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
final ICraftingPatternDetails details = this.getPatternForItem( item, w );
|
||||
final ICraftingPatternDetails details = this.getPatternForItem(item, w);
|
||||
|
||||
out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY;
|
||||
out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY;
|
||||
|
||||
SIMPLE_CACHE.put( item, out );
|
||||
return out;
|
||||
}
|
||||
SIMPLE_CACHE.put(item, out);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,76 +19,62 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
|
||||
public class ItemPaintBall extends AEBaseItem {
|
||||
|
||||
public class ItemPaintBall extends AEBaseItem
|
||||
{
|
||||
private static final int DAMAGE_THRESHOLD = 20;
|
||||
|
||||
private static final int DAMAGE_THRESHOLD = 20;
|
||||
public ItemPaintBall() {
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public ItemPaintBall()
|
||||
{
|
||||
this.setHasSubtypes( true );
|
||||
}
|
||||
@Override
|
||||
public String getItemStackDisplayName(final ItemStack is) {
|
||||
return super.getItemStackDisplayName(is) + " - " + this.getExtraName(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName( final ItemStack is )
|
||||
{
|
||||
return super.getItemStackDisplayName( is ) + " - " + this.getExtraName( is );
|
||||
}
|
||||
private String getExtraName(final ItemStack is) {
|
||||
return (is.getItemDamage() >= DAMAGE_THRESHOLD ? GuiText.Lumen.getLocal() + ' ' : "") + this.getColor(is);
|
||||
}
|
||||
|
||||
private String getExtraName( final ItemStack is )
|
||||
{
|
||||
return ( is.getItemDamage() >= DAMAGE_THRESHOLD ? GuiText.Lumen.getLocal() + ' ' : "" ) + this.getColor( is );
|
||||
}
|
||||
public AEColor getColor(final ItemStack is) {
|
||||
int dmg = is.getItemDamage();
|
||||
if (dmg >= DAMAGE_THRESHOLD) {
|
||||
dmg -= DAMAGE_THRESHOLD;
|
||||
}
|
||||
|
||||
public AEColor getColor( final ItemStack is )
|
||||
{
|
||||
int dmg = is.getItemDamage();
|
||||
if( dmg >= DAMAGE_THRESHOLD )
|
||||
{
|
||||
dmg -= DAMAGE_THRESHOLD;
|
||||
}
|
||||
if (dmg >= AEColor.values().length) {
|
||||
return AEColor.TRANSPARENT;
|
||||
}
|
||||
|
||||
if( dmg >= AEColor.values().length )
|
||||
{
|
||||
return AEColor.TRANSPARENT;
|
||||
}
|
||||
return AEColor.values()[dmg];
|
||||
}
|
||||
|
||||
return AEColor.values()[dmg];
|
||||
}
|
||||
@Override
|
||||
protected void getCheckedSubItems(final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks) {
|
||||
for (final AEColor c : AEColor.values()) {
|
||||
if (c != AEColor.TRANSPARENT) {
|
||||
itemStacks.add(new ItemStack(this, 1, c.ordinal()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getCheckedSubItems( final CreativeTabs creativeTab, final NonNullList<ItemStack> itemStacks )
|
||||
{
|
||||
for( final AEColor c : AEColor.values() )
|
||||
{
|
||||
if( c != AEColor.TRANSPARENT )
|
||||
{
|
||||
itemStacks.add( new ItemStack( this, 1, c.ordinal() ) );
|
||||
}
|
||||
}
|
||||
for (final AEColor c : AEColor.values()) {
|
||||
if (c != AEColor.TRANSPARENT) {
|
||||
itemStacks.add(new ItemStack(this, 1, DAMAGE_THRESHOLD + c.ordinal()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final AEColor c : AEColor.values() )
|
||||
{
|
||||
if( c != AEColor.TRANSPARENT )
|
||||
{
|
||||
itemStacks.add( new ItemStack( this, 1, DAMAGE_THRESHOLD + c.ordinal() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLumen( final ItemStack is )
|
||||
{
|
||||
final int dmg = is.getItemDamage();
|
||||
return dmg >= DAMAGE_THRESHOLD;
|
||||
}
|
||||
public static boolean isLumen(final ItemStack is) {
|
||||
final int dmg = is.getItemDamage();
|
||||
return dmg >= DAMAGE_THRESHOLD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,46 +19,39 @@
|
||||
package appeng.items.misc;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.bootstrap.IItemRendering;
|
||||
import appeng.bootstrap.ItemRenderingCustomizer;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class ItemPaintBallRendering extends ItemRenderingCustomizer
|
||||
{
|
||||
public class ItemPaintBallRendering extends ItemRenderingCustomizer {
|
||||
|
||||
private static final ModelResourceLocation MODEL_NORMAL = new ModelResourceLocation( "appliedenergistics2:paint_ball" );
|
||||
private static final ModelResourceLocation MODEL_SHIMMER = new ModelResourceLocation( "appliedenergistics2:paint_ball_shimmer" );
|
||||
private static final ModelResourceLocation MODEL_NORMAL = new ModelResourceLocation("appliedenergistics2:paint_ball");
|
||||
private static final ModelResourceLocation MODEL_SHIMMER = new ModelResourceLocation("appliedenergistics2:paint_ball_shimmer");
|
||||
|
||||
@Override
|
||||
public void customize( IItemRendering rendering )
|
||||
{
|
||||
rendering.color( ItemPaintBallRendering::getColorFromItemstack );
|
||||
rendering.variants( MODEL_NORMAL, MODEL_SHIMMER );
|
||||
rendering.meshDefinition( is -> ItemPaintBall.isLumen( is ) ? MODEL_SHIMMER : MODEL_NORMAL );
|
||||
}
|
||||
@Override
|
||||
public void customize(IItemRendering rendering) {
|
||||
rendering.color(ItemPaintBallRendering::getColorFromItemstack);
|
||||
rendering.variants(MODEL_NORMAL, MODEL_SHIMMER);
|
||||
rendering.meshDefinition(is -> ItemPaintBall.isLumen(is) ? MODEL_SHIMMER : MODEL_NORMAL);
|
||||
}
|
||||
|
||||
private static int getColorFromItemstack( ItemStack stack, int tintIndex )
|
||||
{
|
||||
final AEColor col = ( (ItemPaintBall) stack.getItem() ).getColor( stack );
|
||||
private static int getColorFromItemstack(ItemStack stack, int tintIndex) {
|
||||
final AEColor col = ((ItemPaintBall) stack.getItem()).getColor(stack);
|
||||
|
||||
final int colorValue = stack.getItemDamage() >= 20 ? col.mediumVariant : col.mediumVariant;
|
||||
final int r = ( colorValue >> 16 ) & 0xff;
|
||||
final int g = ( colorValue >> 8 ) & 0xff;
|
||||
final int b = ( colorValue ) & 0xff;
|
||||
final int colorValue = col.mediumVariant;
|
||||
final int r = (colorValue >> 16) & 0xff;
|
||||
final int g = (colorValue >> 8) & 0xff;
|
||||
final int b = (colorValue) & 0xff;
|
||||
|
||||
if( stack.getItemDamage() >= 20 )
|
||||
{
|
||||
final float fail = 0.7f;
|
||||
final int full = (int) ( 255 * 0.3 );
|
||||
return (int) ( full + r * fail ) << 16 | (int) ( full + g * fail ) << 8 | (int) ( full + b * fail ) | 0xff << 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r << 16 | g << 8 | b | 0xff << 24;
|
||||
}
|
||||
}
|
||||
if (stack.getItemDamage() >= 20) {
|
||||
final float fail = 0.7f;
|
||||
final int full = (int) (255 * 0.3);
|
||||
return (int) (full + r * fail) << 16 | (int) (full + g * fail) << 8 | (int) (full + b * fail) | 0xff << 24;
|
||||
} else {
|
||||
return r << 16 | g << 8 | b | 0xff << 24;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user