We don't need the showCraftingLabel flag, as IAEStack is perfectly fine with 0 size stacks. (#3071)

Adjust rendering code to use ItemStack with size 1 where required.
This commit is contained in:
fscan 2017-09-09 12:58:22 +02:00 committed by GitHub
parent 955fcac92a
commit 375e1efb15
13 changed files with 38 additions and 67 deletions

View file

@ -203,15 +203,4 @@ public interface IAEStack<StackType extends IAEStack>
* @return ITEM or FLUID
*/
StorageChannel getChannel();
/**
* @return true if it should show the crafting label.
*/
boolean getShowCraftingLabel();
/**
* Used internally to show that it should show a Crafting label instead of a "1"
*/
void setShowCraftingLabel( boolean showCraftingLabel );
}

View file

@ -455,7 +455,8 @@ public abstract class AEBaseGui extends GuiContainer
action = ( mouseButton == 1 ) ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
stack = ( (SlotME) slot ).getAEStack();
if( stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getShowCraftingLabel() && player.inventory.getItemStack().isEmpty() )
if( stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0 && player.inventory.getItemStack()
.isEmpty() )
{
action = InventoryAction.AUTO_CRAFT;
}
@ -715,7 +716,7 @@ public abstract class AEBaseGui extends GuiContainer
// Annoying but easier than trying to splice into render item
super.drawSlot( new Size1Slot( (SlotME) s ) );
this.stackSizeRenderer.renderStackSize( this.fontRenderer, ( (SlotME) s ).getAEStack(), s.getStack(), s.xPos, s.yPos );
this.stackSizeRenderer.renderStackSize( this.fontRenderer, ( (SlotME) s ).getAEStack(), s.xPos, s.yPos );
}
catch( final Exception err )

View file

