Fixes #2557: Made facades much more robust when rendering. Facades now use string ids for the base item in NBT again to avoid issues when loading worlds with a different Item ID registry mapping. In addition, we don't store the Block metadata instead of the Item Damage anymore, since when reading a facade back in, we were using that block metadata as the item damage, which is technically incorrect.
This commit is contained in:
parent
a3c33d5323
commit
2fe5a3cef8
2 changed files with 74 additions and 13 deletions
|
@ -22,6 +22,7 @@ package appeng.client.render.cablebus;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -64,8 +65,11 @@ public class FacadeBuilder
|
|||
private final VertexFormat format;
|
||||
|
||||
private final TextureAtlasSprite facadeTexture;
|
||||
|
||||
private final BlockRendererDispatcher blockRendererDispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
|
||||
|
||||
private static final Set<ResourceLocation> warnedFor = new HashSet<>();
|
||||
|
||||
FacadeBuilder( VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||
{
|
||||
this.format = format;
|
||||
|
@ -132,11 +136,36 @@ public class FacadeBuilder
|
|||
}
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
if( warnedFor.add( state.getBlock().getRegistryName() ) )
|
||||
{
|
||||
AELog.warn( "Unable to get facade sprite for blockstate %s. Supressing further warnings for this block.", state );
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ForgeHooksClient.setRenderLayer( orgLayer );
|
||||
}
|
||||
|
||||
// Fall back to the particle texture, if we havent found anything else so far.
|
||||
if( firstFound == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
return blockModel.getParticleTexture();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
if( warnedFor.add( state.getBlock().getRegistryName() ) )
|
||||
{
|
||||
AELog.warn( "Unable to get facade sprite particle texture fallback for blockstate %s. Supressing further warnings for this block.", state );
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return firstFound;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ 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;
|
||||
|
@ -57,6 +58,9 @@ import appeng.items.AEBaseItem;
|
|||
public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassItem
|
||||
{
|
||||
|
||||
private static final String TAG_ITEM_ID = "item";
|
||||
private static final String TAG_DAMAGE = "damage";
|
||||
|
||||
private List<ItemStack> subTypes = null;
|
||||
|
||||
public ItemFacade()
|
||||
|
@ -107,6 +111,10 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
try
|
||||
{
|
||||
final Item item = Item.getItemFromBlock( b );
|
||||
if( item == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final List<ItemStack> tmpList = new ArrayList<ItemStack>( 100 );
|
||||
b.getSubBlocks( item, b.getCreativeTabToDisplayOn(), tmpList );
|
||||
|
@ -184,10 +192,8 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
|
||||
final ItemStack is = new ItemStack( this );
|
||||
final NBTTagCompound data = new NBTTagCompound();
|
||||
final int[] ds = new int[2];
|
||||
ds[0] = Item.getIdFromItem( l.getItem() );
|
||||
ds[1] = metadata;
|
||||
data.setIntArray( "x", ds );
|
||||
data.setString( TAG_ITEM_ID, l.getItem().getRegistryName().toString() );
|
||||
data.setInteger( TAG_DAMAGE, l.getItemDamage() );
|
||||
is.setTagCompound( data );
|
||||
return is;
|
||||
}
|
||||
|
@ -216,22 +222,39 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
return null;
|
||||
}
|
||||
|
||||
// First item is numeric item id, second is damage
|
||||
int[] ids = nbt.getIntArray( "x" );
|
||||
ResourceLocation itemId;
|
||||
int itemDamage;
|
||||
|
||||
if( ids.length != 2 )
|
||||
// Handle legacy facades
|
||||
if( nbt.hasKey( "x" ) )
|
||||
{
|
||||
return null;
|
||||
int[] data = nbt.getIntArray( "x" );
|
||||
if( data.length != 2 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Item item = Item.REGISTRY.getObjectById( data[0] );
|
||||
if ( item == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
itemId = item.getRegistryName();
|
||||
itemDamage = data[1];
|
||||
} else {
|
||||
// First item is numeric item id, second is damage
|
||||
itemId = new ResourceLocation( nbt.getString( TAG_ITEM_ID ) );
|
||||
itemDamage = nbt.getInteger( TAG_DAMAGE );
|
||||
}
|
||||
|
||||
Item baseItem = Item.REGISTRY.getObjectById( ids[0] );
|
||||
Item baseItem = Item.REGISTRY.getObject( itemId );
|
||||
|
||||
if( baseItem == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ItemStack( baseItem, 1, ids[1] );
|
||||
return new ItemStack( baseItem, 1, itemDamage );
|
||||
|
||||
}
|
||||
|
||||
|
@ -253,13 +276,15 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
return Blocks.GLASS.getDefaultState();
|
||||
}
|
||||
|
||||
int metadata = baseItemStack.getItem().getMetadata( baseItemStack );
|
||||
|
||||
try
|
||||
{
|
||||
return block.getStateFromMeta( baseItemStack.getItemDamage() );
|
||||
return block.getStateFromMeta( metadata );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
AELog.warn( "Block {} has broken getStateFromMeta method for meta {}", block.getRegistryName(), baseItemStack.getItemDamage() );
|
||||
AELog.warn( "Block %s has broken getStateFromMeta method for meta %d", block.getRegistryName().toString(), baseItemStack.getItemDamage() );
|
||||
return Blocks.GLASS.getDefaultState();
|
||||
}
|
||||
|
||||
|
@ -286,8 +311,15 @@ public class ItemFacade extends AEBaseItem implements IFacadeItem, IAlphaPassIte
|
|||
ItemStack facadeStack = AEApi.instance().definitions().items().facade().maybeStack( 1 )
|
||||
.orElseThrow( () -> new MissingDefinition( "Tried to create a facade, while facades are being deactivated." ) );
|
||||
|
||||
// Convert back to a registry name...
|
||||
Item item = Item.REGISTRY.getObjectById( ids[0] );
|
||||
if ( item == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final NBTTagCompound facadeTag = new NBTTagCompound();
|
||||
facadeTag.setIntArray( "x", ids.clone() );
|
||||
facadeTag.setString( TAG_ITEM_ID, item.getRegistryName().toString() );
|
||||
facadeTag.setInteger( TAG_DAMAGE, ids[1] );
|
||||
facadeStack.setTagCompound( facadeTag );
|
||||
|
||||
return facadeStack;
|
||||
|
|
Loading…
Reference in a new issue