pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,12 +18,12 @@
package appeng.items.misc;
import java.util.List;
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;
@@ -41,121 +41,116 @@ import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nullable;
import java.util.List;
import appeng.api.implementations.items.IGrowableCrystal;
import appeng.core.localization.ButtonToolTips;
import appeng.entity.EntityGrowingCrystal;
import appeng.items.AEBaseItem;
/**
* 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
{
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal {
/**
* Name of NBT tag used to store the growth progress value.
*/
private static final String TAG_GROWTH_TICKS = "p";
/**
* Name of NBT tag used to store the growth progress value.
*/
private static final String TAG_GROWTH_TICKS = "p";
/**
* The number of growth ticks required to finish growing.
*/
private static final int GROWTH_TICKS_REQUIRED = 600;
/**
* The number of growth ticks required to finish growing.
*/
private static final int GROWTH_TICKS_REQUIRED = 600;
/**
* The item to convert to, when growth finishes.
*/
private final IItemProvider grownItem;
/**
* The item to convert to, when growth finishes.
*/
private final IItemProvider grownItem;
public ItemCrystalSeed(Properties properties, IItemProvider grownItem) {
super(properties);
this.grownItem = Preconditions.checkNotNull(grownItem);
// Expose the growth of the seed to the model system
addPropertyOverride(new ResourceLocation("appliedenergistics2:growth"),
(is, w, p) -> getGrowthTicks(is) / (float) GROWTH_TICKS_REQUIRED);
}
public ItemCrystalSeed(Properties properties, IItemProvider grownItem) {
super(properties);
this.grownItem = Preconditions.checkNotNull(grownItem);
// Expose the growth of the seed to the model system
addPropertyOverride(new ResourceLocation("appliedenergistics2:growth"),
(is, w, p) -> getGrowthTicks(is) / (float) GROWTH_TICKS_REQUIRED);
}
@Nullable
@Override
public ItemStack triggerGrowth( final ItemStack is )
{
final int growthTicks = getGrowthTicks( is ) + 1;
if (growthTicks >= GROWTH_TICKS_REQUIRED) {
return new ItemStack(grownItem, is.getCount());
} else {
this.setGrowthTicks(is, growthTicks);
return is;
}
}
@Nullable
@Override
public ItemStack triggerGrowth(final ItemStack is) {
final int growthTicks = getGrowthTicks(is) + 1;
if (growthTicks >= GROWTH_TICKS_REQUIRED) {
return new ItemStack(grownItem, is.getCount());
} else {
this.setGrowthTicks(is, growthTicks);
return is;
}
}
private static int getGrowthTicks(final ItemStack is )
{
CompoundNBT tag = is.getTag();
return tag != null ? tag.getInt(TAG_GROWTH_TICKS) : 0;
}
private static int getGrowthTicks(final ItemStack is) {
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);
}
private void setGrowthTicks(final ItemStack is, int ticks) {
ticks = MathHelper.clamp(ticks, 0, GROWTH_TICKS_REQUIRED);
is.getOrCreateTag().putInt(TAG_GROWTH_TICKS, ticks);
}
@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
@OnlyIn( Dist.CLIENT )
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
{
lines.add( ButtonToolTips.DoesntDespawn.getTranslationKey() );
lines.add(getGrowthTooltipItem(stack));
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
final ITooltipFlag advancedTooltips) {
lines.add(ButtonToolTips.DoesntDespawn.getTranslationKey());
lines.add(getGrowthTooltipItem(stack));
super.addInformation( stack, world, lines, advancedTooltips );
}
super.addInformation(stack, world, lines, advancedTooltips);
}
public ITextComponent getGrowthTooltipItem(ItemStack stack) {
final int progress = getGrowthTicks( stack );
return new StringTextComponent( Math.round( 100 * progress / (float) GROWTH_TICKS_REQUIRED ) + "%" );
}
public ITextComponent getGrowthTooltipItem(ItemStack stack) {
final int progress = getGrowthTicks(stack);
return new StringTextComponent(Math.round(100 * progress / (float) GROWTH_TICKS_REQUIRED) + "%");
}
@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 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.getPosX(), location.getPosY(), location.getPosZ(), itemstack );
@Override
public Entity createEntity(final World world, final Entity location, final ItemStack itemstack) {
final EntityGrowingCrystal egc = new EntityGrowingCrystal(world, location.getPosX(), location.getPosY(),
location.getPosZ(), itemstack);
egc.setMotion( location.getMotion() );
egc.setMotion(location.getMotion());
// 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
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
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);
}
}
@Override
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
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);
}
}
}
@@ -18,17 +18,10 @@
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.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@@ -44,189 +37,176 @@ import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
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;
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(Properties properties) {
super(properties);
}
public ItemEncodedPattern(Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> onItemRightClick(final World w, final PlayerEntity player, final Hand hand) {
this.clearPattern(player.getHeldItem(hand), player);
@Override
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity player, final Hand hand )
{
this.clearPattern( player.getHeldItem( hand ), player );
return new ActionResult<>(ActionResultType.SUCCESS, player.getHeldItem(hand));
}
return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
return this.clearPattern(stack, context.getPlayer()) ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
@Override
public ActionResultType onItemUseFirst( ItemStack stack, ItemUseContext context )
{
return this.clearPattern( stack, context.getPlayer() ) ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
private boolean clearPattern(final ItemStack stack, final PlayerEntity player) {
if (player.isCrouching()) {
if (Platform.isClient()) {
return false;
}
private boolean clearPattern( final ItemStack stack, final PlayerEntity player )
{
if( player.isCrouching() )
{
if( Platform.isClient() )
{
return false;
}
final PlayerInventory inv = player.inventory;
final PlayerInventory 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
@OnlyIn(Dist.CLIENT)
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines,
final ITooltipFlag advancedTooltips) {
final ICraftingPatternDetails details = this.getPatternForItem(stack, world);
@Override
@OnlyIn( Dist.CLIENT )
public void addInformation( final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
{
final ICraftingPatternDetails details = this.getPatternForItem( stack, world );
if (details == null) {
if (!stack.hasTag()) {
return;
}
if( details == null )
{
if( !stack.hasTag() )
{
return;
}
stack.setDisplayName(GuiText.InvalidPattern.textComponent().applyTextStyle(TextFormatting.RED));
stack.setDisplayName(GuiText.InvalidPattern.textComponent().applyTextStyle(TextFormatting.RED));
InvalidPatternHelper invalid = new InvalidPatternHelper(stack);
InvalidPatternHelper invalid = new InvalidPatternHelper( stack );
final ITextComponent label = (invalid.isCraftable() ? GuiText.Crafts.textComponent()
: GuiText.Creates.textComponent()).appendText(": ");
final ITextComponent and = new StringTextComponent(" ").appendSibling(GuiText.And.textComponent())
.appendText(" ");
final ITextComponent with = GuiText.With.textComponent().appendText(": ");
final ITextComponent label = (invalid.isCraftable() ? GuiText.Crafts.textComponent() : GuiText.Creates.textComponent()).appendText(": ");
final ITextComponent and = new StringTextComponent(" ").appendSibling(GuiText.And.textComponent()).appendText(" ");
final ITextComponent with = GuiText.With.textComponent().appendText(": ");
boolean first = true;
for (final InvalidPatternHelper.PatternIngredient output : invalid.getOutputs()) {
lines.add((first ? label : and).deepCopy().appendSibling(output.getFormattedToolTip()));
first = false;
}
boolean first = true;
for( final InvalidPatternHelper.PatternIngredient output : invalid.getOutputs() )
{
lines.add( ( first ? label : and ).deepCopy().appendSibling(output.getFormattedToolTip()) );
first = false;
}
first = true;
for (final InvalidPatternHelper.PatternIngredient input : invalid.getInputs()) {
lines.add((first ? with : and).deepCopy().appendSibling(input.getFormattedToolTip()));
first = false;
}
first = true;
for( final InvalidPatternHelper.PatternIngredient input : invalid.getInputs() )
{
lines.add( ( first ? with : and ).deepCopy().appendSibling(input.getFormattedToolTip()) );
first = false;
}
if (invalid.isCraftable()) {
final ITextComponent substitutionLabel = GuiText.Substitute.textComponent().appendText(" ");
final ITextComponent canSubstitute = invalid.canSubstitute() ? GuiText.Yes.textComponent()
: GuiText.No.textComponent();
if( invalid.isCraftable() )
{
final ITextComponent substitutionLabel = GuiText.Substitute.textComponent().appendText(" ");
final ITextComponent canSubstitute = invalid.canSubstitute() ? GuiText.Yes.textComponent() : GuiText.No.textComponent();
lines.add(substitutionLabel.appendSibling(canSubstitute));
}
lines.add( substitutionLabel.appendSibling(canSubstitute) );
}
return;
}
return;
}
if (stack.hasDisplayName()) {
stack.removeChildTag("display");
}
if( stack.hasDisplayName() )
{
stack.removeChildTag( "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 ITextComponent label = (isCrafting ? GuiText.Crafts.textComponent() : GuiText.Creates.textComponent())
.appendText(": ");
final ITextComponent and = new StringTextComponent(" ").appendSibling(GuiText.And.textComponent())
.appendText(" ");
final ITextComponent with = GuiText.With.textComponent().appendText(": ");
final ITextComponent label = ( isCrafting ? GuiText.Crafts.textComponent() : GuiText.Creates.textComponent() ).appendText(": ");
final ITextComponent and = new StringTextComponent(" ").appendSibling(GuiText.And.textComponent()).appendText(" ");
final ITextComponent with = GuiText.With.textComponent().appendText(": ");
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).deepCopy().appendText(anOut.getStackSize() + "x ")
.appendSibling(Platform.getItemDisplayName(anOut)));
first = false;
}
lines.add( ( first ? label : and ).deepCopy().appendText(anOut.getStackSize() + "x ").appendSibling(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).deepCopy().appendText(anIn.getStackSize() + "x ")
.appendSibling(Platform.getItemDisplayName(anIn)));
first = false;
}
lines.add((first ? with : and).deepCopy().appendText(anIn.getStackSize() + "x ").appendSibling(Platform.getItemDisplayName(anIn)));
first = false;
}
if (isCrafting) {
final ITextComponent substitutionLabel = GuiText.Substitute.textComponent().appendText(" ");
final ITextComponent canSubstitute = substitute ? GuiText.Yes.textComponent() : GuiText.No.textComponent();
if( isCrafting )
{
final ITextComponent substitutionLabel = GuiText.Substitute.textComponent().appendText(" ");
final ITextComponent canSubstitute = substitute ? GuiText.Yes.textComponent() : GuiText.No.textComponent();
lines.add(substitutionLabel.appendSibling(canSubstitute));
}
}
lines.add( substitutionLabel.appendSibling(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;
}
}
@@ -18,9 +18,6 @@
package appeng.items.misc;
import appeng.api.util.AEColor;
import appeng.items.AEBaseItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
@@ -29,28 +26,27 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import appeng.api.util.AEColor;
import appeng.items.AEBaseItem;
public class ItemPaintBall extends AEBaseItem
{
public class ItemPaintBall extends AEBaseItem {
private final AEColor color;
private final AEColor color;
private final boolean lumen;
private final boolean lumen;
public ItemPaintBall(Properties properties, AEColor color, boolean lumen) {
super(properties);
this.color = color;
this.lumen = lumen;
}
public ItemPaintBall(Properties properties, AEColor color, boolean lumen) {
super(properties);
this.color = color;
this.lumen = lumen;
}
public AEColor getColor()
{
return color;
}
public AEColor getColor() {
return color;
}
public boolean isLumen()
{
return lumen;
}
public boolean isLumen() {
return lumen;
}
}
@@ -18,46 +18,39 @@
package appeng.items.misc;
import appeng.api.util.AEColor;
import appeng.bootstrap.IItemRendering;
import appeng.bootstrap.ItemRenderingCustomizer;
public class ItemPaintBallRendering extends ItemRenderingCustomizer {
public class ItemPaintBallRendering extends ItemRenderingCustomizer
{
private final boolean lumen;
private final boolean lumen;
private final AEColor color;
private final AEColor color;
public ItemPaintBallRendering(AEColor color, boolean lumen) {
this.lumen = lumen;
this.color = color;
}
public ItemPaintBallRendering(AEColor color, boolean lumen) {
this.lumen = lumen;
this.color = color;
}
@Override
public void customize(IItemRendering rendering) {
final int colorValue = lumen ? color.mediumVariant : color.mediumVariant;
final int r = (colorValue >> 16) & 0xff;
final int g = (colorValue >> 8) & 0xff;
final int b = (colorValue) & 0xff;
@Override
public void customize( IItemRendering rendering )
{
final int colorValue = lumen ? color.mediumVariant : color.mediumVariant;
final int r = ( colorValue >> 16 ) & 0xff;
final int g = ( colorValue >> 8 ) & 0xff;
final int b = ( colorValue ) & 0xff;
int renderColor;
if (lumen) {
final float fail = 0.7f;
final int full = (int) (255 * 0.3);
renderColor = (int) (full + r * fail) << 16 | (int) (full + g * fail) << 8 | (int) (full + b * fail)
| 0xff << 24;
} else {
renderColor = r << 16 | g << 8 | b | 0xff << 24;
}
int renderColor;
if( lumen )
{
final float fail = 0.7f;
final int full = (int) ( 255 * 0.3 );
renderColor = (int) ( full + r * fail ) << 16 | (int) ( full + g * fail ) << 8 | (int) ( full + b * fail ) | 0xff << 24;
}
else
{
renderColor = r << 16 | g << 8 | b | 0xff << 24;
}
rendering.color( (is, tintIndex) -> renderColor );
}
rendering.color((is, tintIndex) -> renderColor);
}
}