@ -352,7 +352,8 @@ public class GuiCraftConfirm extends AEBaseGui
final int posX = x * ( 1 + sectionLength ) + xo + sectionLength - 19;
final int posY = y * offY + yo;
final ItemStack is = refStack.copy().getItemStack();
final ItemStack is = refStack.getItemStack();
is.setCount( 1 );
if( this.tooltip == z - viewStart )
{

View file

@ -309,7 +309,8 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
final int posX = x * ( 1 + SECTION_LENGTH ) + ITEMSTACK_LEFT_OFFSET + SECTION_LENGTH - 19;
final int posY = y * offY + ITEMSTACK_TOP_OFFSET;
final ItemStack is = refStack.copy().getItemStack();
final ItemStack is = refStack.getItemStack();
is.setCount( 1 );
if( this.tooltip == z - viewStart )
{

View file

@ -177,12 +177,10 @@ public class ItemRepo
if( viewMode == ViewItems.CRAFTABLE )
{
is = is.copy();
// is.setStackSize( 0 ) triggers isEmpty() and thus only shows empty stacks!
is.setStackSize( 1 );
is.setShowCraftingLabel( true );
is.setStackSize( 0 );
}
if( viewMode == ViewItems.STORED && is.getShowCraftingLabel() )
if( viewMode == ViewItems.STORED && is.getStackSize() == 0 )
{
continue;
}
@ -240,7 +238,9 @@ public class ItemRepo
for( final IAEItemStack is : this.view )
{
this.dsp.add( is.getItemStack() );
final ItemStack displayStack = is.getItemStack();
displayStack.setCount( 1 );
this.dsp.add( displayStack );
}
}

View file

@ -21,7 +21,6 @@ package appeng.client.render;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AEConfig;
@ -42,9 +41,9 @@ public class StackSizeRenderer
private static final ISlimReadableNumberConverter SLIM_CONVERTER = ReadableNumberConverter.INSTANCE;
private static final IWideReadableNumberConverter WIDE_CONVERTER = ReadableNumberConverter.INSTANCE;
public void renderStackSize( FontRenderer fontRenderer, IAEItemStack aeStack, ItemStack is, int xPos, int yPos )
public void renderStackSize( FontRenderer fontRenderer, IAEItemStack aeStack, int xPos, int yPos )
{
if( !is.isEmpty() )
if( aeStack != null )
{
final float scaleFactor = AEConfig.instance().useTerminalUseLargeFont() ? 0.85f : 0.5f;
final float inverseScaleFactor = 1.0f / scaleFactor;
@ -53,7 +52,7 @@ public class StackSizeRenderer
final boolean unicodeFlag = fontRenderer.getUnicodeFlag();
fontRenderer.setUnicodeFlag( false );
if( aeStack.getShowCraftingLabel() )
if( aeStack.getStackSize() == 0 && aeStack.isCraftable() )
{
final String craftLabelText = AEConfig.instance().useTerminalUseLargeFont() ? GuiText.LargeFontCraft.getLocal() : GuiText.SmallFontCraft
.getLocal();
@ -71,10 +70,9 @@ public class StackSizeRenderer
GlStateManager.enableBlend();
}
final long amount = aeStack != null ? aeStack.getStackSize() : is.getCount();
if( amount != 0 && !aeStack.getShowCraftingLabel() )
if( aeStack.getStackSize() > 0 )
{
final String stackSize = this.getToBeRenderedStackSize( amount );
final String stackSize = this.getToBeRenderedStackSize( aeStack.getStackSize() );
GlStateManager.disableLighting();
GlStateManager.disableDepth();

View file

@ -22,6 +22,7 @@ package appeng.client.render.effects;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.storage.data.IAEItemStack;
@ -45,7 +46,9 @@ public class AssemblerFX extends Particle implements ICanDie
this.motionY = 0;
this.motionZ = 0;
this.speed = speed;
this.fi = new EntityFloatingItem( this, w, x, y, z, is.getItemStack() );
final ItemStack displayItem = is.getItemStack();
displayItem.setCount( 1 );
this.fi = new EntityFloatingItem( this, w, x, y, z, displayItem );
w.spawnEntity( this.fi );
this.particleMaxAge = (int) Math.ceil( Math.max( 1, 100.0f / speed ) ) + 2;
}

View file

@ -225,10 +225,11 @@ public abstract class AEBaseContainer extends Container
// client doesn't need to re-send, makes for lower overhead rapid packets.
if( Platform.isClient() )
{
final ItemStack a = stack == null ? ItemStack.EMPTY : stack.getItemStack();
final ItemStack b = this.clientRequestedTargetItem == null ? ItemStack.EMPTY : this.clientRequestedTargetItem.getItemStack();
if( Platform.itemComparisons().isSameItem( a, b ) )
if( stack == null && this.clientRequestedTargetItem == null )
{
return;
}
if( stack != null && stack.isSameType( this.clientRequestedTargetItem ) )
{
return;
}

View file

@ -142,7 +142,7 @@ public class PacketInventoryAction extends AppEngPacket
if( baseContainer.getTargetStack() != null )
{
// Force to stack size 1 to fix a client-side display problem...
ItemStack displayIs = baseContainer.getTargetStack().getItemStack().copy();
ItemStack displayIs = baseContainer.getTargetStack().getItemStack();
displayIs.setCount( 1 );
cca.getCraftingItem().putStack( displayIs );
// This is the *actual* item that matters, not the display item above

View file

@ -80,9 +80,9 @@ public class ItemSorters
{
if( getDirection() == SortDir.ASCENDING )
{
return compareLong( o2.getStackSize() - ( o2.getShowCraftingLabel() ? 1 : 0 ), o1.getStackSize() - ( o1.getShowCraftingLabel() ? 1 : 0 ) );
return compareLong( o2.getStackSize(), o1.getStackSize() );
}
return compareLong( o1.getStackSize() - ( o1.getShowCraftingLabel() ? 1 : 0 ), o2.getStackSize() - ( o2.getShowCraftingLabel() ? 1 : 0 ) );
return compareLong( o1.getStackSize(), o2.getStackSize() );
}
};
private static IInvTweaks api;

View file

@ -60,7 +60,6 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
// priority = is.priority;
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.setShowCraftingLabel( is.getShowCraftingLabel() );
this.myHash = is.myHash;
}
@ -163,7 +162,6 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
final AEFluidStack fluid = AEFluidStack.create( fluidStack );
// fluid.priority = (int) priority;
fluid.setStackSize( stackSize );
fluid.setShowCraftingLabel( showCraftingLabel );
fluid.setCountRequestable( countRequestable );
fluid.setCraftable( isCraftable );
return fluid;
@ -183,7 +181,6 @@ public final class AEFluidStack extends AEStack<IAEFluidStack> implements IAEFlu
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
this.setShowCraftingLabel( this.getShowCraftingLabel() || option.getShowCraftingLabel() );
}
@Override

View file

@ -58,7 +58,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.setStackSize( is.getStackSize() );
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.setShowCraftingLabel( is.getShowCraftingLabel() );
}
private AEItemStack( final ItemStack is )
@ -158,7 +157,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
final boolean isCraftable = ( mask & 0x40 ) > 0;
final boolean hasTagCompound = ( mask & 0x80 ) > 0;
boolean showCraftingLabel = data.readBoolean();
// don't send this...
final NBTTagCompound d = new NBTTagCompound();
@ -186,11 +184,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
final ItemStack itemstack = new ItemStack( d );
if( !showCraftingLabel )
{
showCraftingLabel = stackSize == 0 && isCraftable;
}
if( itemstack.isEmpty() )
{
return null;
@ -198,8 +191,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
final AEItemStack item = AEItemStack.create( itemstack );
// item.priority = (int) priority;
item.setStackSize( showCraftingLabel ? 1 : stackSize );
item.setShowCraftingLabel( showCraftingLabel );
item.setStackSize( stackSize );
item.setCountRequestable( countRequestable );
item.setCraftable( isCraftable );
return item;
@ -219,7 +211,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
this.setShowCraftingLabel( this.getShowCraftingLabel() || option.getShowCraftingLabel() );
}
@Override
@ -597,12 +588,14 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
@SideOnly( Side.CLIENT )
public List getToolTip()
{
if( this.getDefinition().getTooltip() != null )
if( this.getDefinition().getTooltip() == null )
{
return this.getDefinition().getTooltip();
final ItemStack is = this.getItemStack();
is.setCount( 1 );
this.getDefinition().setTooltip( Platform.getTooltip( is ) );
}
return this.getDefinition().setTooltip( Platform.getTooltip( this.getItemStack() ) );
return this.getDefinition().getTooltip();
}
@SideOnly( Side.CLIENT )
@ -610,7 +603,9 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
{
if( this.getDefinition().getDisplayName() == null )
{
this.getDefinition().setDisplayName( Platform.getItemDisplayName( this.getItemStack() ) );
final ItemStack is = this.getItemStack();
is.setCount( 1 );
this.getDefinition().setDisplayName( Platform.getItemDisplayName( is ) );
}
return this.getDefinition().getDisplayName();

View file

@ -32,7 +32,6 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
private boolean isCraftable;
private long stackSize;
private long countRequestable;
private boolean showCraftingLabel = false;
static long getPacketValue( final byte type, final ByteBuf tag )
{
@ -104,22 +103,9 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
// priority = Integer.MIN_VALUE;
this.setCountRequestable( 0 );
this.setCraftable( false );
this.setShowCraftingLabel( false );
return (StackType) this;
}
@Override
public boolean getShowCraftingLabel()
{
return this.showCraftingLabel;
}
@Override
public void setShowCraftingLabel( boolean showCraftingLabel )
{
this.showCraftingLabel = showCraftingLabel;
}
@Override
public boolean isMeaningful()
{
@ -157,7 +143,6 @@ public abstract class AEStack<StackType extends IAEStack> implements IAEStack<St
.getType( this.countRequestable ) << 4 ) | ( (byte) ( this.isCraftable ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
i.writeByte( mask );
i.writeBoolean( this.showCraftingLabel );
this.writeIdentity( i );