Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We don't need the showCraftingLabel flag #3071

Merged
merged 1 commit into from Sep 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/api/java/appeng/api/storage/data/IAEStack.java
Expand Up @@ -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 );

}
5 changes: 3 additions & 2 deletions src/main/java/appeng/client/gui/AEBaseGui.java
Expand Up @@ -455,7 +455,8 @@ else if( slot instanceof SlotCraftingTerm )
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;
}
Expand Down Expand Up @@ -715,7 +716,7 @@ public void drawSlot( Slot s )
// 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 )
Expand Down
Expand Up @@ -352,7 +352,8 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
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 )
{
Expand Down
Expand Up @@ -309,7 +309,8 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina
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 )
{
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/appeng/client/me/ItemRepo.java
Expand Up @@ -177,12 +177,10 @@ public void updateView()
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;
}
Expand Down Expand Up @@ -240,7 +238,9 @@ else if( SortBy == SortOrder.INVTWEAKS )

for( final IAEItemStack is : this.view )
{
this.dsp.add( is.getItemStack() );
final ItemStack displayStack = is.getItemStack();
displayStack.setCount( 1 );
this.dsp.add( displayStack );
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/appeng/client/render/StackSizeRenderer.java
Expand Up @@ -21,7 +21,6 @@

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;
Expand All @@ -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;
Expand All @@ -53,7 +52,7 @@ public void renderStackSize( FontRenderer fontRenderer, IAEItemStack aeStack, It
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();
Expand All @@ -71,10 +70,9 @@ public void renderStackSize( FontRenderer fontRenderer, IAEItemStack aeStack, It
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();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/appeng/client/render/effects/AssemblerFX.java
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -45,7 +46,9 @@ public AssemblerFX( final World w, final double x, final double y, final double
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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/appeng/container/AEBaseContainer.java
Expand Up @@ -225,10 +225,11 @@ public void setTargetStack( final IAEItemStack stack )
// 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;
}
Expand Down
Expand Up @@ -142,7 +142,7 @@ public void serverPacketData( final INetworkInfo manager, final AppEngPacket pac
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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/util/ItemSorters.java
Expand Up @@ -80,9 +80,9 @@ public int compare( final IAEItemStack o1, final IAEItemStack o2 )
{
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;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/appeng/util/item/AEFluidStack.java
Expand Up @@ -60,7 +60,6 @@ private AEFluidStack( final AEFluidStack is )
// priority = is.priority;
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.setShowCraftingLabel( is.getShowCraftingLabel() );

this.myHash = is.myHash;
}
Expand Down Expand Up @@ -163,7 +162,6 @@ public static IAEFluidStack loadFluidStackFromPacket( final ByteBuf data ) throw
final AEFluidStack fluid = AEFluidStack.create( fluidStack );
// fluid.priority = (int) priority;
fluid.setStackSize( stackSize );
fluid.setShowCraftingLabel( showCraftingLabel );
fluid.setCountRequestable( countRequestable );
fluid.setCraftable( isCraftable );
return fluid;
Expand All @@ -183,7 +181,6 @@ public void add( final IAEFluidStack option )
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
this.setShowCraftingLabel( this.getShowCraftingLabel() || option.getShowCraftingLabel() );
}

@Override
Expand Down
23 changes: 9 additions & 14 deletions src/main/java/appeng/util/item/AEItemStack.java
Expand Up @@ -58,7 +58,6 @@ private AEItemStack( final AEItemStack is )
this.setStackSize( is.getStackSize() );
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.setShowCraftingLabel( is.getShowCraftingLabel() );
}

private AEItemStack( final ItemStack is )
Expand Down Expand Up @@ -158,7 +157,6 @@ public static IAEItemStack loadItemStackFromPacket( final ByteBuf data ) throws
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();
Expand Down Expand Up @@ -186,20 +184,14 @@ public static IAEItemStack loadItemStackFromPacket( final ByteBuf data ) throws

final ItemStack itemstack = new ItemStack( d );

if( !showCraftingLabel )
{
showCraftingLabel = stackSize == 0 && isCraftable;
}

if( itemstack.isEmpty() )
{
return null;
}

final AEItemStack item = AEItemStack.create( itemstack );
// item.priority = (int) priority;
item.setStackSize( showCraftingLabel ? 1 : stackSize );
item.setShowCraftingLabel( showCraftingLabel );
item.setStackSize( stackSize );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR A "NullPointerException" could be thrown; "item" is nullable here. rule

item.setCountRequestable( countRequestable );
item.setCraftable( isCraftable );
return item;
Expand All @@ -219,7 +211,6 @@ public void add( final IAEItemStack option )
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
this.setShowCraftingLabel( this.getShowCraftingLabel() || option.getShowCraftingLabel() );
}

@Override
Expand Down Expand Up @@ -597,20 +588,24 @@ private int compare( final int l, final int m )
@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 )
public String getDisplayName()
{
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();
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/appeng/util/item/AEStack.java
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -104,22 +103,9 @@ public StackType reset()
// 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()
{
Expand Down Expand Up @@ -157,7 +143,6 @@ public void writeToPacket( final ByteBuf i ) throws IOException
.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 );

Expand Down