Enabled block states ignoring properties

Enabled block states ignoring. File with same name as block state, but
with .ignore.json extension. Although it's json extension, it is NOT IN
JSON FORMAT!!! Each line is name of property to ignore. Refers to #10.
This commit is contained in:
elix-x
2016-07-01 20:19:10 +02:00
parent e24d166f6a
commit 9f96b86938
11 changed files with 124 additions and 6 deletions
@@ -93,6 +93,10 @@ public class ClientHelper extends ServerHelper
{
MinecraftForge.EVENT_BUS.register( this );
ModelLoaderRegistry.registerLoader( UVLModelLoader.INSTANCE );
for( IAEFeature feature : Api.INSTANCE.definitions().getFeatureRegistry().getRegisteredFeatures() )
{
feature.handler().registerStateMapper();
}
}
@Override
@@ -0,0 +1,65 @@
package appeng.client.render.model;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Maps;
import org.apache.commons.io.IOUtils;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.ResourceLocation;
public class AEIgnoringStateMapper extends StateMapperBase implements IResourceManagerReloadListener
{
private final ResourceLocation ignoredRL;
private final List<String> ignored = new ArrayList<>();
public AEIgnoringStateMapper( ResourceLocation ignoredRL )
{
this.ignoredRL = new ResourceLocation( ignoredRL.getResourceDomain(), "blockstates/" + ignoredRL.getResourcePath() + ".ignore.json" );
}
@Override
public void onResourceManagerReload( IResourceManager resourceManager )
{
try
{
ignored.addAll( IOUtils.readLines( resourceManager.getResource( ignoredRL ).getInputStream() ) );
}
catch( IOException e )
{
// There's no ignore file, so everything is ok.
}
}
@Override
protected ModelResourceLocation getModelResourceLocation( IBlockState state )
{
Map<IProperty<?>, Comparable<?>> map = Maps.<IProperty<?>, Comparable<?>>newLinkedHashMap( state.getProperties() );
Iterator<Entry<IProperty<?>, Comparable<?>>> it = map.entrySet().iterator();
while( it.hasNext() )
{
if( ignored.contains( it.next().getKey().getName() ) )
{
it.remove();
}
}
return new ModelResourceLocation( (ResourceLocation) Block.REGISTRY.getNameForObject( state.getBlock() ), this.getPropertyString( map ) );
}
}