Fixes #2533 and #2531: Slight overhaul to how Facades store the associated item and retrieve the sprite.
This commit is contained in:
parent
c2b5a58dd2
commit
971fc3d243
|
@ -23,7 +23,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
|
@ -108,11 +107,7 @@ public class FacadeDispatcherBakedModel implements IBakedModel
|
|||
|
||||
ItemFacade itemFacade = (ItemFacade) stack.getItem();
|
||||
|
||||
Block block = itemFacade.getBlock( stack );
|
||||
int meta = itemFacade.getMeta( stack );
|
||||
|
||||
// This is kinda fascinating, how do we get the meta from the itemblock
|
||||
IBlockState state = block.getStateFromMeta( meta );
|
||||
IBlockState state = itemFacade.getTextureBlockState( stack );
|
||||
|
||||
return new FacadeWithBlockBakedModel( baseModel, state, format );
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ import net.minecraft.util.BlockRenderLayer;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.util.AEAxisAlignedBB;
|
||||
|
@ -100,23 +102,41 @@ public class FacadeBuilder
|
|||
|
||||
public static TextureAtlasSprite getSprite( IBakedModel blockModel, IBlockState state, EnumFacing facing, long rand)
|
||||
{
|
||||
for( BakedQuad bakedQuad : blockModel.getQuads( state, facing, rand ) )
|
||||
{
|
||||
return bakedQuad.getSprite();
|
||||
}
|
||||
|
||||
TextureAtlasSprite firstFound = null;
|
||||
for( BakedQuad bakedQuad : blockModel.getQuads( state, null, rand ) )
|
||||
BlockRenderLayer orgLayer = MinecraftForgeClient.getRenderLayer();
|
||||
|
||||
try
|
||||
{
|
||||
if( firstFound == null )
|
||||
// Some other mods also distinguish between layers, so we're doing this in a loop from most likely to least likely
|
||||
for( BlockRenderLayer layer : BlockRenderLayer.values() )
|
||||
{
|
||||
firstFound = bakedQuad.getSprite();
|
||||
}
|
||||
if( bakedQuad.getFace() == facing )
|
||||
{
|
||||
return bakedQuad.getSprite();
|
||||
|
||||
ForgeHooksClient.setRenderLayer( layer );
|
||||
|
||||
for( BakedQuad bakedQuad : blockModel.getQuads( state, facing, rand ) )
|
||||
{
|
||||
return bakedQuad.getSprite();
|
||||
}
|
||||
|
||||
for( BakedQuad bakedQuad : blockModel.getQuads( state, null, rand ) )
|
||||
{
|
||||
if( firstFound == null )
|
||||
{
|
||||
firstFound = bakedQuad.getSprite();
|
||||
}
|
||||
if( bakedQuad.getFace() == facing )
|
||||
{
|
||||
return bakedQuad.getSprite();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ForgeHooksClient.setRenderLayer( orgLayer );
|
||||
}
|
||||
|
||||
return firstFound;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,11 @@ package appeng.facade;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
|
@ -121,10 +120,7 @@ public class FacadePart implements IFacadePart, IBoxProvider
|
|||
return true;
|
||||
}
|
||||
|
||||
final ItemStack is = this.getTextureItem();
|
||||
final Block blk = Block.getBlockFromItem( is.getItem() );
|
||||
|
||||
return !blk.isOpaqueCube( blk.getDefaultState() );
|
||||
return this.getBlockState().isOpaqueCube();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -147,25 +143,17 @@ public class FacadePart implements IFacadePart, IBoxProvider
|
|||
@Override
|
||||
public IBlockState getBlockState()
|
||||
{
|
||||
ItemStack itemStack = getTextureItem();
|
||||
final Item maybeFacade = this.facade.getItem();
|
||||
|
||||
if( !(itemStack.getItem() instanceof ItemBlock ) )
|
||||
// AE Facade
|
||||
if( maybeFacade instanceof IFacadeItem )
|
||||
{
|
||||
return null;
|
||||
final IFacadeItem facade = (IFacadeItem) maybeFacade;
|
||||
|
||||
return facade.getTextureBlockState( this.facade );
|
||||
}
|
||||
|
||||
ItemBlock itemBlock = (ItemBlock) itemStack.getItem();
|
||||
|
||||
// Try to get the block state based on the item stack's meta. If this fails, don't consider it for a facade
|
||||
// This for example fails for Pistons because they hardcoded an invalid meta value in vanilla
|
||||
try
|
||||
{
|
||||
return itemBlock.getBlock().getStateFromMeta( itemStack.getItemDamage() );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Blocks.GLASS.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package appeng.facade;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
@ -32,7 +32,6 @@ public interface IFacadeItem
|
|||
|
||||
ItemStack getTextureItem( ItemStack is );
|
||||
|
||||
int getMeta( ItemStack is );
|
||||
IBlockState getTextureBlockState( ItemStack is );
|
||||
|
||||
Block getBlock( ItemStack is );
|
||||
}
|
||||
|
|
|
@ -38,11 +38,9 @@ import net.minecraft.util.EnumActionResult;
|
|||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.exceptions.MissingDefinition;
|
||||
|
@ -190,9 +188,6 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
ds[0] = Item.getIdFromItem( l.getItem() );
|
||||
ds[1] = metadata;
|
||||
data.setIntArray( "x", ds );
|
||||
final ResourceLocation ui = Item.REGISTRY.getNameForObject( l.getItem() );
|
||||
data.setString( "modid", ui.getResourceDomain() );
|
||||
data.setString( "itemname", ui.getResourcePath() );
|
||||
is.setTagCompound( data );
|
||||
return is;
|
||||
}
|
||||
|
@ -211,56 +206,55 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTextureItem( final ItemStack is )
|
||||
public ItemStack getTextureItem( ItemStack is )
|
||||
{
|
||||
final Block blk = this.getBlock( is );
|
||||
if( blk != null )
|
||||
|
||||
NBTTagCompound nbt = is.getTagCompound();
|
||||
|
||||
if( nbt == null )
|
||||
{
|
||||
return new ItemStack( blk, 1, this.getMeta( is ) );
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
// First item is numeric item id, second is damage
|
||||
int[] ids = nbt.getIntArray( "x" );
|
||||
|
||||
if( ids.length != 2 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Item baseItem = Item.REGISTRY.getObjectById( ids[0] );
|
||||
|
||||
if( baseItem == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ItemStack( baseItem, 1, ids[1] );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMeta( final ItemStack is )
|
||||
public IBlockState getTextureBlockState( ItemStack is )
|
||||
{
|
||||
final NBTTagCompound data = is.getTagCompound();
|
||||
if( data != null )
|
||||
{
|
||||
final int[] blk = data.getIntArray( "x" );
|
||||
if( blk != null && blk.length == 2 )
|
||||
{
|
||||
return blk[1];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock( final ItemStack is )
|
||||
{
|
||||
final NBTTagCompound data = is.getTagCompound();
|
||||
if( data != null )
|
||||
{
|
||||
if( data.hasKey( "modid" ) && data.hasKey( "itemname" ) )
|
||||
{
|
||||
if( data.getString( "modid" ).equals( "minecraft" ) )
|
||||
{
|
||||
return Block.getBlockFromName( data.getString( "itemname" ) );
|
||||
}
|
||||
ItemStack baseItemStack = getTextureItem( is );
|
||||
|
||||
return GameRegistry.findBlock( data.getString( "modid" ), data.getString( "itemname" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
final int[] blk = data.getIntArray( "x" );
|
||||
if( blk != null && blk.length == 2 )
|
||||
{
|
||||
return Block.getBlockById( blk[0] );
|
||||
}
|
||||
}
|
||||
if( baseItemStack == null )
|
||||
{
|
||||
return Blocks.GLASS.getDefaultState();
|
||||
}
|
||||
return Blocks.GLASS;
|
||||
|
||||
Block block = Block.getBlockFromItem( baseItemStack.getItem() );
|
||||
|
||||
if( block == null )
|
||||
{
|
||||
return Blocks.GLASS.getDefaultState();
|
||||
}
|
||||
|
||||
return block.getStateFromMeta( baseItemStack.getItemDamage() );
|
||||
|
||||
}
|
||||
|
||||
public List<ItemStack> getFacades()
|
||||
|
@ -294,19 +288,14 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
@Override
|
||||
public boolean useAlphaPass( final ItemStack is )
|
||||
{
|
||||
final ItemStack out = this.getTextureItem( is );
|
||||
IBlockState blockState = this.getTextureBlockState( is );
|
||||
|
||||
if( out == null || out.getItem() == null )
|
||||
if( blockState == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Block blk = Block.getBlockFromItem( out.getItem() );
|
||||
if( blk != null && blk.canRenderInLayer( BlockRenderLayer.TRANSLUCENT ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
Block blk = blockState.getBlock();
|
||||
return blk.canRenderInLayer( BlockRenderLayer.TRANSLUCENT );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue