Merge pull request #1127 from thatsIch/b-1118-api-crash

Fixes #1118 Does not crash with invalid ItemStacks anymore
This commit is contained in:
thatsIch
2015-03-30 11:54:28 +02:00
10 changed files with 1077 additions and 1068 deletions
+49 -37
View File
@@ -22,9 +22,7 @@ package appeng.block;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
@@ -56,6 +54,9 @@ import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import appeng.api.implementations.items.IMemoryCard; import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages; import appeng.api.implementations.items.MemoryCardMessages;
import appeng.api.implementations.tiles.IColorableTile; import appeng.api.implementations.tiles.IColorableTile;
@@ -97,6 +98,8 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
@SideOnly( Side.CLIENT ) @SideOnly( Side.CLIENT )
BlockRenderInfo renderInfo; BlockRenderInfo renderInfo;
private IFeatureHandler handler; private IFeatureHandler handler;
@Nullable
private Class<? extends TileEntity> tileEntityType = null; private Class<? extends TileEntity> tileEntityType = null;
protected AEBaseBlock( Class<? extends AEBaseBlock> c, Material mat ) protected AEBaseBlock( Class<? extends AEBaseBlock> c, Material mat )
@@ -126,6 +129,12 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
this.featureSubName = subName; this.featureSubName = subName;
} }
// update Block value.
private void setTileProvider( boolean b )
{
ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" );
}
@Override @Override
public String toString() public String toString()
{ {
@@ -139,6 +148,28 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
info.updateIcons( i, i, i, i, i, i ); info.updateIcons( i, i, i, i, i, i );
} }
@SideOnly( Side.CLIENT )
public BlockRenderInfo getRendererInstance()
{
if( this.renderInfo != null )
return this.renderInfo;
try
{
return this.renderInfo = new BlockRenderInfo( this.getRenderer().newInstance() );
}
catch( Throwable t )
{
throw new RuntimeException( t );
}
}
@SideOnly( Side.CLIENT )
protected Class<? extends BaseBlockRender> getRenderer()
{
return BaseBlockRender.class;
}
public IIcon unmappedGetIcon( IBlockAccess w, int x, int y, int z, int s ) public IIcon unmappedGetIcon( IBlockAccess w, int x, int y, int z, int s )
{ {
return super.getIcon( w, x, y, z, s ); return super.getIcon( w, x, y, z, s );
@@ -146,16 +177,17 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
protected void setTileEntity( Class<? extends TileEntity> c ) protected void setTileEntity( Class<? extends TileEntity> c )
{ {
this.tileEntityType = c;
AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) ); AEBaseTile.registerTileItem( c, new ItemStackSrc( this, 0 ) );
GameRegistry.registerTileEntity( this.tileEntityType = c, this.featureFullName ); GameRegistry.registerTileEntity( this.tileEntityType, this.featureFullName );
this.isInventory = IInventory.class.isAssignableFrom( c ); this.isInventory = IInventory.class.isAssignableFrom( c );
this.setTileProvider( this.hasBlockTileEntity() ); this.setTileProvider( this.hasBlockTileEntity() );
} }
// update Block value. public boolean hasBlockTileEntity()
private void setTileProvider( boolean b )
{ {
ReflectionHelper.setPrivateValue( Block.class, this, b, "isTileProvider" ); return this.tileEntityType != null;
} }
protected void setFeature( EnumSet<AEFeature> f ) protected void setFeature( EnumSet<AEFeature> f )
@@ -634,22 +666,6 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return super.recolourBlock( world, x, y, z, side, colour ); return super.recolourBlock( world, x, y, z, side, colour );
} }
@SideOnly( Side.CLIENT )
public BlockRenderInfo getRendererInstance()
{
if ( this.renderInfo != null )
return this.renderInfo;
try
{
return this.renderInfo = new BlockRenderInfo( this.getRenderer().newInstance() );
}
catch ( Throwable t )
{
throw new RuntimeException( t );
}
}
@SideOnly( Side.CLIENT ) @SideOnly( Side.CLIENT )
private FlippableIcon optionalIcon( IIconRegister ir, String Name, IIcon substitute ) private FlippableIcon optionalIcon( IIconRegister ir, String Name, IIcon substitute )
{ {
@@ -662,8 +678,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
try try
{ {
ResourceLocation resLoc = new ResourceLocation( Name ); ResourceLocation resLoc = new ResourceLocation( Name );
resLoc = new ResourceLocation( resLoc.getResourceDomain(), String.format( "%s/%s%s", "textures/blocks", resLoc = new ResourceLocation( resLoc.getResourceDomain(), String.format( "%s/%s%s", "textures/blocks", resLoc.getResourcePath(), ".png" ) );
resLoc.getResourcePath(), ".png" ) );
IResource res = Minecraft.getMinecraft().getResourceManager().getResource( resLoc ); IResource res = Minecraft.getMinecraft().getResourceManager().getResource( resLoc );
if( res != null ) if( res != null )
@@ -678,12 +693,6 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return new FlippableIcon( ir.registerIcon( Name ) ); return new FlippableIcon( ir.registerIcon( Name ) );
} }
@SideOnly( Side.CLIENT )
protected Class<? extends BaseBlockRender> getRenderer()
{
return BaseBlockRender.class;
}
@SideOnly( Side.CLIENT ) @SideOnly( Side.CLIENT )
public void getCheckedSubBlocks( Item item, CreativeTabs tabs, List<ItemStack> itemStacks ) public void getCheckedSubBlocks( Item item, CreativeTabs tabs, List<ItemStack> itemStacks )
{ {
@@ -711,11 +720,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
return s; return s;
} }
public boolean hasBlockTileEntity() @Nullable
{
return this.tileEntityType != null;
}
public <T extends TileEntity> T getTileEntity( IBlockAccess w, int x, int y, int z ) public <T extends TileEntity> T getTileEntity( IBlockAccess w, int x, int y, int z )
{ {
if( !this.hasBlockTileEntity() ) if( !this.hasBlockTileEntity() )
@@ -790,11 +795,18 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
{ {
return this.tileEntityType.newInstance(); return this.tileEntityType.newInstance();
} }
catch ( Throwable e ) catch( InstantiationException e )
{ {
e.printStackTrace();
throw new RuntimeException( e );
}
catch( IllegalAccessException e )
{
e.printStackTrace();
throw new RuntimeException( e ); throw new RuntimeException( e );
} }
} }
return null; return null;
} }
+300 -312
View File
@@ -30,9 +30,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.google.common.base.Joiner;
import com.google.common.base.Stopwatch;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@@ -52,6 +49,9 @@ import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.common.ObfuscationReflectionHelper;
import com.google.common.base.Joiner;
import com.google.common.base.Stopwatch;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.ITooltip; import appeng.client.gui.widgets.ITooltip;
@@ -81,12 +81,20 @@ import appeng.integration.IntegrationType;
import appeng.integration.abstraction.INEI; import appeng.integration.abstraction.INEI;
import appeng.util.Platform; import appeng.util.Platform;
public abstract class AEBaseGui extends GuiContainer public abstract class AEBaseGui extends GuiContainer
{ {
public static boolean switchingGuis;
protected final List<InternalSlotME> meSlots = new LinkedList<InternalSlotME>(); protected final List<InternalSlotME> meSlots = new LinkedList<InternalSlotME>();
// drag y
final Set<Slot> drag_click = new HashSet<Slot>();
final AppEngRenderItem aeRenderItem = new AppEngRenderItem();
protected GuiScrollbar myScrollBar = null; protected GuiScrollbar myScrollBar = null;
static public boolean switchingGuis; boolean disableShiftClick = false;
Stopwatch dbl_clickTimer = Stopwatch.createStarted();
ItemStack dbl_whichItem;
Slot bl_clicked;
boolean useNEI = false;
private boolean subGui; private boolean subGui;
public AEBaseGui( Container container ) public AEBaseGui( Container container )
@@ -96,6 +104,13 @@ public abstract class AEBaseGui extends GuiContainer
switchingGuis = false; switchingGuis = false;
} }
protected static String join( Collection<String> toolTip, String delimiter )
{
final Joiner joiner = Joiner.on( delimiter );
return joiner.join( toolTip );
}
protected int getQty( GuiButton btn ) protected int getQty( GuiButton btn )
{ {
try try
@@ -136,47 +151,171 @@ public abstract class AEBaseGui extends GuiContainer
} }
@Override @Override
public void handleMouseInput() public void drawScreen( int mouse_x, int mouse_y, float btn )
{ {
super.handleMouseInput(); super.drawScreen( mouse_x, mouse_y, btn );
int i = Mouse.getEventDWheel(); boolean hasClicked = Mouse.isButtonDown( 0 );
if ( i != 0 && isShiftKeyDown() ) if( hasClicked && this.myScrollBar != null )
this.myScrollBar.click( this, mouse_x - this.guiLeft, mouse_y - this.guiTop );
for( Object c : this.buttonList )
{ {
int x = Mouse.getEventX() * this.width / this.mc.displayWidth; if( c instanceof ITooltip )
int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; {
this.mouseWheelEvent( x, y, i / Math.abs( i ) ); ITooltip tooltip = (ITooltip) c;
int x = tooltip.xPos(); // ((GuiImgButton) c).xPosition;
int y = tooltip.yPos(); // ((GuiImgButton) c).yPosition;
if( x < mouse_x && x + tooltip.getWidth() > mouse_x && tooltip.isVisible() )
{
if( y < mouse_y && y + tooltip.getHeight() > mouse_y )
{
if( y < 15 )
y = 15;
String msg = tooltip.getMessage();
if( msg != null )
this.drawTooltip( x + 11, y + 4, 0, msg );
}
}
}
} }
else if ( i != 0 && this.myScrollBar != null )
this.myScrollBar.wheel( i );
} }
protected void mouseWheelEvent(int x, int y, int wheel) public void drawTooltip( int par2, int par3, int forceWidth, String Msg )
{ {
Slot slot = this.getSlot( x, y ); GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
if ( slot instanceof SlotME ) GL11.glDisable( GL12.GL_RESCALE_NORMAL );
RenderHelper.disableStandardItemLighting();
GL11.glDisable( GL11.GL_LIGHTING );
GL11.glDisable( GL11.GL_DEPTH_TEST );
String[] var4 = Msg.split( "\n" );
if( var4.length > 0 )
{ {
IAEItemStack item = ((SlotME) slot).getAEStack(); int var5 = 0;
if ( item != null ) int var6;
int var7;
for( var6 = 0; var6 < var4.length; ++var6 )
{ {
((AEBaseContainer) this.inventorySlots).setTargetStack( item ); var7 = this.fontRendererObj.getStringWidth( var4[var6] );
InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP;
int times = Math.abs( wheel ); if( var7 > var5 )
final int inventorySize = this.getInventorySlots().size();
for (int h = 0; h < times; h++)
{ {
PacketInventoryAction p = new PacketInventoryAction( direction, inventorySize, 0 ); var5 = var7;
NetworkHandler.instance.sendToServer( p );
} }
} }
var6 = par2 + 12;
var7 = par3 - 12;
int var9 = 8;
if( var4.length > 1 )
{
var9 += 2 + ( var4.length - 1 ) * 10;
} }
if( this.guiTop + var7 + var9 + 6 > this.height )
{
var7 = this.height - var9 - this.guiTop - 6;
}
if( forceWidth > 0 )
var5 = forceWidth;
this.zLevel = 300.0F;
itemRender.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect( var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10 );
this.drawGradientRect( var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10 );
this.drawGradientRect( var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10 );
this.drawGradientRect( var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10 );
this.drawGradientRect( var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10 );
int var11 = 1347420415;
int var12 = ( var11 & 16711422 ) >> 1 | var11 & -16777216;
this.drawGradientRect( var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12 );
this.drawGradientRect( var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12 );
this.drawGradientRect( var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11 );
this.drawGradientRect( var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12 );
for( int var13 = 0; var13 < var4.length; ++var13 )
{
String var14 = var4[var13];
if( var13 == 0 )
{
var14 = '\u00a7' + Integer.toHexString( 15 ) + var14;
}
else
{
var14 = "\u00a77" + var14;
}
this.fontRendererObj.drawStringWithShadow( var14, var6, var7, -1 );
if( var13 == 0 )
{
var7 += 2;
}
var7 += 10;
}
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
}
GL11.glPopAttrib();
} }
@Override @Override
public void onGuiClosed() final protected void drawGuiContainerForegroundLayer( int x, int y )
{ {
super.onGuiClosed(); int ox = this.guiLeft; // (width - xSize) / 2;
this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI ) int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
if( this.myScrollBar != null )
this.myScrollBar.draw( this );
this.drawFG( ox, oy, x, y );
}
public abstract void drawFG( int offsetX, int offsetY, int mouseX, int mouseY );
@Override
final protected void drawGuiContainerBackgroundLayer( float f, int x, int y )
{
int ox = this.guiLeft; // (width - xSize) / 2;
int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
this.drawBG( ox, oy, x, y );
final List<Slot> slots = this.getInventorySlots();
for( Slot slot : slots )
{
if( slot instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) slot;
if( fs.renderDisabled() )
{
if( fs.isEnabled() )
{
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 );
}
else
{
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 0.4F );
GL11.glEnable( GL11.GL_BLEND );
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
GL11.glPopAttrib();
}
}
}
}
} }
@Override @Override
@@ -200,13 +339,27 @@ public abstract class AEBaseGui extends GuiContainer
super.mouseClicked( xCoord, yCoord, btn ); super.mouseClicked( xCoord, yCoord, btn );
} }
boolean disableShiftClick = false; @Override
Stopwatch dbl_clickTimer = Stopwatch.createStarted(); protected void mouseClickMove( int x, int y, int c, long d )
ItemStack dbl_whichItem; {
Slot bl_clicked; Slot slot = this.getSlot( x, y );
ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
// drag y if( slot instanceof SlotFake && itemstack != null )
final Set<Slot> drag_click = new HashSet<Slot>(); {
this.drag_click.add( slot );
if( this.drag_click.size() > 1 )
{
for( Slot dr : this.drag_click )
{
PacketInventoryAction p = new PacketInventoryAction( c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE, dr.slotNumber, 0 );
NetworkHandler.instance.sendToServer( p );
}
}
}
else
super.mouseClickMove( x, y, c, d );
}
@Override @Override
protected void handleMouseClick( Slot slot, int slotIdx, int ctrlDown, int key ) protected void handleMouseClick( Slot slot, int slotIdx, int ctrlDown, int key )
@@ -385,8 +538,7 @@ public abstract class AEBaseGui extends GuiContainer
final List<Slot> slots = this.getInventorySlots(); final List<Slot> slots = this.getInventorySlots();
for( Slot inventorySlot : slots ) for( Slot inventorySlot : slots )
{ {
if ( inventorySlot != null && inventorySlot.canTakeStack( this.mc.thePlayer ) && inventorySlot.getHasStack() if( inventorySlot != null && inventorySlot.canTakeStack( this.mc.thePlayer ) && inventorySlot.getHasStack() && inventorySlot.inventory == slot.inventory && Container.func_94527_a( inventorySlot, this.dbl_whichItem, true ) )
&& inventorySlot.inventory == slot.inventory && Container.func_94527_a( inventorySlot, this.dbl_whichItem, true ) )
{ {
this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, ctrlDown, 1 ); this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, ctrlDown, 1 );
} }
@@ -399,34 +551,6 @@ public abstract class AEBaseGui extends GuiContainer
super.handleMouseClick( slot, slotIdx, ctrlDown, key ); super.handleMouseClick( slot, slotIdx, ctrlDown, key );
} }
@Override
protected void mouseClickMove(int x, int y, int c, long d)
{
Slot slot = this.getSlot( x, y );
ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack();
if ( slot instanceof SlotFake && itemstack != null )
{
this.drag_click.add( slot );
if ( this.drag_click.size() > 1 )
{
for (Slot dr : this.drag_click)
{
PacketInventoryAction p = new PacketInventoryAction( c == 0 ? InventoryAction.PICKUP_OR_SET_DOWN : InventoryAction.PLACE_SINGLE,
dr.slotNumber, 0 );
NetworkHandler.instance.sendToServer( p );
}
}
}
else
super.mouseClickMove( x, y, c, d );
}
protected boolean enableSpaceClicking()
{
return true;
}
@Override @Override
protected boolean checkHotbarKeys( int p_146983_1_ ) protected boolean checkHotbarKeys( int p_146983_1_ )
{ {
@@ -483,127 +607,70 @@ public abstract class AEBaseGui extends GuiContainer
} }
@Override @Override
public void drawScreen(int mouse_x, int mouse_y, float btn) public void onGuiClosed()
{ {
super.drawScreen( mouse_x, mouse_y, btn ); super.onGuiClosed();
this.subGui = true; // in case the gui is reopened later ( i'm looking at you NEI )
boolean hasClicked = Mouse.isButtonDown( 0 );
if ( hasClicked && this.myScrollBar != null )
this.myScrollBar.click( this, mouse_x - this.guiLeft, mouse_y - this.guiTop );
for (Object c : this.buttonList)
{
if ( c instanceof ITooltip )
{
ITooltip tooltip = (ITooltip) c;
int x = tooltip.xPos(); // ((GuiImgButton) c).xPosition;
int y = tooltip.yPos(); // ((GuiImgButton) c).yPosition;
if ( x < mouse_x && x + tooltip.getWidth() > mouse_x && tooltip.isVisible() )
{
if ( y < mouse_y && y + tooltip.getHeight() > mouse_y )
{
if ( y < 15 )
y = 15;
String msg = tooltip.getMessage();
if ( msg != null )
this.drawTooltip( x + 11, y + 4, 0, msg );
}
}
}
}
}
public void drawTooltip(int par2, int par3, int forceWidth, String Msg)
{
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
RenderHelper.disableStandardItemLighting();
GL11.glDisable( GL11.GL_LIGHTING );
GL11.glDisable( GL11.GL_DEPTH_TEST );
String[] var4 = Msg.split( "\n" );
if ( var4.length > 0 )
{
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < var4.length; ++var6)
{
var7 = this.fontRendererObj.getStringWidth( var4[var6] );
if ( var7 > var5 )
{
var5 = var7;
}
}
var6 = par2 + 12;
var7 = par3 - 12;
int var9 = 8;
if ( var4.length > 1 )
{
var9 += 2 + (var4.length - 1) * 10;
}
if ( this.guiTop + var7 + var9 + 6 > this.height )
{
var7 = this.height - var9 - this.guiTop - 6;
}
if ( forceWidth > 0 )
var5 = forceWidth;
this.zLevel = 300.0F;
itemRender.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect( var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10 );
this.drawGradientRect( var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10 );
this.drawGradientRect( var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10 );
this.drawGradientRect( var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10 );
this.drawGradientRect( var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10 );
int var11 = 1347420415;
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect( var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12 );
this.drawGradientRect( var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12 );
this.drawGradientRect( var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11 );
this.drawGradientRect( var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12 );
for (int var13 = 0; var13 < var4.length; ++var13)
{
String var14 = var4[var13];
if ( var13 == 0 )
{
var14 = '\u00a7' + Integer.toHexString( 15 ) + var14;
}
else
{
var14 = "\u00a77" + var14;
}
this.fontRendererObj.drawStringWithShadow( var14, var6, var7, -1 );
if ( var13 == 0 )
{
var7 += 2;
}
var7 += 10;
}
this.zLevel = 0.0F;
itemRender.zLevel = 0.0F;
}
GL11.glPopAttrib();
} }
public abstract void drawBG( int offsetX, int offsetY, int mouseX, int mouseY ); public abstract void drawBG( int offsetX, int offsetY, int mouseX, int mouseY );
public abstract void drawFG(int offsetX, int offsetY, int mouseX, int mouseY); @Override
public void handleMouseInput()
{
super.handleMouseInput();
int i = Mouse.getEventDWheel();
if( i != 0 && isShiftKeyDown() )
{
int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
this.mouseWheelEvent( x, y, i / Math.abs( i ) );
}
else if( i != 0 && this.myScrollBar != null )
this.myScrollBar.wheel( i );
}
protected void mouseWheelEvent( int x, int y, int wheel )
{
Slot slot = this.getSlot( x, y );
if( slot instanceof SlotME )
{
IAEItemStack item = ( (SlotME) slot ).getAEStack();
if( item != null )
{
( (AEBaseContainer) this.inventorySlots ).setTargetStack( item );
InventoryAction direction = wheel > 0 ? InventoryAction.ROLL_DOWN : InventoryAction.ROLL_UP;
int times = Math.abs( wheel );
final int inventorySize = this.getInventorySlots().size();
for( int h = 0; h < times; h++ )
{
PacketInventoryAction p = new PacketInventoryAction( direction, inventorySize, 0 );
NetworkHandler.instance.sendToServer( p );
}
}
}
}
protected Slot getSlot( int mouseX, int mouseY )
{
final List<Slot> slots = this.getInventorySlots();
for( Slot slot : slots )
{
// isPointInRegion
if( this.func_146978_c( slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY ) )
{
return slot;
}
}
return null;
}
protected boolean enableSpaceClicking()
{
return true;
}
public void bindTexture( String base, String file ) public void bindTexture( String base, String file )
{ {
@@ -611,12 +678,6 @@ public abstract class AEBaseGui extends GuiContainer
this.mc.getTextureManager().bindTexture( loc ); this.mc.getTextureManager().bindTexture( loc );
} }
public void bindTexture(String file)
{
ResourceLocation loc = new ResourceLocation( "appliedenergistics2", "textures/" + file );
this.mc.getTextureManager().bindTexture( loc );
}
protected void drawItem( int x, int y, ItemStack is ) protected void drawItem( int x, int y, ItemStack is )
{ {
this.zLevel = 100.0F; this.zLevel = 100.0F;
@@ -634,63 +695,11 @@ public abstract class AEBaseGui extends GuiContainer
this.zLevel = 0.0F; this.zLevel = 0.0F;
} }
@Override
final protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
int ox = this.guiLeft; // (width - xSize) / 2;
int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
this.drawBG( ox, oy, x, y );
final List<Slot> slots = this.getInventorySlots();
for (Slot slot : slots)
{
if ( slot instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) slot;
if ( fs.renderDisabled() )
{
if ( fs.isEnabled() )
{
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 );
}
else
{
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 0.4F );
GL11.glEnable( GL11.GL_BLEND );
this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 );
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
GL11.glPopAttrib();
}
}
}
}
}
@Override
final protected void drawGuiContainerForegroundLayer(int x, int y)
{
int ox = this.guiLeft; // (width - xSize) / 2;
int oy = this.guiTop; // (height - ySize) / 2;
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
if ( this.myScrollBar != null )
this.myScrollBar.draw( this );
this.drawFG( ox, oy, x, y );
}
protected String getGuiDisplayName( String in ) protected String getGuiDisplayName( String in )
{ {
return this.hasCustomInventoryName() ? this.getInventoryName() : in; return this.hasCustomInventoryName() ? this.getInventoryName() : in;
} }
private String getInventoryName()
{
return ((AEBaseContainer) this.inventorySlots).customName;
}
private boolean hasCustomInventoryName() private boolean hasCustomInventoryName()
{ {
if( this.inventorySlots instanceof AEBaseContainer ) if( this.inventorySlots instanceof AEBaseContainer )
@@ -698,65 +707,9 @@ public abstract class AEBaseGui extends GuiContainer
return false; return false;
} }
protected Slot getSlot(int mouseX, int mouseY) private String getInventoryName()
{ {
final List<Slot> slots = this.getInventorySlots(); return ( (AEBaseContainer) this.inventorySlots ).customName;
for (Slot slot : slots)
{
// isPointInRegion
if ( this.func_146978_c( slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX, mouseY ) )
{
return slot;
}
}
return null;
}
protected static String join(Collection<String> toolTip, String delimiter)
{
final Joiner joiner = Joiner.on( delimiter );
return joiner.join( toolTip );
}
boolean useNEI = false;
private RenderItem setItemRender(RenderItem item)
{
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.NEI ) )
{
return ((INEI) AppEng.instance.getIntegration( IntegrationType.NEI )).setItemRender( item );
}
else
{
RenderItem ri = itemRender;
itemRender = item;
return ri;
}
}
private void safeDrawSlot(Slot s)
{
try
{
// drawSlotInventory
// super.func_146977_a( s );r
GuiContainer.class.getDeclaredMethod( "func_146977_a_original", Slot.class ).invoke( this, s );
}
catch (Exception err)
{
Tessellator tessellator = Tessellator.instance;
if ( Platform.isDrawing( tessellator ) )
tessellator.draw();
}
}
final AppEngRenderItem aeRenderItem = new AppEngRenderItem();
protected boolean isPowered()
{
return true;
} }
public void a( Slot s ) public void a( Slot s )
@@ -764,11 +717,6 @@ public abstract class AEBaseGui extends GuiContainer
this.drawSlot( s ); this.drawSlot( s );
} }
public void func_146977_a(Slot s)
{
this.drawSlot( s );
}
public void drawSlot( Slot s ) public void drawSlot( Slot s )
{ {
if( s instanceof SlotME ) if( s instanceof SlotME )
@@ -837,14 +785,10 @@ public abstract class AEBaseGui extends GuiContainer
float f1 = 0.00390625F; float f1 = 0.00390625F;
tessellator.startDrawingQuads(); tessellator.startDrawingQuads();
tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() ); tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, aes.getOpacityOfIcon() );
tessellator.addVertexWithUV( par1 + 0, par2 + par6, this.zLevel, (par3 + 0) * f, tessellator.addVertexWithUV( par1 + 0, par2 + par6, this.zLevel, ( par3 + 0 ) * f, ( par4 + par6 ) * f1 );
(par4 + par6) * f1 ); tessellator.addVertexWithUV( par1 + par5, par2 + par6, this.zLevel, ( par3 + par5 ) * f, ( par4 + par6 ) * f1 );
tessellator.addVertexWithUV( par1 + par5, par2 + par6, this.zLevel, tessellator.addVertexWithUV( par1 + par5, par2 + 0, this.zLevel, ( par3 + par5 ) * f, ( par4 + 0 ) * f1 );
(par3 + par5) * f, (par4 + par6) * f1 ); tessellator.addVertexWithUV( par1 + 0, par2 + 0, this.zLevel, ( par3 + 0 ) * f, ( par4 + 0 ) * f1 );
tessellator.addVertexWithUV( par1 + par5, par2 + 0, this.zLevel,
(par3 + par5) * f, (par4 + 0) * f1 );
tessellator.addVertexWithUV( par1 + 0, par2 + 0, this.zLevel, (par3 + 0) * f,
(par4 + 0) * f1 );
tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, 1.0f ); tessellator.setColorRGBA_F( 1.0f, 1.0f, 1.0f, 1.0f );
tessellator.draw(); tessellator.draw();
} }
@@ -861,8 +805,7 @@ public abstract class AEBaseGui extends GuiContainer
{ {
if( ( (AppEngSlot) s ).isValid == hasCalculatedValidness.NotAvailable ) if( ( (AppEngSlot) s ).isValid == hasCalculatedValidness.NotAvailable )
{ {
boolean isValid = s.isItemValid( is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled boolean isValid = s.isItemValid( is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled || s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
|| s instanceof SlotInaccessible || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
if( isValid && s instanceof SlotRestrictedInput ) if( isValid && s instanceof SlotRestrictedInput )
{ {
try try
@@ -910,4 +853,49 @@ public abstract class AEBaseGui extends GuiContainer
this.safeDrawSlot( s ); this.safeDrawSlot( s );
} }
private RenderItem setItemRender( RenderItem item )
{
if( AppEng.instance.isIntegrationEnabled( IntegrationType.NEI ) )
{
return ( (INEI) AppEng.instance.getIntegration( IntegrationType.NEI ) ).setItemRender( item );
}
else
{
RenderItem ri = itemRender;
itemRender = item;
return ri;
}
}
protected boolean isPowered()
{
return true;
}
private void safeDrawSlot( Slot s )
{
try
{
// drawSlotInventory
// super.func_146977_a( s );r
GuiContainer.class.getDeclaredMethod( "func_146977_a_original", Slot.class ).invoke( this, s );
}
catch( Exception err )
{
Tessellator tessellator = Tessellator.instance;
if( Platform.isDrawing( tessellator ) )
tessellator.draw();
}
}
public void bindTexture( String file )
{
ResourceLocation loc = new ResourceLocation( "appliedenergistics2", "textures/" + file );
this.mc.getTextureManager().bindTexture( loc );
}
public void func_146977_a( Slot s )
{
this.drawSlot( s );
}
} }
@@ -57,8 +57,8 @@ public class AppEngRenderItem extends RenderItem
{ {
if ( is != null ) if ( is != null )
{ {
float ScaleFactor = AEConfig.instance.useTerminalUseLargeFont() ? 0.85f : 0.5f; float scaleFactor = AEConfig.instance.useTerminalUseLargeFont() ? 0.85f : 0.5f;
float RScaleFactor = 1.0f / ScaleFactor; float inverseScaleFactor = 1.0f / scaleFactor;
int offset = AEConfig.instance.useTerminalUseLargeFont() ? 0 : -1; int offset = AEConfig.instance.useTerminalUseLargeFont() ? 0 : -1;
boolean unicodeFlag = par1FontRenderer.getUnicodeFlag(); boolean unicodeFlag = par1FontRenderer.getUnicodeFlag();
@@ -93,9 +93,9 @@ public class AppEngRenderItem extends RenderItem
GL11.glDisable( GL11.GL_LIGHTING ); GL11.glDisable( GL11.GL_LIGHTING );
GL11.glDisable( GL11.GL_DEPTH_TEST ); GL11.glDisable( GL11.GL_DEPTH_TEST );
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glScaled( ScaleFactor, ScaleFactor, ScaleFactor ); GL11.glScaled( scaleFactor, scaleFactor, scaleFactor );
int X = (int) (((float) par4 + offset + 16.0f - par1FontRenderer.getStringWidth( var6 ) * ScaleFactor) * RScaleFactor); int X = (int) (((float) par4 + offset + 16.0f - par1FontRenderer.getStringWidth( var6 ) * scaleFactor) * inverseScaleFactor);
int Y = (int) (((float) par5 + offset + 16.0f - 7.0f * ScaleFactor) * RScaleFactor); int Y = (int) (((float) par5 + offset + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor);
par1FontRenderer.drawStringWithShadow( var6, X, Y, 16777215 ); par1FontRenderer.drawStringWithShadow( var6, X, Y, 16777215 );
GL11.glPopMatrix(); GL11.glPopMatrix();
GL11.glEnable( GL11.GL_LIGHTING ); GL11.glEnable( GL11.GL_LIGHTING );
@@ -103,8 +103,7 @@ public class AppEngRenderItem extends RenderItem
} }
long amount = this.aeStack != null ? this.aeStack.getStackSize() : is.stackSize; long amount = this.aeStack != null ? this.aeStack.getStackSize() : is.stackSize;
if ( amount > 999999999999L ) amount = Math.max( amount, 999999999999L );
amount = 999999999999L;
if ( amount != 0 ) if ( amount != 0 )
{ {
@@ -156,9 +155,9 @@ public class AppEngRenderItem extends RenderItem
GL11.glDisable( GL11.GL_LIGHTING ); GL11.glDisable( GL11.GL_LIGHTING );
GL11.glDisable( GL11.GL_DEPTH_TEST ); GL11.glDisable( GL11.GL_DEPTH_TEST );
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glScaled( ScaleFactor, ScaleFactor, ScaleFactor ); GL11.glScaled( scaleFactor, scaleFactor, scaleFactor );
int X = (int) (((float) par4 + offset + 16.0f - par1FontRenderer.getStringWidth( var6 ) * ScaleFactor) * RScaleFactor); int X = (int) (((float) par4 + offset + 16.0f - par1FontRenderer.getStringWidth( var6 ) * scaleFactor) * inverseScaleFactor);
int Y = (int) (((float) par5 + offset + 16.0f - 7.0f * ScaleFactor) * RScaleFactor); int Y = (int) (((float) par5 + offset + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor);
par1FontRenderer.drawStringWithShadow( var6, X, Y, 16777215 ); par1FontRenderer.drawStringWithShadow( var6, X, Y, 16777215 );
GL11.glPopMatrix(); GL11.glPopMatrix();
GL11.glEnable( GL11.GL_LIGHTING ); GL11.glEnable( GL11.GL_LIGHTING );
@@ -22,6 +22,8 @@ package appeng.client.render;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.EnumSet; import java.util.EnumSet;
import javax.annotation.Nullable;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@@ -432,6 +434,7 @@ public class BaseBlockRender
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0; renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
} }
@Nullable
public IOrientable getOrientable( AEBaseBlock block, IBlockAccess w, int x, int y, int z ) public IOrientable getOrientable( AEBaseBlock block, IBlockAccess w, int x, int y, int z )
{ {
if ( block.hasBlockTileEntity() ) if ( block.hasBlockTileEntity() )
@@ -102,6 +102,7 @@ public class RenderBlockInscriber extends BaseBlockRender
BlockInscriber blk = (BlockInscriber) block; BlockInscriber blk = (BlockInscriber) block;
IOrientable te = this.getOrientable( block, world, x, y, z ); IOrientable te = this.getOrientable( block, world, x, y, z );
if ( te == null ) return false;
ForgeDirection fdy = te.getUp(); ForgeDirection fdy = te.getUp();
ForgeDirection fdz = te.getForward(); ForgeDirection fdz = te.getForward();
@@ -40,10 +40,9 @@ public class RenderBlockInterface extends BaseBlockRender
public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer) public boolean renderInWorld(AEBaseBlock block, IBlockAccess world, int x, int y, int z, RenderBlocks renderer)
{ {
TileInterface ti = block.getTileEntity( world, x, y, z ); TileInterface ti = block.getTileEntity( world, x, y, z );
BlockRenderInfo info = block.getRendererInstance(); BlockRenderInfo info = block.getRendererInstance();
if ( ti.getForward() != ForgeDirection.UNKNOWN ) if ( ti != null && ti.getForward() != ForgeDirection.UNKNOWN )
{ {
IIcon side = ExtraBlockTextures.BlockInterfaceAlternateArrow.getIcon(); IIcon side = ExtraBlockTextures.BlockInterfaceAlternateArrow.getIcon();
info.setTemporaryRenderIcons( ExtraBlockTextures.BlockInterfaceAlternate.getIcon(), block.getIcon( 0, 0 ), side, side, side, side ); info.setTemporaryRenderIcons( ExtraBlockTextures.BlockInterfaceAlternate.getIcon(), block.getIcon( 0, 0 ), side, side, side, side );
@@ -67,6 +67,8 @@ public class RenderMEChest extends BaseBlockRender
TileChest sp = imb.getTileEntity( world, x, y, z ); TileChest sp = imb.getTileEntity( world, x, y, z );
renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 ); renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 );
if ( sp == null ) return false;
ForgeDirection up = sp.getUp(); ForgeDirection up = sp.getUp();
ForgeDirection forward = sp.getForward(); ForgeDirection forward = sp.getForward();
ForgeDirection west = Platform.crossProduct( forward, up ); ForgeDirection west = Platform.crossProduct( forward, up );
@@ -18,6 +18,7 @@
package appeng.client.render.blocks; package appeng.client.render.blocks;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -32,10 +33,12 @@ import appeng.client.render.BlockRenderInfo;
import appeng.client.texture.ExtraBlockTextures; import appeng.client.texture.ExtraBlockTextures;
import appeng.tile.spatial.TileSpatialPylon; import appeng.tile.spatial.TileSpatialPylon;
public class RenderSpatialPylon extends BaseBlockRender public class RenderSpatialPylon extends BaseBlockRender
{ {
public RenderSpatialPylon() { public RenderSpatialPylon()
{
super( false, 0 ); super( false, 0 );
} }
@@ -55,7 +58,7 @@ public class RenderSpatialPylon extends BaseBlockRender
TileSpatialPylon sp = imb.getTileEntity( world, x, y, z ); TileSpatialPylon sp = imb.getTileEntity( world, x, y, z );
int displayBits = sp.getDisplayBits(); int displayBits = ( sp == null ) ? 0 : sp.getDisplayBits();
ForgeDirection ori = ForgeDirection.UNKNOWN; ForgeDirection ori = ForgeDirection.UNKNOWN;
if( displayBits != 0 ) if( displayBits != 0 )
@@ -122,12 +125,7 @@ public class RenderSpatialPylon extends BaseBlockRender
BlockRenderInfo bri = imb.getRendererInstance(); BlockRenderInfo bri = imb.getRendererInstance();
bri.setTemporaryRenderIcon( null ); bri.setTemporaryRenderIcon( null );
bri.setTemporaryRenderIcons( this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.UP ), bri.setTemporaryRenderIcons( this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.UP ), this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.DOWN ), this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ), this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.NORTH ), this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.EAST ), this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.WEST ) );
this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.DOWN ),
this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ),
this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.NORTH ),
this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.EAST ),
this.getBlockTextureFromSideOutside( imb, sp, displayBits, ori, ForgeDirection.WEST ) );
boolean r = renderer.renderStandardBlock( imb, x, y, z ); boolean r = renderer.renderStandardBlock( imb, x, y, z );
@@ -143,12 +141,7 @@ public class RenderSpatialPylon extends BaseBlockRender
else else
{ {
bri.setTemporaryRenderIcon( null ); bri.setTemporaryRenderIcon( null );
bri.setTemporaryRenderIcons( this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.UP ), bri.setTemporaryRenderIcons( this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.UP ), this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.DOWN ), this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ), this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.NORTH ), this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.EAST ), this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.WEST ) );
this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.DOWN ),
this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.SOUTH ),
this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.NORTH ),
this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.EAST ),
this.getBlockTextureFromSideInside( imb, sp, displayBits, ori, ForgeDirection.WEST ) );
renderer.renderStandardBlock( imb, x, y, z ); renderer.renderStandardBlock( imb, x, y, z );
} }
@@ -21,6 +21,7 @@ package appeng.tile.storage;
import java.util.ArrayList; import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -114,7 +115,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
this.mySrc = new MachineSource( this ); this.mySrc = new MachineSource( this );
this.lastRedstoneState = YesNo.UNDECIDED; this.lastRedstoneState = YesNo.UNDECIDED;
this.upgrades = new BlockUpgradeInventory( this.getBlockType(), this, 3 ); final Block ioPortBlock = AEApi.instance().definitions().blocks().iOPort().maybeBlock().get();
this.upgrades = new BlockUpgradeInventory( ioPortBlock, this, 3 );
} }
@TileEvent( TileEventType.WORLD_NBT_WRITE ) @TileEvent( TileEventType.WORLD_NBT_WRITE )
+315 -305
View File
@@ -18,12 +18,15 @@
package appeng.util.item; package appeng.util.item;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@@ -40,50 +43,40 @@ import cpw.mods.fml.relauncher.SideOnly;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
import appeng.api.storage.StorageChannel; import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IAETagCompound; import appeng.api.storage.data.IAETagCompound;
import appeng.util.Platform; import appeng.util.Platform;
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack, Comparable<AEItemStack> public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack, Comparable<AEItemStack>
{ {
AEItemDef def; AEItemDef def;
@Override private AEItemStack( AEItemStack is )
public String toString()
{ {
return this.getItemStack().toString();
}
@Override
public void add(IAEItemStack option)
{
if ( option == null )
return;
// if ( priority < ((AEItemStack) option).priority )
// priority = ((AEItemStack) option).priority;
this.incStackSize( option.getStackSize() );
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
this.setCraftable( this.isCraftable() || option.isCraftable() );
}
private AEItemStack(AEItemStack is) {
this.def = is.def; this.def = is.def;
this.stackSize = is.stackSize; this.stackSize = is.stackSize;
this.setCraftable( is.isCraftable() ); this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() ); this.setCountRequestable( is.getCountRequestable() );
} }
private AEItemStack( ItemStack is ) { private AEItemStack( ItemStack is )
{
if( is == null ) if( is == null )
throw new RuntimeException( "Invalid Itemstack." ); {
throw new InvalidParameterException( "null is not a valid ItemStack for AEItemStack." );
}
this.def = new AEItemDef( is.getItem() ); final Item item = is.getItem();
if( item == null )
{
throw new InvalidParameterException( "Contained item is null, thus not a valid ItemStack for AEItemStack." );
}
this.def = new AEItemDef( item );
if( this.def.item == null ) if( this.def.item == null )
throw new RuntimeException( "This ItemStack is bad, it has a null item." ); throw new InvalidParameterException( "This ItemStack is bad, it has a null item." );
/* /*
* Prevent an Item from changing the damage value on me... Either, this or a core mod. * Prevent an Item from changing the damage value on me... Either, this or a core mod.
@@ -114,70 +107,89 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.def.isOre = OreHelper.INSTANCE.isOre( is ); this.def.isOre = OreHelper.INSTANCE.isOre( is );
} }
public static IAEItemStack loadItemStackFromNBT( NBTTagCompound i )
{
if( i == null )
return null;
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
if( itemstack == null )
return null;
AEItemStack item = AEItemStack.create( itemstack );
// item.priority = i.getInteger( "Priority" );
item.stackSize = i.getLong( "Cnt" );
item.setCountRequestable( i.getLong( "Req" ) );
item.setCraftable( i.getBoolean( "Craft" ) );
return item;
}
@Nullable
public static AEItemStack create( ItemStack stack ) public static AEItemStack create( ItemStack stack )
{ {
if( stack == null )
{
return null;
}
return new AEItemStack( stack ); return new AEItemStack( stack );
} }
public static IAEStack<IAEItemStack> create( IAEStack<IAEItemStack> stack ) public static IAEItemStack loadItemStackFromPacket( ByteBuf data ) throws IOException
{ {
return stack.copy(); byte mask = data.readByte();
// byte PriorityType = (byte) (mask & 0x03);
byte StackType = (byte) ( ( mask & 0x0C ) >> 2 );
byte CountReqType = (byte) ( ( mask & 0x30 ) >> 4 );
boolean isCraftable = ( mask & 0x40 ) > 0;
boolean hasTagCompound = ( mask & 0x80 ) > 0;
// don't send this...
NBTTagCompound d = new NBTTagCompound();
d.setShort( "id", data.readShort() );
d.setShort( "Damage", data.readShort() );
d.setByte( "Count", (byte) 0 );
if( hasTagCompound )
{
int len = data.readInt();
byte[] bd = new byte[len];
data.readBytes( bd );
ByteArrayInputStream di = new ByteArrayInputStream( bd );
d.setTag( "tag", CompressedStreamTools.read( new DataInputStream( di ) ) );
}
// long priority = getPacketValue( PriorityType, data );
long stackSize = getPacketValue( StackType, data );
long countRequestable = getPacketValue( CountReqType, data );
ItemStack itemstack = ItemStack.loadItemStackFromNBT( d );
if( itemstack == null )
return null;
AEItemStack item = AEItemStack.create( itemstack );
// item.priority = (int) priority;
item.stackSize = stackSize;
item.setCountRequestable( countRequestable );
item.setCraftable( isCraftable );
return item;
} }
@Override @Override
public Item getItem() public void add( IAEItemStack option )
{ {
return this.def.item; if( option == null )
} return;
@Override // if ( priority < ((AEItemStack) option).priority )
public boolean equals(Object ia) // priority = ((AEItemStack) option).priority;
{
if ( ia instanceof AEItemStack )
{
return ((AEItemStack) ia).def.equals( this.def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
}
else if ( ia instanceof ItemStack )
{
ItemStack is = (ItemStack) ia;
if ( is.getItem() == this.def.item && is.getItemDamage() == this.def.damageValue ) this.incStackSize( option.getStackSize() );
{ this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
NBTTagCompound ta = this.def.tagCompound; this.setCraftable( this.isCraftable() || option.isCraftable() );
NBTTagCompound tb = is.getTagCompound();
if ( ta == tb )
return true;
if ( (ta == null && tb == null) || (ta != null && ta.hasNoTags() && tb == null) || (tb != null && tb.hasNoTags() && ta == null)
|| (ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags()) )
return true;
if ( (ta == null && tb != null) || (ta != null && tb == null) )
return false;
if ( AESharedNBT.isShared( tb ) )
return ta == tb;
return Platform.NBTEqualityTest( ta, tb );
}
}
return false;
}
@Override
public ItemStack getItemStack()
{
ItemStack is = new ItemStack( this.def.item, (int) Math.min( Integer.MAX_VALUE, this.stackSize ), this.def.damageValue );
if ( this.def.tagCompound != null )
is.setTagCompound( this.def.tagCompound.getNBTTagCompoundCopy() );
return is;
}
@Override
public IAEItemStack copy()
{
return new AEItemStack( this );
} }
@Override @Override
@@ -228,190 +240,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
i.setTag( "tag", this.def.tagCompound ); i.setTag( "tag", this.def.tagCompound );
else else
i.removeTag( "tag" ); i.removeTag( "tag" );
}
public static IAEItemStack loadItemStackFromNBT(NBTTagCompound i)
{
if ( i == null )
return null;
ItemStack itemstack = ItemStack.loadItemStackFromNBT( i );
if ( itemstack == null )
return null;
AEItemStack item = AEItemStack.create( itemstack );
// item.priority = i.getInteger( "Priority" );
item.stackSize = i.getLong( "Cnt" );
item.setCountRequestable( i.getLong( "Req" ) );
item.setCraftable( i.getBoolean( "Craft" ) );
return item;
}
@Override
public boolean hasTagCompound()
{
return this.def.tagCompound != null;
}
@Override
public int hashCode()
{
return this.def.myHash;
}
@Override
public int compareTo(AEItemStack b)
{
int id = this.def.itemID - b.def.itemID;
if (id != 0)
return id;
int damageValue = this.def.damageValue - b.def.damageValue ;
if (damageValue != 0)
return damageValue;
int displayDamage = this.def.displayDamage - b.def.displayDamage;
if (displayDamage != 0)
return displayDamage;
return (this.def.tagCompound == b.def.tagCompound) ? 0 : this.compareNBT( b.def );
}
private int compareNBT(AEItemDef b)
{
int nbt = this.compare( (this.def.tagCompound == null ? 0 : this.def.tagCompound.getHash()), (b.tagCompound == null ? 0 : b.tagCompound.getHash()) );
if ( nbt == 0 )
return this.compare( System.identityHashCode( this.def.tagCompound ), System.identityHashCode( b.tagCompound ) );
return nbt;
}
private int compare(int l, int m)
{
return l < m ? -1 : (l > m ? 1 : 0);
}
@SideOnly(Side.CLIENT)
public List getToolTip()
{
if ( this.def.tooltip != null )
return this.def.tooltip;
return this.def.tooltip = Platform.getTooltip( this.getItemStack() );
}
@SideOnly(Side.CLIENT)
public String getDisplayName()
{
if ( this.def.displayName != null )
return this.def.displayName;
return this.def.displayName = Platform.getItemDisplayName( this.getItemStack() );
}
@SideOnly(Side.CLIENT)
public String getModID()
{
if ( this.def.uniqueID != null )
return this.getModName( this.def.uniqueID );
return this.getModName( this.def.uniqueID = GameRegistry.findUniqueIdentifierFor( this.def.item ) );
}
private String getModName(UniqueIdentifier uniqueIdentifier)
{
if ( uniqueIdentifier == null )
return "** Null";
return uniqueIdentifier.modId == null ? "** Null" : uniqueIdentifier.modId;
}
@Override
public IAEItemStack empty()
{
IAEItemStack dup = this.copy();
dup.reset();
return dup;
}
@Override
public int getItemDamage()
{
return this.def.damageValue;
}
@Override
void writeIdentity(ByteBuf i) throws IOException
{
i.writeShort( Item.itemRegistry.getIDForObject( this.def.item ) );
i.writeShort( this.getItemDamage() );
}
@Override
void readNBT(ByteBuf i) throws IOException
{
if ( this.hasTagCompound() )
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data );
byte[] tagBytes = bytes.toByteArray();
int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
}
}
public static IAEItemStack loadItemStackFromPacket(ByteBuf data) throws IOException
{
byte mask = data.readByte();
// byte PriorityType = (byte) (mask & 0x03);
byte StackType = (byte) ((mask & 0x0C) >> 2);
byte CountReqType = (byte) ((mask & 0x30) >> 4);
boolean isCraftable = (mask & 0x40) > 0;
boolean hasTagCompound = (mask & 0x80) > 0;
// don't send this...
NBTTagCompound d = new NBTTagCompound();
d.setShort( "id", data.readShort() );
d.setShort( "Damage", data.readShort() );
d.setByte( "Count", (byte) 0 );
if ( hasTagCompound )
{
int len = data.readInt();
byte[] bd = new byte[len];
data.readBytes( bd );
ByteArrayInputStream di = new ByteArrayInputStream( bd );
d.setTag( "tag", CompressedStreamTools.read( new DataInputStream( di ) ) );
}
// long priority = getPacketValue( PriorityType, data );
long stackSize = getPacketValue( StackType, data );
long countRequestable = getPacketValue( CountReqType, data );
ItemStack itemstack = ItemStack.loadItemStackFromNBT( d );
if ( itemstack == null )
return null;
AEItemStack item = AEItemStack.create( itemstack );
// item.priority = (int) priority;
item.stackSize = stackSize;
item.setCountRequestable( countRequestable );
item.setCraftable( isCraftable );
return item;
}
@Override
public boolean sameOre(IAEItemStack is)
{
return OreHelper.INSTANCE.sameOre( this, is );
} }
@Override @Override
@@ -530,6 +358,232 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return false; return false;
} }
@Override
public IAEItemStack copy()
{
return new AEItemStack( this );
}
@Override
public IAEItemStack empty()
{
IAEItemStack dup = this.copy();
dup.reset();
return dup;
}
@Override
public IAETagCompound getTagCompound()
{
return this.def.tagCompound;
}
@Override
public boolean isItem()
{
return true;
}
@Override
public boolean isFluid()
{
return false;
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
@Override
public int hashCode()
{
return this.def.myHash;
}
@Override
public boolean equals( Object ia )
{
if( ia instanceof AEItemStack )
{
return ( (AEItemStack) ia ).def.equals( this.def );// && def.tagCompound == ((AEItemStack) ia).def.tagCompound;
}
else if( ia instanceof ItemStack )
{
ItemStack is = (ItemStack) ia;
if( is.getItem() == this.def.item && is.getItemDamage() == this.def.damageValue )
{
NBTTagCompound ta = this.def.tagCompound;
NBTTagCompound tb = is.getTagCompound();
if( ta == tb )
return true;
if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) )
return true;
if( ( ta == null && tb != null ) || ( ta != null && tb == null ) )
return false;
if( AESharedNBT.isShared( tb ) )
return ta == tb;
return Platform.NBTEqualityTest( ta, tb );
}
}
return false;
}
@Override
public String toString()
{
return this.getItemStack().toString();
}
@Override
public ItemStack getItemStack()
{
ItemStack is = new ItemStack( this.def.item, (int) Math.min( Integer.MAX_VALUE, this.stackSize ), this.def.damageValue );
if( this.def.tagCompound != null )
is.setTagCompound( this.def.tagCompound.getNBTTagCompoundCopy() );
return is;
}
@Override
public Item getItem()
{
return this.def.item;
}
@Override
public int getItemDamage()
{
return this.def.damageValue;
}
@Override
public boolean sameOre( IAEItemStack is )
{
return OreHelper.INSTANCE.sameOre( this, is );
}
@Override
public boolean isSameType( IAEItemStack otherStack )
{
if( otherStack == null )
return false;
return this.def.equals( ( (AEItemStack) otherStack ).def );
}
@Override
public boolean isSameType( ItemStack otherStack )
{
if( otherStack == null )
return false;
return this.def.isItem( otherStack );
}
@Override
public int compareTo( AEItemStack b )
{
int id = this.def.itemID - b.def.itemID;
if( id != 0 )
return id;
int damageValue = this.def.damageValue - b.def.damageValue;
if( damageValue != 0 )
return damageValue;
int displayDamage = this.def.displayDamage - b.def.displayDamage;
if( displayDamage != 0 )
return displayDamage;
return ( this.def.tagCompound == b.def.tagCompound ) ? 0 : this.compareNBT( b.def );
}
private int compareNBT( AEItemDef b )
{
int nbt = this.compare( ( this.def.tagCompound == null ? 0 : this.def.tagCompound.getHash() ), ( b.tagCompound == null ? 0 : b.tagCompound.getHash() ) );
if( nbt == 0 )
return this.compare( System.identityHashCode( this.def.tagCompound ), System.identityHashCode( b.tagCompound ) );
return nbt;
}
private int compare( int l, int m )
{
return l < m ? -1 : ( l > m ? 1 : 0 );
}
@SideOnly( Side.CLIENT )
public List getToolTip()
{
if( this.def.tooltip != null )
return this.def.tooltip;
return this.def.tooltip = Platform.getTooltip( this.getItemStack() );
}
@SideOnly( Side.CLIENT )
public String getDisplayName()
{
if( this.def.displayName != null )
return this.def.displayName;
return this.def.displayName = Platform.getItemDisplayName( this.getItemStack() );
}
@SideOnly( Side.CLIENT )
public String getModID()
{
if( this.def.uniqueID != null )
return this.getModName( this.def.uniqueID );
return this.getModName( this.def.uniqueID = GameRegistry.findUniqueIdentifierFor( this.def.item ) );
}
private String getModName( UniqueIdentifier uniqueIdentifier )
{
if( uniqueIdentifier == null )
return "** Null";
return uniqueIdentifier.modId == null ? "** Null" : uniqueIdentifier.modId;
}
@Override
void writeIdentity( ByteBuf i ) throws IOException
{
i.writeShort( Item.itemRegistry.getIDForObject( this.def.item ) );
i.writeShort( this.getItemDamage() );
}
@Override
void readNBT( ByteBuf i ) throws IOException
{
if( this.hasTagCompound() )
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
CompressedStreamTools.write( (NBTTagCompound) this.getTagCompound(), data );
byte[] tagBytes = bytes.toByteArray();
int size = tagBytes.length;
i.writeInt( size );
i.writeBytes( tagBytes );
}
}
@Override
public boolean hasTagCompound()
{
return this.def.tagCompound != null;
}
public IAEItemStack getLow( FuzzyMode fuzzy, boolean ignoreMeta ) public IAEItemStack getLow( FuzzyMode fuzzy, boolean ignoreMeta )
{ {
AEItemStack bottom = new AEItemStack( this ); AEItemStack bottom = new AEItemStack( this );
@@ -554,7 +608,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
newDef.displayDamage = 0; newDef.displayDamage = 0;
else else
newDef.displayDamage = 1; newDef.displayDamage = 1;
} }
else else
{ {
@@ -609,51 +662,8 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return top; return top;
} }
@Override
public IAETagCompound getTagCompound()
{
return this.def.tagCompound;
}
@Override
public boolean isSameType(IAEItemStack otherStack)
{
if ( otherStack == null )
return false;
return this.def.equals( ((AEItemStack) otherStack).def );
}
@Override
public boolean isSameType(ItemStack otherStack)
{
if ( otherStack == null )
return false;
return this.def.isItem( otherStack );
}
@Override
public boolean isItem()
{
return true;
}
@Override
public boolean isFluid()
{
return false;
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
public boolean isOre() public boolean isOre()
{ {
return this.def.isOre != null; return this.def.isOre != null;
} }
} }