Major Refactoring of Bootstrap Code (#75)
- Refactored boostrap code: * Completely reworked item/block/tile registration. * Fixed server side startup. * Fixed server side startup. * More documentation. * More heavy cleanup * More cleanups. * Major refactoring of state mapping and fixes a lot of other issue related to item rendering. * Fixes sky chest item models (no item TESR). * Only use CachingRotatingBakedModel for tile entities automatically. Fix default rotation of quartz pillar for item model. * Used method reference instead of lambda for ItemMeshDefinition for multiparts. * Removed unnecessary IHasSpecialItemModel * Removed unused IconReg class. * Updated resource pack version.
This commit is contained in:
committed by
Sebastian Hartte
parent
66df324ef0
commit
6f2bbfab4c
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.block.IHasSpecialItemModel;
|
||||
import appeng.client.render.model.AEIgnoringStateMapper;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
|
||||
|
||||
public final class AEBlockFeatureHandler implements IFeatureHandler
|
||||
{
|
||||
private final Block featured;
|
||||
private final FeatureNameExtractor extractor;
|
||||
private final boolean enabled;
|
||||
private final BlockDefinition definition;
|
||||
|
||||
private ResourceLocation registryName;
|
||||
|
||||
public AEBlockFeatureHandler( final EnumSet<AEFeature> features, final Block featured, final Optional<String> subName )
|
||||
{
|
||||
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
||||
|
||||
this.featured = featured;
|
||||
this.extractor = new FeatureNameExtractor( featured.getClass(), subName );
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
// TODO use real identifier
|
||||
this.definition = new BlockDefinition( featured.getClass().getSimpleName(), featured, state );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFeatureAvailable()
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition getDefinition()
|
||||
{
|
||||
return this.definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register( final Side side )
|
||||
{
|
||||
if( this.enabled )
|
||||
{
|
||||
String name = this.extractor.get();
|
||||
if( Item.REGISTRY.containsKey( new ResourceLocation( AppEng.MOD_ID, name ) ) )
|
||||
{
|
||||
name += "_block";
|
||||
}
|
||||
this.featured.setCreativeTab( CreativeTab.instance );
|
||||
this.featured.setUnlocalizedName( "appliedenergistics2." + name );
|
||||
|
||||
registryName = new ResourceLocation( AppEng.MOD_ID, name );
|
||||
GameRegistry.register( this.featured.setRegistryName( registryName ) );
|
||||
|
||||
// register the block/item conversion...
|
||||
if( this.definition.maybeItem().isPresent() )
|
||||
{
|
||||
GameRegistry.register( this.definition.maybeItem().get().setRegistryName( registryName ) );
|
||||
|
||||
if( side == Side.CLIENT )
|
||||
{
|
||||
ModelBakery.registerItemVariants( this.definition.maybeItem().get(), registryName );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel()
|
||||
{
|
||||
ItemModelMesher itemModelMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
|
||||
Item item = this.definition.maybeItem().get();
|
||||
|
||||
// Retrieve a custom item mesh definition, if the block defines one
|
||||
ItemMeshDefinition itemMeshDefinition = null;
|
||||
if( featured instanceof AEBaseBlock )
|
||||
{
|
||||
itemMeshDefinition = ( (AEBaseBlock) featured ).getItemMeshDefinition();
|
||||
}
|
||||
|
||||
if ( itemMeshDefinition != null )
|
||||
{
|
||||
// This block has a custom item mesh definition, so register it instead of the resource location
|
||||
itemModelMesher.register( item, itemMeshDefinition );
|
||||
}
|
||||
else if( !featured.getBlockState().getProperties().isEmpty() || featured instanceof IHasSpecialItemModel )
|
||||
{
|
||||
itemModelMesher.register( item, 0, new ModelResourceLocation( registryName, "inventory" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
itemModelMesher.register( item, 0, new ModelResourceLocation( registryName, "normal" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper()
|
||||
{
|
||||
AEIgnoringStateMapper mapper = new AEIgnoringStateMapper( registryName );
|
||||
ModelLoader.setCustomStateMapper( this.featured, mapper );
|
||||
( (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager() ).registerReloadListener( mapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCustomModelOverride( IRegistry<ModelResourceLocation, IBakedModel> modelRegistry )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.api.client.BakingPipeline;
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.block.networking.BlockCableBus;
|
||||
import appeng.client.render.model.pipeline.BakingPipelineBakedModel;
|
||||
import appeng.client.render.model.pipeline.FacingQuadRotator;
|
||||
import appeng.client.render.model.pipeline.Merge;
|
||||
import appeng.client.render.model.pipeline.TintIndexModifier;
|
||||
import appeng.client.render.model.pipeline.TypeTransformer;
|
||||
import appeng.client.render.model.pipeline.cable.CableAndConnections;
|
||||
import appeng.client.render.model.pipeline.cable.Facades;
|
||||
import appeng.client.render.model.pipeline.cable.Parts;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.parts.CableBusContainer;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public final class AECableBusFeatureHandler implements IFeatureHandler
|
||||
{
|
||||
private final AEBaseTileBlock featured;
|
||||
private final FeatureNameExtractor extractor;
|
||||
private final boolean enabled;
|
||||
private final TileDefinition definition;
|
||||
|
||||
private ResourceLocation registryName;
|
||||
|
||||
public AECableBusFeatureHandler( final EnumSet<AEFeature> features, final BlockCableBus featured, final Optional<String> subName )
|
||||
{
|
||||
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
||||
|
||||
this.featured = featured;
|
||||
this.extractor = new FeatureNameExtractor( featured.getClass(), subName );
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
this.definition = new TileDefinition( featured.getClass().getSimpleName(), featured, state );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFeatureAvailable()
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDefinition getDefinition()
|
||||
{
|
||||
return this.definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration of the {@link TileEntity} will actually be handled by {@link BlockCableBus#setupTile()}.
|
||||
*/
|
||||
@Override
|
||||
public void register( final Side side )
|
||||
{
|
||||
if( this.enabled )
|
||||
{
|
||||
final String name = this.extractor.get();
|
||||
this.featured.setCreativeTab( CreativeTab.instance );
|
||||
this.featured.setUnlocalizedName( "appliedenergistics2." + name );
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
CommonHelper.proxy.bindTileEntitySpecialRenderer( this.featured.getTileEntityClass(), this.featured );
|
||||
}
|
||||
|
||||
registryName = new ResourceLocation( AppEng.MOD_ID, name );
|
||||
|
||||
// Bypass the forge magic with null to register our own itemblock later.
|
||||
GameRegistry.register( this.featured.setRegistryName( registryName ) );
|
||||
GameRegistry.register( this.definition.maybeItem().get().setRegistryName( registryName ) );
|
||||
|
||||
if( side == Side.CLIENT )
|
||||
{
|
||||
ModelBakery.registerItemVariants( this.definition.maybeItem().get(), registryName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel()
|
||||
{
|
||||
Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler( new CableBusColor(), this.featured );
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( this.definition.maybeItem().get(), 0, new ModelResourceLocation( registryName, "normal" ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCustomModelOverride( IRegistry<ModelResourceLocation, IBakedModel> modelRegistry )
|
||||
{
|
||||
final BakingPipeline rotatingPipeline = new BakingPipeline( TypeTransformer.quads2vecs, new FacingQuadRotator(), TypeTransformer.vecs2quads );
|
||||
final TintIndexModifier tintIndexModifier = new TintIndexModifier( tint -> tint );
|
||||
final BakingPipeline tintIndexFixPipeline = new BakingPipeline( TypeTransformer.quads2vecs, tintIndexModifier, TypeTransformer.vecs2quads );
|
||||
Set<ModelResourceLocation> keys = Sets.newHashSet( modelRegistry.getKeys() );
|
||||
for( ModelResourceLocation model : keys )
|
||||
{
|
||||
if( model.getResourceDomain().equals( registryName.getResourceDomain() ) && model.getResourcePath().equals( registryName.getResourcePath() ) )
|
||||
{
|
||||
modelRegistry.putObject( model, new BakingPipelineBakedModel( modelRegistry.getObject( model ), new Merge( new CableAndConnections( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ), new Facades( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ), new Parts( rotatingPipeline, tintIndexModifier, tintIndexFixPipeline ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class CableBusColor implements IBlockColor
|
||||
{
|
||||
|
||||
@Override
|
||||
public int colorMultiplier( IBlockState state, IBlockAccess worldIn, BlockPos pos, int color )
|
||||
{
|
||||
AEPartLocation side = AEPartLocation.fromOrdinal( ( color >> 2 ) & 7 );
|
||||
CableBusContainer bus = ( (IExtendedBlockState) state ).getValue( BlockCableBus.cableBus );
|
||||
switch( color & 3 )
|
||||
{
|
||||
case 0:
|
||||
return bus.getGridNode( side ) != null && bus.getGridNode( side ).isActive() ? 0xffffff : 0;
|
||||
case 1:
|
||||
return bus.getColor().blackVariant;
|
||||
case 2:
|
||||
return bus.getColor().mediumVariant;
|
||||
case 3:
|
||||
return bus.getColor().whiteVariant;
|
||||
default:
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.block.IHasSpecialItemModel;
|
||||
import appeng.client.render.model.AEIgnoringStateMapper;
|
||||
import appeng.client.render.model.CachingRotatingBakedModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public final class AETileBlockFeatureHandler implements IFeatureHandler
|
||||
{
|
||||
private final AEBaseTileBlock featured;
|
||||
private final FeatureNameExtractor extractor;
|
||||
private final boolean enabled;
|
||||
private final TileDefinition definition;
|
||||
|
||||
private ResourceLocation registryName;
|
||||
|
||||
public AETileBlockFeatureHandler( final EnumSet<AEFeature> features, final AEBaseTileBlock featured, final Optional<String> subName )
|
||||
{
|
||||
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
||||
|
||||
this.featured = featured;
|
||||
this.extractor = new FeatureNameExtractor( featured.getClass(), subName );
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
this.definition = new TileDefinition( featured.getClass().getSimpleName(), featured, state );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFeatureAvailable()
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDefinition getDefinition()
|
||||
{
|
||||
return this.definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register( final Side side )
|
||||
{
|
||||
if( this.enabled )
|
||||
{
|
||||
String name = this.extractor.get();
|
||||
if( Item.REGISTRY.containsKey( new ResourceLocation( AppEng.MOD_ID, name ) ) )
|
||||
{
|
||||
name += "_block";
|
||||
}
|
||||
this.featured.setCreativeTab( CreativeTab.instance );
|
||||
this.featured.setUnlocalizedName( "appliedenergistics2." + name );
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
CommonHelper.proxy.bindTileEntitySpecialRenderer( this.featured.getTileEntityClass(), this.featured );
|
||||
}
|
||||
|
||||
registryName = new ResourceLocation( AppEng.MOD_ID, name );
|
||||
|
||||
GameRegistry.register( this.featured.setRegistryName( registryName ) );
|
||||
GameRegistry.register( this.definition.maybeItem().get().setRegistryName( registryName ) );
|
||||
AEBaseTile.registerTileItem( this.featured.getTileEntityClass(), new BlockStackSrc( this.featured, 0, ActivityState.from( this.isFeatureAvailable() ) ) );
|
||||
|
||||
GameRegistry.registerTileEntityWithAlternatives( this.featured.getTileEntityClass(), this.featured.toString() );
|
||||
|
||||
if( side == Side.CLIENT )
|
||||
{
|
||||
TileEntitySpecialRenderer tesr = this.featured.getTESR();
|
||||
ModelBakery.registerItemVariants( this.definition.maybeItem().get(), registryName );
|
||||
if( tesr != null )
|
||||
{
|
||||
ClientRegistry.bindTileEntitySpecialRenderer( this.featured.getTileEntityClass(), tesr );
|
||||
if( this.featured.hasItemTESR() )
|
||||
{
|
||||
ForgeHooksClient.registerTESRItemStack( this.definition.maybeItem().get(), 0, this.featured.getTileEntityClass() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel()
|
||||
{
|
||||
ItemModelMesher itemModelMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
|
||||
Item item = this.definition.maybeItem().get();
|
||||
ItemMeshDefinition itemMeshDefinition = featured.getItemMeshDefinition();
|
||||
|
||||
if( itemMeshDefinition != null )
|
||||
{
|
||||
// This block has a custom item mesh definition, so register it instead of the resource location
|
||||
itemModelMesher.register( item, itemMeshDefinition );
|
||||
}
|
||||
else if( !featured.getBlockState().getProperties().isEmpty() || featured instanceof IHasSpecialItemModel )
|
||||
{
|
||||
itemModelMesher.register( item, 0, new ModelResourceLocation( registryName, "inventory" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
itemModelMesher.register( item, 0, new ModelResourceLocation( registryName, "normal" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper()
|
||||
{
|
||||
AEIgnoringStateMapper mapper = new AEIgnoringStateMapper( registryName );
|
||||
ModelLoader.setCustomStateMapper( this.featured, mapper );
|
||||
( (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager() ).registerReloadListener( mapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCustomModelOverride( IRegistry<ModelResourceLocation, IBakedModel> modelRegistry )
|
||||
{
|
||||
Set<ModelResourceLocation> keys = Sets.newHashSet( modelRegistry.getKeys() );
|
||||
for( ModelResourceLocation model : keys )
|
||||
{
|
||||
if( model.getResourceDomain().equals( registryName.getResourceDomain() ) && model.getResourcePath().equals( registryName.getResourcePath() ) )
|
||||
{
|
||||
modelRegistry.putObject( model, new CachingRotatingBakedModel( modelRegistry.getObject( model ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,111 +19,26 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.block.AEBaseBlock;
|
||||
|
||||
|
||||
public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
{
|
||||
private static final ItemBlockTransformer ITEMBLOCK_TRANSFORMER = new ItemBlockTransformer();
|
||||
private final Optional<Block> block;
|
||||
|
||||
public BlockDefinition( final String identifier, final Block block, final ActivityState state )
|
||||
public BlockDefinition( String registryName, Block block, ItemBlock item )
|
||||
{
|
||||
super( identifier, constructItemFromBlock( block ), state );
|
||||
|
||||
Preconditions.checkNotNull( block );
|
||||
Preconditions.checkNotNull( state );
|
||||
|
||||
if( state == ActivityState.Enabled )
|
||||
{
|
||||
this.block = Optional.of( block );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.block = Optional.absent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link ItemBlock} from a {@link Block} to register it later as {@link Item}
|
||||
*
|
||||
* @param block source block
|
||||
*
|
||||
* @return item from block
|
||||
*/
|
||||
private static Item constructItemFromBlock( final Block block )
|
||||
{
|
||||
final Class<? extends ItemBlock> itemclass = getItemBlockConstructor( block );
|
||||
return constructItemBlock( block, itemclass );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructor to use.
|
||||
*
|
||||
* Either {@link ItemBlock} or in case of an {@link AEBaseBlock} the class returned by
|
||||
* AEBaseBlock.getItemBlockClass().
|
||||
*
|
||||
* @param block the block used to determine the used constructor.
|
||||
*
|
||||
* @return a {@link Class} extending ItemBlock
|
||||
*/
|
||||
private static Class<? extends ItemBlock> getItemBlockConstructor( final Block block )
|
||||
{
|
||||
if( block instanceof AEBaseBlock )
|
||||
{
|
||||
final AEBaseBlock aeBaseBlock = (AEBaseBlock) block;
|
||||
return aeBaseBlock.getItemBlockClass();
|
||||
}
|
||||
|
||||
return ItemBlock.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually construct an instance of {@link Item} with the block and earlier determined constructor.
|
||||
*
|
||||
* Shamelessly stolen from the forge magic.
|
||||
*
|
||||
* TODO: throw an exception instead of returning null? As this could cause issue later on.
|
||||
*
|
||||
* @param block the block to create the {@link ItemBlock} from
|
||||
* @param itemclass the class used to construct it.
|
||||
*
|
||||
* @return an {@link Item} for the block. Actually always a sub type of {@link ItemBlock}
|
||||
*/
|
||||
private static Item constructItemBlock( final Block block, final Class<? extends ItemBlock> itemclass )
|
||||
{
|
||||
try
|
||||
{
|
||||
final Object[] itemCtorArgs = {};
|
||||
final Class<?>[] ctorArgClasses = new Class<?>[itemCtorArgs.length + 1];
|
||||
ctorArgClasses[0] = Block.class;
|
||||
for( int idx = 1; idx < ctorArgClasses.length; idx++ )
|
||||
{
|
||||
ctorArgClasses[idx] = itemCtorArgs[idx - 1].getClass();
|
||||
}
|
||||
|
||||
final Constructor<? extends ItemBlock> itemCtor = itemclass.getConstructor( ctorArgClasses );
|
||||
return itemCtor.newInstance( ObjectArrays.concat( block, itemCtorArgs ) );
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
super( registryName, item );
|
||||
this.block = Optional.fromNullable( block );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,13 +50,15 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
@Override
|
||||
public final Optional<ItemBlock> maybeItemBlock()
|
||||
{
|
||||
return this.block.transform( ITEMBLOCK_TRANSFORMER );
|
||||
return this.block.transform( ItemBlock::new );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Optional<ItemStack> maybeStack( final int stackSize )
|
||||
public final Optional<ItemStack> maybeStack( int stackSize )
|
||||
{
|
||||
return this.block.transform( new ItemStackTransformer( stackSize ) );
|
||||
Preconditions.checkArgument( stackSize > 0 );
|
||||
|
||||
return this.block.transform( b -> new ItemStack( b, stackSize ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,31 +66,4 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
{
|
||||
return this.isEnabled() && world.getBlockState( pos ).getBlock() == this.block.get();
|
||||
}
|
||||
|
||||
private static class ItemBlockTransformer implements Function<Block, ItemBlock>
|
||||
{
|
||||
@Override
|
||||
public ItemBlock apply( final Block input )
|
||||
{
|
||||
return new ItemBlock( input );
|
||||
}
|
||||
}
|
||||
|
||||
private static class ItemStackTransformer implements Function<Block, ItemStack>
|
||||
{
|
||||
private final int stackSize;
|
||||
|
||||
public ItemStackTransformer( final int stackSize )
|
||||
{
|
||||
Preconditions.checkArgument( stackSize > 0 );
|
||||
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack apply( final Block input )
|
||||
{
|
||||
return new ItemStack( input, this.stackSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
|
||||
public class FeatureNameExtractor
|
||||
{
|
||||
private static final Pattern PATTERN_ITEM_MULTI_PART = Pattern.compile( "ItemMultiPart", Pattern.LITERAL );
|
||||
private static final Pattern PATTERN_ITEM_MULTI_MATERIAL = Pattern.compile( "ItemMultiMaterial", Pattern.LITERAL );
|
||||
private static final Pattern PATTERN_QUARTZ = Pattern.compile( "Quartz", Pattern.LITERAL );
|
||||
|
||||
private static final Pattern PATTERN_LOWERCASE = Pattern.compile( "([\\p{Upper}])([\\p{Upper}]+)" );
|
||||
private static final Pattern PATTERN_LOWERCASER = Pattern.compile( "(.)?([\\p{Upper}])" );
|
||||
|
||||
private final Class<?> clazz;
|
||||
private final Optional<String> subName;
|
||||
|
||||
public FeatureNameExtractor( final Class<?> clazz, final Optional<String> subName )
|
||||
{
|
||||
this.clazz = clazz;
|
||||
this.subName = subName;
|
||||
}
|
||||
|
||||
public String get()
|
||||
{
|
||||
String ret;
|
||||
String name = this.clazz.getSimpleName().replaceFirst( "\\p{Upper}[\\p{Lower}]*(\\p{Upper})", "$1" );
|
||||
|
||||
if( this.subName.isPresent() )
|
||||
{
|
||||
final String subName = this.subName.get();
|
||||
// simple hack to allow me to do get nice names for these without
|
||||
// mode code outside of AEBaseItem
|
||||
if( subName.startsWith( "P2PTunnel" ) )
|
||||
{
|
||||
ret = "p2ptunnel";
|
||||
}
|
||||
else if( subName.equals( "CertusQuartzTools" ) )
|
||||
{
|
||||
ret = PATTERN_QUARTZ.matcher( name ).replaceAll( "CertusQuartz" );
|
||||
}
|
||||
else if( subName.equals( "NetherQuartzTools" ) )
|
||||
{
|
||||
ret = PATTERN_QUARTZ.matcher( name ).replaceAll( "NetherQuartz" );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = name + '_' + subName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = name;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Matcher m = PATTERN_LOWERCASE.matcher( ret );
|
||||
while( m.find() )
|
||||
{
|
||||
m.appendReplacement( buffer, m.group( 1 ) + m.group( 2 ).toLowerCase() );
|
||||
}
|
||||
m.appendTail( buffer );
|
||||
m = PATTERN_LOWERCASER.matcher( buffer.toString() );
|
||||
buffer = new StringBuffer();
|
||||
while( m.find() )
|
||||
{
|
||||
m.appendReplacement( buffer, ( m.group( 1 ) != null ? m.group( 1 ) + '_' : "" ) + m.group( 2 ).toLowerCase() );
|
||||
}
|
||||
m.appendTail( buffer );
|
||||
ret = buffer.toString().replace( '.', '_' ).replaceAll( "_+", "_" );
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.core.AEConfig;
|
||||
|
||||
|
||||
public final class FeaturedActiveChecker
|
||||
{
|
||||
private final Set<AEFeature> features;
|
||||
|
||||
public FeaturedActiveChecker( final Set<AEFeature> features )
|
||||
{
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
ActivityState getActivityState()
|
||||
{
|
||||
for( final AEFeature f : this.features )
|
||||
{
|
||||
if( !AEConfig.instance.isFeatureEnabled( f ) )
|
||||
{
|
||||
return ActivityState.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
return ActivityState.Enabled;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
public interface IAEFeature
|
||||
{
|
||||
IFeatureHandler handler();
|
||||
|
||||
void postInit();
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
|
||||
|
||||
public interface IFeatureHandler
|
||||
{
|
||||
boolean isFeatureAvailable();
|
||||
|
||||
IItemDefinition getDefinition();
|
||||
|
||||
void register( Side side );
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
void registerModel();
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
void registerStateMapper();
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
void registerCustomModelOverride( IRegistry<ModelResourceLocation, IBakedModel> modelRegistry );
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import javax.annotation.Nonnull;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -37,21 +38,11 @@ public class ItemDefinition implements IItemDefinition
|
||||
private final String identifier;
|
||||
private final Optional<Item> item;
|
||||
|
||||
public ItemDefinition( final String identifier, final Item item, final ActivityState state )
|
||||
public ItemDefinition( String registryName, Item item )
|
||||
{
|
||||
this.identifier = Preconditions.checkNotNull( identifier );
|
||||
Preconditions.checkArgument( !identifier.isEmpty() );
|
||||
Preconditions.checkNotNull( item );
|
||||
Preconditions.checkNotNull( state );
|
||||
|
||||
if( state == ActivityState.Enabled )
|
||||
{
|
||||
this.item = Optional.of( item );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.item = Optional.absent();
|
||||
}
|
||||
Preconditions.checkArgument( !Strings.isNullOrEmpty( registryName ), "registryName" );
|
||||
this.identifier = registryName;
|
||||
this.item = Optional.fromNullable( item );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.IRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.CreativeTabFacade;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.items.parts.ItemFacade;
|
||||
|
||||
|
||||
public final class ItemFeatureHandler implements IFeatureHandler
|
||||
{
|
||||
private final Item item;
|
||||
private final FeatureNameExtractor extractor;
|
||||
private final boolean enabled;
|
||||
private final ItemDefinition definition;
|
||||
|
||||
private ResourceLocation registryName;
|
||||
|
||||
public ItemFeatureHandler( final EnumSet<AEFeature> features, final Item item, final IAEFeature featured, final Optional<String> subName )
|
||||
{
|
||||
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
||||
|
||||
this.item = item;
|
||||
this.extractor = new FeatureNameExtractor( featured.getClass(), subName );
|
||||
this.enabled = state == ActivityState.Enabled;
|
||||
this.definition = new ItemDefinition( item.getClass().getSimpleName(), item, state );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFeatureAvailable()
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition getDefinition()
|
||||
{
|
||||
return this.definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register( final Side side )
|
||||
{
|
||||
if( this.enabled )
|
||||
{
|
||||
String name = this.extractor.get();
|
||||
if( Item.REGISTRY.containsKey( new ResourceLocation( AppEng.MOD_ID, name ) ) )
|
||||
{
|
||||
name += "_item";
|
||||
}
|
||||
|
||||
// this.item.setTextureName( "appliedenergistics2:" + name );
|
||||
this.item.setUnlocalizedName( "appliedenergistics2." + name );
|
||||
|
||||
if( this.item instanceof ItemFacade )
|
||||
{
|
||||
this.item.setCreativeTab( CreativeTabFacade.instance );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.item.setCreativeTab( CreativeTab.instance );
|
||||
}
|
||||
|
||||
registryName = new ResourceLocation( AppEng.MOD_ID, name );
|
||||
GameRegistry.register( this.item.setRegistryName( registryName ) );
|
||||
|
||||
if( side == Side.CLIENT )
|
||||
{
|
||||
if( item instanceof AEBaseItem )
|
||||
{
|
||||
AEBaseItem baseItem = (AEBaseItem) item;
|
||||
|
||||
// Handle registration of item variants
|
||||
ResourceLocation[] variants = baseItem.getItemVariants().toArray( new ResourceLocation[0] );
|
||||
ModelBakery.registerItemVariants( item, variants );
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelBakery.registerItemVariants( item, registryName );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel()
|
||||
{
|
||||
ItemMeshDefinition meshDefinition = null;
|
||||
|
||||
// Register a custom item model handler if the item wants one
|
||||
if( item instanceof AEBaseItem )
|
||||
{
|
||||
AEBaseItem baseItem = (AEBaseItem) item;
|
||||
meshDefinition = baseItem.getItemMeshDefinition();
|
||||
}
|
||||
|
||||
if( meshDefinition != null )
|
||||
{
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( item, meshDefinition );
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( item, 0, new ModelResourceLocation( registryName, "inventory" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCustomModelOverride( IRegistry<ModelResourceLocation, IBakedModel> modelRegistry )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,9 @@ package appeng.core.features;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
@@ -33,39 +32,18 @@ import appeng.block.AEBaseTileBlock;
|
||||
|
||||
public final class TileDefinition extends BlockDefinition implements ITileDefinition
|
||||
{
|
||||
private static final TileEntityTransformer TILEENTITY_TRANSFORMER = new TileEntityTransformer();
|
||||
|
||||
private final Optional<AEBaseTileBlock> block;
|
||||
|
||||
public TileDefinition( @Nonnull final String identifier, final AEBaseTileBlock block, final ActivityState state )
|
||||
public TileDefinition( @Nonnull String registryName, AEBaseTileBlock block, ItemBlock item )
|
||||
{
|
||||
super( identifier, block, state );
|
||||
|
||||
Preconditions.checkNotNull( block );
|
||||
|
||||
if( state == ActivityState.Enabled )
|
||||
{
|
||||
this.block = Optional.of( block );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.block = Optional.absent();
|
||||
}
|
||||
super( registryName, block, item );
|
||||
this.block = Optional.fromNullable( block );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Class<? extends TileEntity>> maybeEntity()
|
||||
{
|
||||
return this.block.transform( TILEENTITY_TRANSFORMER );
|
||||
}
|
||||
|
||||
private static class TileEntityTransformer implements Function<AEBaseTileBlock, Class<? extends TileEntity>>
|
||||
{
|
||||
@Override
|
||||
public Class<? extends TileEntity> apply( final AEBaseTileBlock input )
|
||||
{
|
||||
final Class<? extends TileEntity> entity = input.getTileEntityClass();
|
||||
|
||||
return entity;
|
||||
}
|
||||
return this.block.transform( AEBaseTileBlock::getTileEntityClass );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user