pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -28,7 +27,6 @@ import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.core.AEItemGroup;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -37,203 +35,176 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.block.AEBaseBlockItem;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.IBlockRegistrationComponent;
|
||||
import appeng.bootstrap.components.IItemRegistrationComponent;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AEItemGroup;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.features.BlockDefinition;
|
||||
import appeng.core.features.TileDefinition;
|
||||
import appeng.util.Platform;
|
||||
|
||||
class BlockDefinitionBuilder implements IBlockBuilder {
|
||||
|
||||
class BlockDefinitionBuilder implements IBlockBuilder
|
||||
{
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final FeatureFactory factory;
|
||||
private final String registryName;
|
||||
|
||||
private final String registryName;
|
||||
private final Supplier<? extends Block> blockSupplier;
|
||||
|
||||
private final Supplier<? extends Block> blockSupplier;
|
||||
private final List<BiFunction<Block, Item, IBootstrapComponent>> bootstrapComponents = new ArrayList<>();
|
||||
|
||||
private final List<BiFunction<Block, Item, IBootstrapComponent>> bootstrapComponents = new ArrayList<>();
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf( AEFeature.class );
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
private boolean disableItem = false;
|
||||
|
||||
private boolean disableItem = false;
|
||||
private BiFunction<Block, Item.Properties, BlockItem> itemFactory;
|
||||
|
||||
private BiFunction<Block, Item.Properties, BlockItem> itemFactory;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private BlockRendering blockRendering;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private BlockRendering blockRendering;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private ItemRendering itemRendering;
|
||||
BlockDefinitionBuilder(FeatureFactory factory, String id, Supplier<? extends Block> blockSupplier) {
|
||||
this.factory = factory;
|
||||
this.registryName = id;
|
||||
this.blockSupplier = blockSupplier;
|
||||
|
||||
BlockDefinitionBuilder( FeatureFactory factory, String id, Supplier<? extends Block> blockSupplier )
|
||||
{
|
||||
this.factory = factory;
|
||||
this.registryName = id;
|
||||
this.blockSupplier = blockSupplier;
|
||||
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.blockRendering = new BlockRendering();
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder bootstrap( BiFunction<Block, Item, IBootstrapComponent> callback )
|
||||
{
|
||||
this.bootstrapComponents.add( callback );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder features( AEFeature... features )
|
||||
{
|
||||
this.features.clear();
|
||||
this.addFeatures( features );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder addFeatures( AEFeature... features )
|
||||
{
|
||||
Collections.addAll( this.features, features );
|
||||
return this;
|
||||
}
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.blockRendering = new BlockRendering();
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder rendering( BlockRenderingCustomizer callback )
|
||||
{
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.customizeForClient( callback );
|
||||
}
|
||||
public BlockDefinitionBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> callback) {
|
||||
this.bootstrapComponents.add(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder tileEntity( TileEntityDefinition tileEntityDefinition )
|
||||
{
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder item( BiFunction<Block, Item.Properties, BlockItem> factory )
|
||||
{
|
||||
this.itemFactory = factory;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public BlockDefinitionBuilder rendering(BlockRenderingCustomizer callback) {
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder disableItem()
|
||||
{
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private void customizeForClient( BlockRenderingCustomizer callback )
|
||||
{
|
||||
callback.customize( this.blockRendering, this.itemRendering );
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition) {
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Override
|
||||
public <T extends IBlockDefinition> T build()
|
||||
{
|
||||
// Create block and matching item, and set factory name of both
|
||||
Block block = this.blockSupplier.get();
|
||||
block.setRegistryName( AppEng.MOD_ID, this.registryName );
|
||||
@Override
|
||||
public IBlockBuilder item(BiFunction<Block, Item.Properties, BlockItem> factory) {
|
||||
this.itemFactory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockItem item = this.constructItemFromBlock( block );
|
||||
if( item != null )
|
||||
{
|
||||
item.setRegistryName( AppEng.MOD_ID, this.registryName );
|
||||
}
|
||||
@Override
|
||||
public IBlockBuilder disableItem() {
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Register the item and block with the game
|
||||
this.factory.addBootstrapComponent( (IBlockRegistrationComponent) ( side, registry ) -> registry.register( block ) );
|
||||
if( item != null )
|
||||
{
|
||||
this.factory.addBootstrapComponent( (IItemRegistrationComponent) ( side, registry ) -> registry.register( item ) );
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void customizeForClient(BlockRenderingCustomizer callback) {
|
||||
callback.customize(this.blockRendering, this.itemRendering);
|
||||
}
|
||||
|
||||
// Register all extra handlers
|
||||
this.bootstrapComponents.forEach( component -> this.factory.addBootstrapComponent( component.apply( block, item ) ) );
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends IBlockDefinition> T build() {
|
||||
// Create block and matching item, and set factory name of both
|
||||
Block block = this.blockSupplier.get();
|
||||
block.setRegistryName(AppEng.MOD_ID, this.registryName);
|
||||
|
||||
if (this.tileEntityDefinition != null)
|
||||
{
|
||||
// Tell the tile entity definition about the block we've registered
|
||||
this.tileEntityDefinition.addBlock(block);
|
||||
}
|
||||
BlockItem item = this.constructItemFromBlock(block);
|
||||
if (item != null) {
|
||||
item.setRegistryName(AppEng.MOD_ID, this.registryName);
|
||||
}
|
||||
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.blockRendering.apply( this.factory, block );
|
||||
// Register the item and block with the game
|
||||
this.factory.addBootstrapComponent((IBlockRegistrationComponent) (side, registry) -> registry.register(block));
|
||||
if (item != null) {
|
||||
this.factory
|
||||
.addBootstrapComponent((IItemRegistrationComponent) (side, registry) -> registry.register(item));
|
||||
}
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
this.itemRendering.apply( this.factory, item );
|
||||
}
|
||||
}
|
||||
// Register all extra handlers
|
||||
this.bootstrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(block, item)));
|
||||
|
||||
T definition;
|
||||
if( block instanceof AEBaseTileBlock )
|
||||
{
|
||||
definition = (T) new TileDefinition( this.registryName, (AEBaseTileBlock<?>) block, item, features );
|
||||
}
|
||||
else
|
||||
{
|
||||
definition = (T) new BlockDefinition( this.registryName, block, item, features );
|
||||
}
|
||||
if (this.tileEntityDefinition != null) {
|
||||
// Tell the tile entity definition about the block we've registered
|
||||
this.tileEntityDefinition.addBlock(block);
|
||||
}
|
||||
|
||||
if (itemGroup instanceof AEItemGroup) {
|
||||
((AEItemGroup) itemGroup).add(definition);
|
||||
}
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.blockRendering.apply(this.factory, block);
|
||||
|
||||
return definition;
|
||||
}
|
||||
if (item != null) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BlockItem constructItemFromBlock( Block block )
|
||||
{
|
||||
if( this.disableItem )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T definition;
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
definition = (T) new TileDefinition(this.registryName, (AEBaseTileBlock<?>) block, item, features);
|
||||
} else {
|
||||
definition = (T) new BlockDefinition(this.registryName, block, item, features);
|
||||
}
|
||||
|
||||
Item.Properties itemProperties = new Item.Properties();
|
||||
if (itemGroup instanceof AEItemGroup) {
|
||||
((AEItemGroup) itemGroup).add(definition);
|
||||
}
|
||||
|
||||
if (itemGroup != null) {
|
||||
itemProperties.group(itemGroup);
|
||||
}
|
||||
// FIXME: Allow more/all item properties
|
||||
return definition;
|
||||
}
|
||||
|
||||
if( this.itemFactory != null )
|
||||
{
|
||||
return this.itemFactory.apply( block, itemProperties );
|
||||
}
|
||||
else if( block instanceof AEBaseBlock )
|
||||
{
|
||||
return new AEBaseBlockItem( block, itemProperties );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BlockItem( block, itemProperties );
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
private BlockItem constructItemFromBlock(Block block) {
|
||||
if (this.disableItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Item.Properties itemProperties = new Item.Properties();
|
||||
|
||||
if (itemGroup != null) {
|
||||
itemProperties.group(itemGroup);
|
||||
}
|
||||
// FIXME: Allow more/all item properties
|
||||
|
||||
if (this.itemFactory != null) {
|
||||
return this.itemFactory.apply(block, itemProperties);
|
||||
} else if (block instanceof AEBaseBlock) {
|
||||
return new AEBaseBlockItem(block, itemProperties);
|
||||
} else {
|
||||
return new BlockItem(block, itemProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockColorComponent;
|
||||
import appeng.bootstrap.components.RenderTypeComponent;
|
||||
import appeng.client.render.model.AutoRotatingBakedModel;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
@@ -35,74 +33,68 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockColorComponent;
|
||||
import appeng.bootstrap.components.RenderTypeComponent;
|
||||
import appeng.client.render.model.AutoRotatingBakedModel;
|
||||
|
||||
class BlockRendering implements IBlockRendering {
|
||||
|
||||
class BlockRendering implements IBlockRendering
|
||||
{
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private BiFunction<ResourceLocation, IBakedModel, IBakedModel> modelCustomizer;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private BiFunction<ResourceLocation, IBakedModel, IBakedModel> modelCustomizer;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private IBlockColor blockColor;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private IBlockColor blockColor;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private RenderType renderType;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private RenderType renderType;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private Predicate<RenderType> renderTypes;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private Predicate<RenderType> renderTypes;
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public IBlockRendering modelCustomizer(BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer) {
|
||||
this.modelCustomizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public IBlockRendering modelCustomizer( BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer )
|
||||
{
|
||||
this.modelCustomizer = customizer;
|
||||
return this;
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public IBlockRendering blockColor(IBlockColor blockColor) {
|
||||
this.blockColor = blockColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
@Override
|
||||
public IBlockRendering blockColor( IBlockColor blockColor )
|
||||
{
|
||||
this.blockColor = blockColor;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockRendering renderType(RenderType type) {
|
||||
this.renderType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockRendering renderType(RenderType type) {
|
||||
this.renderType = type;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IBlockRendering renderType(Predicate<RenderType> typePredicate) {
|
||||
this.renderTypes = typePredicate;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockRendering renderType(Predicate<RenderType> typePredicate) {
|
||||
this.renderTypes = typePredicate;
|
||||
return this;
|
||||
}
|
||||
void apply(FeatureFactory factory, Block block) {
|
||||
if (this.modelCustomizer != null) {
|
||||
factory.addModelOverride(block.getRegistryName().getPath(), this.modelCustomizer);
|
||||
} else if (block instanceof AEBaseTileBlock) {
|
||||
// This is a default rotating model if the base-block uses an AE tile entity
|
||||
// which exposes UP/FRONT as
|
||||
// extended props
|
||||
factory.addModelOverride(block.getRegistryName().getPath(), (l, m) -> new AutoRotatingBakedModel(m));
|
||||
}
|
||||
|
||||
void apply( FeatureFactory factory, Block block )
|
||||
{
|
||||
if( this.modelCustomizer != null )
|
||||
{
|
||||
factory.addModelOverride( block.getRegistryName().getPath(), this.modelCustomizer );
|
||||
}
|
||||
else if( block instanceof AEBaseTileBlock )
|
||||
{
|
||||
// This is a default rotating model if the base-block uses an AE tile entity which exposes UP/FRONT as
|
||||
// extended props
|
||||
factory.addModelOverride( block.getRegistryName().getPath(), ( l, m ) -> new AutoRotatingBakedModel( m ) );
|
||||
}
|
||||
// TODO : 1.12
|
||||
if (this.blockColor != null) {
|
||||
factory.addBootstrapComponent(new BlockColorComponent(block, this.blockColor));
|
||||
}
|
||||
|
||||
// TODO : 1.12
|
||||
if( this.blockColor != null )
|
||||
{
|
||||
factory.addBootstrapComponent( new BlockColorComponent( block, this.blockColor ) );
|
||||
}
|
||||
|
||||
if (this.renderType != null || this.renderTypes != null) {
|
||||
factory.addBootstrapComponent( new RenderTypeComponent( block, this.renderType, this.renderTypes));
|
||||
}
|
||||
}
|
||||
if (this.renderType != null || this.renderTypes != null) {
|
||||
factory.addBootstrapComponent(new RenderTypeComponent(block, this.renderType, this.renderTypes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,17 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
/**
|
||||
* A callback that allows the rendering of a block to be customized. Sadly this class is required and no lambdas can be
|
||||
* used
|
||||
* due to them not being able to be annotated with @OnlyIn(CLIENT).
|
||||
* A callback that allows the rendering of a block to be customized. Sadly this
|
||||
* class is required and no lambdas can be used due to them not being able to be
|
||||
* annotated with @OnlyIn(CLIENT).
|
||||
*/
|
||||
public abstract class BlockRenderingCustomizer
|
||||
{
|
||||
public abstract class BlockRenderingCustomizer {
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public abstract void customize( IBlockRendering rendering, IItemRendering itemRendering );
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract void customize(IBlockRendering rendering, IItemRendering itemRendering);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.IClientSetupComponent;
|
||||
import appeng.bootstrap.components.IEntityRegistrationComponent;
|
||||
@@ -8,16 +19,6 @@ import appeng.entity.EntityFloatingItem;
|
||||
import appeng.entity.EntityTinyTNTPrimed;
|
||||
import appeng.entity.RenderFloatingItem;
|
||||
import appeng.entity.RenderTinyTNTPrimed;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Helper to register a custom Entity with Minecraft.
|
||||
@@ -32,7 +33,8 @@ public class EntityBuilder<T extends Entity> {
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
public EntityBuilder(FeatureFactory factory, String id, EntityType.IFactory<T> entityFactory, EntityClassification classification) {
|
||||
public EntityBuilder(FeatureFactory factory, String id, EntityType.IFactory<T> entityFactory,
|
||||
EntityClassification classification) {
|
||||
this.factory = factory;
|
||||
this.id = id;
|
||||
this.builder = EntityType.Builder.create(entityFactory, classification);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -30,8 +29,6 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import appeng.bootstrap.components.ModelOverrideComponent;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
||||
@@ -45,86 +42,75 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.ModelOverrideComponent;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class FeatureFactory {
|
||||
|
||||
public class FeatureFactory
|
||||
{
|
||||
private final AEFeature[] defaultFeatures;
|
||||
|
||||
private final AEFeature[] defaultFeatures;
|
||||
private final Map<Class<? extends IBootstrapComponent>, List<IBootstrapComponent>> bootstrapComponents;
|
||||
|
||||
private final Map<Class<? extends IBootstrapComponent>, List<IBootstrapComponent>> bootstrapComponents;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private ModelOverrideComponent modelOverrideComponent;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private ModelOverrideComponent modelOverrideComponent;
|
||||
public FeatureFactory() {
|
||||
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
|
||||
this.bootstrapComponents = new HashMap<>();
|
||||
|
||||
public FeatureFactory()
|
||||
{
|
||||
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
|
||||
this.bootstrapComponents = new HashMap<>();
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.modelOverrideComponent = new ModelOverrideComponent();
|
||||
this.addBootstrapComponent(this.modelOverrideComponent);
|
||||
}
|
||||
}
|
||||
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.modelOverrideComponent = new ModelOverrideComponent();
|
||||
this.addBootstrapComponent( this.modelOverrideComponent );
|
||||
}
|
||||
}
|
||||
private FeatureFactory(FeatureFactory parent, AEFeature... defaultFeatures) {
|
||||
this.defaultFeatures = defaultFeatures.clone();
|
||||
this.bootstrapComponents = parent.bootstrapComponents;
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.modelOverrideComponent = parent.modelOverrideComponent;
|
||||
}
|
||||
}
|
||||
|
||||
private FeatureFactory( FeatureFactory parent, AEFeature... defaultFeatures )
|
||||
{
|
||||
this.defaultFeatures = defaultFeatures.clone();
|
||||
this.bootstrapComponents = parent.bootstrapComponents;
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.modelOverrideComponent = parent.modelOverrideComponent;
|
||||
}
|
||||
}
|
||||
public IBlockBuilder block(String id, Supplier<Block> block) {
|
||||
return new BlockDefinitionBuilder(this, id, block).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public IBlockBuilder block( String id, Supplier<Block> block )
|
||||
{
|
||||
return new BlockDefinitionBuilder( this, id, block ).features( this.defaultFeatures );
|
||||
}
|
||||
public IItemBuilder item(String id, Function<Item.Properties, Item> itemFactory) {
|
||||
return new ItemDefinitionBuilder(this, id, itemFactory).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public IItemBuilder item( String id, Function<Item.Properties, Item> itemFactory )
|
||||
{
|
||||
return new ItemDefinitionBuilder( this, id, itemFactory ).features( this.defaultFeatures );
|
||||
}
|
||||
public <T extends Entity> EntityBuilder<T> entity(String id, EntityType.IFactory<T> factory,
|
||||
EntityClassification classification) {
|
||||
return new EntityBuilder<T>(this, id, factory, classification).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public <T extends Entity> EntityBuilder<T> entity(String id, EntityType.IFactory<T> factory, EntityClassification classification)
|
||||
{
|
||||
return new EntityBuilder<T>( this, id, factory, classification ).features( this.defaultFeatures );
|
||||
}
|
||||
public <T extends AEBaseTile> TileEntityBuilder<T> tileEntity(String id, Class<T> teClass,
|
||||
Function<TileEntityType<T>, T> factory) {
|
||||
return new TileEntityBuilder<>(this, id, teClass, factory).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public <T extends AEBaseTile> TileEntityBuilder<T> tileEntity(String id, Class<T> teClass, Function<TileEntityType<T>, T> factory)
|
||||
{
|
||||
return new TileEntityBuilder<>( this, id, teClass, factory ).features( this.defaultFeatures );
|
||||
}
|
||||
public FeatureFactory features(AEFeature... features) {
|
||||
return new FeatureFactory(this, features);
|
||||
}
|
||||
|
||||
public FeatureFactory features( AEFeature... features )
|
||||
{
|
||||
return new FeatureFactory( this, features );
|
||||
}
|
||||
public void addBootstrapComponent(IBootstrapComponent component) {
|
||||
Arrays.stream(component.getClass().getInterfaces()).filter(i -> IBootstrapComponent.class.isAssignableFrom(i))
|
||||
.forEach(i -> this.addBootstrapComponent((Class<? extends IBootstrapComponent>) i, component));
|
||||
}
|
||||
|
||||
public void addBootstrapComponent( IBootstrapComponent component )
|
||||
{
|
||||
Arrays.stream( component.getClass().getInterfaces() )
|
||||
.filter( i -> IBootstrapComponent.class.isAssignableFrom( i ) )
|
||||
.forEach( i -> this.addBootstrapComponent( (Class<? extends IBootstrapComponent>) i, component ) );
|
||||
}
|
||||
private <T extends IBootstrapComponent> void addBootstrapComponent(Class<? extends IBootstrapComponent> eventType,
|
||||
T component) {
|
||||
this.bootstrapComponents.computeIfAbsent(eventType, c -> new ArrayList<IBootstrapComponent>()).add(component);
|
||||
}
|
||||
|
||||
private <T extends IBootstrapComponent> void addBootstrapComponent( Class<? extends IBootstrapComponent> eventType, T component )
|
||||
{
|
||||
this.bootstrapComponents.computeIfAbsent( eventType, c -> new ArrayList<IBootstrapComponent>() ).add( component );
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
void addModelOverride(String resourcePath, BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer) {
|
||||
this.modelOverrideComponent.addOverride(resourcePath, customizer);
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
void addModelOverride( String resourcePath, BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer )
|
||||
{
|
||||
this.modelOverrideComponent.addOverride( resourcePath, customizer );
|
||||
}
|
||||
|
||||
public <T extends IBootstrapComponent> Iterator<T> getBootstrapComponents( Class<T> eventType )
|
||||
{
|
||||
return (Iterator<T>) this.bootstrapComponents.getOrDefault( eventType, Collections.emptyList() ).iterator();
|
||||
}
|
||||
public <T extends IBootstrapComponent> Iterator<T> getBootstrapComponents(Class<T> eventType) {
|
||||
return (Iterator<T>) this.bootstrapComponents.getOrDefault(eventType, Collections.emptyList()).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -26,28 +25,26 @@ import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
|
||||
public interface IBlockBuilder {
|
||||
IBlockBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> component);
|
||||
|
||||
public interface IBlockBuilder
|
||||
{
|
||||
IBlockBuilder bootstrap( BiFunction<Block, Item, IBootstrapComponent> component );
|
||||
IBlockBuilder features(AEFeature... features);
|
||||
|
||||
IBlockBuilder features( AEFeature... features );
|
||||
IBlockBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IBlockBuilder addFeatures( AEFeature... features );
|
||||
IBlockBuilder rendering(BlockRenderingCustomizer callback);
|
||||
|
||||
IBlockBuilder rendering( BlockRenderingCustomizer callback );
|
||||
IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition);
|
||||
|
||||
IBlockBuilder tileEntity( TileEntityDefinition tileEntityDefinition );
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
IBlockBuilder item(BiFunction<Block, Item.Properties, BlockItem> factory);
|
||||
|
||||
IBlockBuilder item( BiFunction<Block, Item.Properties, BlockItem> factory );
|
||||
|
||||
<T extends IBlockDefinition> T build();
|
||||
<T extends IBlockDefinition> T build();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
@@ -34,23 +33,22 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
/**
|
||||
* Allows for client-side rendering to be customized in the context of block/item registration.
|
||||
* Allows for client-side rendering to be customized in the context of
|
||||
* block/item registration.
|
||||
*/
|
||||
public interface IBlockRendering
|
||||
{
|
||||
public interface IBlockRendering {
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
IBlockRendering modelCustomizer( BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer );
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
IBlockRendering modelCustomizer(BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer);
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
IBlockRendering blockColor( IBlockColor blockColor );
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
IBlockRendering blockColor(IBlockColor blockColor);
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
IBlockRendering renderType(RenderType type);
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
IBlockRendering renderType(RenderType type);
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
IBlockRendering renderType(Predicate<RenderType> type);
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
IBlockRendering renderType(Predicate<RenderType> type);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,10 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrap components can be registered to take part in the various initialization phases of Forge.
|
||||
* See the individual subclasses for a specific forge initalization event.
|
||||
* Bootstrap components can be registered to take part in the various
|
||||
* initialization phases of Forge. See the individual subclasses for a specific
|
||||
* forge initalization event.
|
||||
*/
|
||||
public interface IBootstrapComponent
|
||||
{
|
||||
public interface IBootstrapComponent {
|
||||
}
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import net.minecraft.advancements.ICriterionInstance;
|
||||
import net.minecraft.advancements.ICriterionTrigger;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ICriterionTriggerRegistry
|
||||
{
|
||||
void register( ICriterionTrigger<? extends ICriterionInstance> trigger );
|
||||
public interface ICriterionTriggerRegistry {
|
||||
void register(ICriterionTrigger<? extends ICriterionInstance> trigger);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -30,29 +29,27 @@ import net.minecraft.item.ItemGroup;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
|
||||
|
||||
/**
|
||||
* Allows an item to be defined and registered with the game.
|
||||
* The item is only registered once build is called.
|
||||
* Allows an item to be defined and registered with the game. The item is only
|
||||
* registered once build is called.
|
||||
*/
|
||||
public interface IItemBuilder
|
||||
{
|
||||
IItemBuilder bootstrap( Function<Item, IBootstrapComponent> component );
|
||||
public interface IItemBuilder {
|
||||
IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component);
|
||||
|
||||
IItemBuilder features( AEFeature... features );
|
||||
IItemBuilder features(AEFeature... features);
|
||||
|
||||
IItemBuilder addFeatures( AEFeature... features );
|
||||
IItemBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IItemBuilder itemGroup( ItemGroup tab );
|
||||
IItemBuilder itemGroup(ItemGroup tab);
|
||||
|
||||
IItemBuilder props(Consumer<Item.Properties> customizer);
|
||||
IItemBuilder props(Consumer<Item.Properties> customizer);
|
||||
|
||||
IItemBuilder rendering( ItemRenderingCustomizer callback );
|
||||
IItemBuilder rendering(ItemRenderingCustomizer callback);
|
||||
|
||||
/**
|
||||
* Registers a custom dispenser behavior for this item.
|
||||
*/
|
||||
IItemBuilder dispenserBehavior( Supplier<IDispenseItemBehavior> behavior );
|
||||
/**
|
||||
* Registers a custom dispenser behavior for this item.
|
||||
*/
|
||||
IItemBuilder dispenserBehavior(Supplier<IDispenseItemBehavior> behavior);
|
||||
|
||||
ItemDefinition build();
|
||||
ItemDefinition build();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -27,35 +26,32 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
/**
|
||||
* Allows the rendering of an item to be customized.
|
||||
*/
|
||||
public interface IItemRendering
|
||||
{
|
||||
public interface IItemRendering {
|
||||
|
||||
/**
|
||||
* Convenient override for {@link #variants(Collection)}.
|
||||
*/
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
default IItemRendering variants( ResourceLocation... resources )
|
||||
{
|
||||
return this.variants( Arrays.asList( resources ) );
|
||||
}
|
||||
/**
|
||||
* Convenient override for {@link #variants(Collection)}.
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
default IItemRendering variants(ResourceLocation... resources) {
|
||||
return this.variants(Arrays.asList(resources));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the item variants of this item. This are all models that need to be loaded for this item.
|
||||
* This has no direct effect on rendering, but is used to load models that are used for example by
|
||||
* the ItemMeshDefinition.
|
||||
*/
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
IItemRendering variants( Collection<ResourceLocation> resources );
|
||||
/**
|
||||
* Registers the item variants of this item. This are all models that need to be
|
||||
* loaded for this item. This has no direct effect on rendering, but is used to
|
||||
* load models that are used for example by the ItemMeshDefinition.
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
IItemRendering variants(Collection<ResourceLocation> resources);
|
||||
|
||||
/**
|
||||
* Registers a custom item color definition that inspects an item stack and tint and
|
||||
* returns a color multiplier.
|
||||
*/
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
IItemRendering color( IItemColor itemColor );
|
||||
/**
|
||||
* Registers a custom item color definition that inspects an item stack and tint
|
||||
* and returns a color multiplier.
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
IItemRendering color(IItemColor itemColor);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public interface IModelRegistry
|
||||
{
|
||||
void registerItemVariants( Item item, ResourceLocation... names );
|
||||
public interface IModelRegistry {
|
||||
void registerItemVariants(Item item, ResourceLocation... names);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -27,151 +26,134 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import appeng.bootstrap.components.IInitComponent;
|
||||
import appeng.core.AEItemGroup;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.dispenser.IDispenseItemBehavior;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
|
||||
import appeng.bootstrap.components.IItemRegistrationComponent;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.IInitComponent;
|
||||
import appeng.bootstrap.components.IItemRegistrationComponent;
|
||||
import appeng.core.AEItemGroup;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
|
||||
class ItemDefinitionBuilder implements IItemBuilder
|
||||
{
|
||||
class ItemDefinitionBuilder implements IItemBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final String registryName;
|
||||
private final String registryName;
|
||||
|
||||
private final Function<Item.Properties, Item> itemFactory;
|
||||
private final Function<Item.Properties, Item> itemFactory;
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf( AEFeature.class );
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
|
||||
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
|
||||
|
||||
private final Item.Properties props = new Item.Properties();
|
||||
private final Item.Properties props = new Item.Properties();
|
||||
|
||||
private Supplier<IDispenseItemBehavior> dispenserBehaviorSupplier;
|
||||
private Supplier<IDispenseItemBehavior> dispenserBehaviorSupplier;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private ItemRendering itemRendering;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
|
||||
ItemDefinitionBuilder( FeatureFactory factory, String registryName, Function<Item.Properties, Item> itemFactory )
|
||||
{
|
||||
this.factory = factory;
|
||||
this.registryName = registryName;
|
||||
this.itemFactory = itemFactory;
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
ItemDefinitionBuilder(FeatureFactory factory, String registryName, Function<Item.Properties, Item> itemFactory) {
|
||||
this.factory = factory;
|
||||
this.registryName = registryName;
|
||||
this.itemFactory = itemFactory;
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.itemRendering = new ItemRendering();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder bootstrap( Function<Item, IBootstrapComponent> component )
|
||||
{
|
||||
this.boostrapComponents.add( component );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component) {
|
||||
this.boostrapComponents.add(component);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder features( AEFeature... features )
|
||||
{
|
||||
this.features.clear();
|
||||
this.addFeatures( features );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder addFeatures( AEFeature... features )
|
||||
{
|
||||
Collections.addAll( this.features, features );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder itemGroup( ItemGroup itemGroup )
|
||||
{
|
||||
this.itemGroup = itemGroup;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder itemGroup(ItemGroup itemGroup) {
|
||||
this.itemGroup = itemGroup;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder props( Consumer<Item.Properties> consumer )
|
||||
{
|
||||
consumer.accept(props);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder props(Consumer<Item.Properties> consumer) {
|
||||
consumer.accept(props);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder rendering( ItemRenderingCustomizer callback )
|
||||
{
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.customizeForClient( callback );
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder rendering(ItemRenderingCustomizer callback) {
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder dispenserBehavior( Supplier<IDispenseItemBehavior> behavior )
|
||||
{
|
||||
this.dispenserBehaviorSupplier = behavior;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public IItemBuilder dispenserBehavior(Supplier<IDispenseItemBehavior> behavior) {
|
||||
this.dispenserBehaviorSupplier = behavior;
|
||||
return this;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private void customizeForClient( ItemRenderingCustomizer callback )
|
||||
{
|
||||
callback.customize( this.itemRendering );
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void customizeForClient(ItemRenderingCustomizer callback) {
|
||||
callback.customize(this.itemRendering);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDefinition build()
|
||||
{
|
||||
props.group(itemGroup);
|
||||
@Override
|
||||
public ItemDefinition build() {
|
||||
props.group(itemGroup);
|
||||
|
||||
Item item = this.itemFactory.apply(props);
|
||||
item.setRegistryName( AppEng.MOD_ID, this.registryName );
|
||||
Item item = this.itemFactory.apply(props);
|
||||
item.setRegistryName(AppEng.MOD_ID, this.registryName);
|
||||
|
||||
ItemDefinition definition = new ItemDefinition( this.registryName, item, features );
|
||||
ItemDefinition definition = new ItemDefinition(this.registryName, item, features);
|
||||
|
||||
// Register all extra handlers
|
||||
this.boostrapComponents.forEach( component -> this.factory.addBootstrapComponent( component.apply( item ) ) );
|
||||
// Register all extra handlers
|
||||
this.boostrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(item)));
|
||||
|
||||
// Register custom dispenser behavior if requested
|
||||
if( this.dispenserBehaviorSupplier != null )
|
||||
{
|
||||
this.factory.addBootstrapComponent( (IInitComponent) () ->
|
||||
{
|
||||
IDispenseItemBehavior behavior = this.dispenserBehaviorSupplier.get();
|
||||
DispenserBlock.registerDispenseBehavior( item, behavior );
|
||||
} );
|
||||
}
|
||||
// Register custom dispenser behavior if requested
|
||||
if (this.dispenserBehaviorSupplier != null) {
|
||||
this.factory.addBootstrapComponent((IInitComponent) () -> {
|
||||
IDispenseItemBehavior behavior = this.dispenserBehaviorSupplier.get();
|
||||
DispenserBlock.registerDispenseBehavior(item, behavior);
|
||||
});
|
||||
}
|
||||
|
||||
this.factory.addBootstrapComponent( (IItemRegistrationComponent) ( side, reg ) -> reg.register( item ) );
|
||||
this.factory.addBootstrapComponent((IItemRegistrationComponent) (side, reg) -> reg.register(item));
|
||||
|
||||
if( Platform.hasClientClasses() )
|
||||
{
|
||||
this.itemRendering.apply( this.factory, item );
|
||||
}
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
|
||||
if (itemGroup instanceof AEItemGroup) {
|
||||
((AEItemGroup) itemGroup).add(definition);
|
||||
}
|
||||
if (itemGroup instanceof AEItemGroup) {
|
||||
((AEItemGroup) itemGroup).add(definition);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -32,44 +31,37 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import appeng.bootstrap.components.ItemColorComponent;
|
||||
import appeng.bootstrap.components.ItemVariantsComponent;
|
||||
|
||||
class ItemRendering implements IItemRendering {
|
||||
|
||||
class ItemRendering implements IItemRendering
|
||||
{
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private IItemColor itemColor;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private IItemColor itemColor;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private Set<ResourceLocation> variants = new HashSet<>();
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private Set<ResourceLocation> variants = new HashSet<>();
|
||||
@Override
|
||||
public IItemRendering variants(Collection<ResourceLocation> resources) {
|
||||
this.variants.addAll(resources);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemRendering variants( Collection<ResourceLocation> resources )
|
||||
{
|
||||
this.variants.addAll( resources );
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public IItemRendering color(IItemColor itemColor) {
|
||||
this.itemColor = itemColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public IItemRendering color( IItemColor itemColor )
|
||||
{
|
||||
this.itemColor = itemColor;
|
||||
return this;
|
||||
}
|
||||
void apply(FeatureFactory factory, Item item) {
|
||||
Set<ResourceLocation> resources = new HashSet<>(this.variants);
|
||||
|
||||
void apply( FeatureFactory factory, Item item )
|
||||
{
|
||||
Set<ResourceLocation> resources = new HashSet<>( this.variants );
|
||||
if (!resources.isEmpty()) {
|
||||
factory.addBootstrapComponent(new ItemVariantsComponent(item, resources));
|
||||
}
|
||||
|
||||
if( !resources.isEmpty() )
|
||||
{
|
||||
factory.addBootstrapComponent( new ItemVariantsComponent( item, resources ) );
|
||||
}
|
||||
|
||||
if( this.itemColor != null )
|
||||
{
|
||||
factory.addBootstrapComponent( new ItemColorComponent( item, this.itemColor ) );
|
||||
}
|
||||
}
|
||||
if (this.itemColor != null) {
|
||||
factory.addBootstrapComponent(new ItemColorComponent(item, this.itemColor));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,19 +18,16 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
/**
|
||||
* A callback that allows the rendering of a item to be customized. Sadly this class is required and no lambdas can be
|
||||
* used
|
||||
* due to them not being able to be annotated with @OnlyIn(CLIENT).
|
||||
* A callback that allows the rendering of a item to be customized. Sadly this
|
||||
* class is required and no lambdas can be used due to them not being able to be
|
||||
* annotated with @OnlyIn(CLIENT).
|
||||
*/
|
||||
public abstract class ItemRenderingCustomizer
|
||||
{
|
||||
public abstract class ItemRenderingCustomizer {
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public abstract void customize( IItemRendering rendering );
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract void customize(IItemRendering rendering);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.IClientSetupComponent;
|
||||
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.BlockStackSrc;
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -25,8 +7,28 @@ import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.IClientSetupComponent;
|
||||
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.ActivityState;
|
||||
import appeng.core.features.BlockStackSrc;
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
/**
|
||||
* Used to define our tile entities and all of their properties that are relevant to registering them.
|
||||
* Used to define our tile entities and all of their properties that are
|
||||
* relevant to registering them.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@@ -51,7 +53,8 @@ public class TileEntityBuilder<T extends AEBaseTile> {
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
public TileEntityBuilder(FeatureFactory factory, String registryName, Class<T> tileClass, Function<TileEntityType<T>, T> supplier) {
|
||||
public TileEntityBuilder(FeatureFactory factory, String registryName, Class<T> tileClass,
|
||||
Function<TileEntityType<T>, T> supplier) {
|
||||
this.factory = factory;
|
||||
this.registryName = registryName;
|
||||
this.tileClass = tileClass;
|
||||
@@ -77,21 +80,17 @@ public class TileEntityBuilder<T extends AEBaseTile> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public TileEntityDefinition build() {
|
||||
|
||||
this.factory.addBootstrapComponent((ITileEntityRegistrationComponent) registry ->
|
||||
{
|
||||
this.factory.addBootstrapComponent((ITileEntityRegistrationComponent) registry -> {
|
||||
if (blocks.isEmpty()) {
|
||||
throw new IllegalStateException("No blocks make use of this tile entity: " + tileClass);
|
||||
}
|
||||
|
||||
Supplier<T> factory = () -> supplier.apply(type);
|
||||
type = TileEntityType.Builder.create(factory, blocks.toArray(new Block[0]))
|
||||
.build(null);
|
||||
type = TileEntityType.Builder.create(factory, blocks.toArray(new Block[0])).build(null);
|
||||
type.setRegistryName(AppEng.MOD_ID, registryName);
|
||||
registry.register(type);
|
||||
|
||||
AEBaseTile.registerTileItem(
|
||||
tileClass,
|
||||
new BlockStackSrc(blocks.get(0), ActivityState.Enabled));
|
||||
AEBaseTile.registerTileItem(tileClass, new BlockStackSrc(blocks.get(0), ActivityState.Enabled));
|
||||
|
||||
for (Block block : blocks) {
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
@@ -101,7 +100,7 @@ public class TileEntityBuilder<T extends AEBaseTile> {
|
||||
}
|
||||
|
||||
});
|
||||
DistExecutor.runWhenOn( Dist.CLIENT, () -> this::buildClient );
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> this::buildClient);
|
||||
|
||||
return new TileEntityDefinition(this::addBlock);
|
||||
|
||||
@@ -109,7 +108,7 @@ public class TileEntityBuilder<T extends AEBaseTile> {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void buildClient() {
|
||||
this.factory.addBootstrapComponent( (IClientSetupComponent) ()-> {
|
||||
this.factory.addBootstrapComponent((IClientSetupComponent) () -> {
|
||||
if (tileEntityRendering.tileEntityRenderer != null) {
|
||||
ClientRegistry.bindTileEntityRenderer(type, tileEntityRendering.tileEntityRenderer);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.function.Function;
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
public class TileEntityRendering<T extends AEBaseTile> {
|
||||
|
||||
@@ -33,7 +33,8 @@ public class TileEntityRendering<T extends AEBaseTile> {
|
||||
Function<TileEntityRendererDispatcher, TileEntityRenderer<T>> tileEntityRenderer;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public TileEntityRendering<T> tileEntityRenderer(Function<TileEntityRendererDispatcher, TileEntityRenderer<T>> tileEntityRenderer) {
|
||||
public TileEntityRendering<T> tileEntityRenderer(
|
||||
Function<TileEntityRendererDispatcher, TileEntityRenderer<T>> tileEntityRenderer) {
|
||||
this.tileEntityRenderer = tileEntityRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -18,20 +18,19 @@
|
||||
|
||||
package appeng.bootstrap;
|
||||
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
/**
|
||||
* A callback that allows the rendering of a tile entity to be customized. Sadly this class is required and no lambdas
|
||||
* can be used due to them not being able to be annotated with @OnlyIn(CLIENT).
|
||||
* A callback that allows the rendering of a tile entity to be customized. Sadly
|
||||
* this class is required and no lambdas can be used due to them not being able
|
||||
* to be annotated with @OnlyIn(CLIENT).
|
||||
*/
|
||||
public abstract class TileEntityRenderingCustomizer<T extends AEBaseTile>
|
||||
{
|
||||
public abstract class TileEntityRenderingCustomizer<T extends AEBaseTile> {
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public abstract void customize( TileEntityRendering<T> rendering );
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract void customize(TileEntityRendering<T> rendering);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,30 +18,25 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
public class BlockColorComponent implements IInitComponent {
|
||||
|
||||
public class BlockColorComponent implements IInitComponent
|
||||
{
|
||||
private final Block block;
|
||||
|
||||
private final Block block;
|
||||
private final IBlockColor blockColor;
|
||||
|
||||
private final IBlockColor blockColor;
|
||||
public BlockColorComponent(Block block, IBlockColor blockColor) {
|
||||
this.block = block;
|
||||
this.blockColor = blockColor;
|
||||
}
|
||||
|
||||
public BlockColorComponent( Block block, IBlockColor blockColor )
|
||||
{
|
||||
this.block = block;
|
||||
this.blockColor = blockColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
Minecraft.getInstance().getBlockColors().register( this.blockColor, this.block );
|
||||
}
|
||||
@Override
|
||||
public void initialize() {
|
||||
Minecraft.getInstance().getBlockColors().register(this.blockColor, this.block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IBlockRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void blockRegistration( Dist dist, IForgeRegistry<Block> blockRegistry );
|
||||
public interface IBlockRegistrationComponent extends IBootstrapComponent {
|
||||
void blockRegistration(Dist dist, IForgeRegistry<Block> blockRegistry);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ package appeng.bootstrap.components;
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
/**
|
||||
* Will be run during {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}.
|
||||
* Will be run during
|
||||
* {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}.
|
||||
*/
|
||||
public interface IClientSetupComponent extends IBootstrapComponent {
|
||||
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IEntityRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void entityRegistration( IForgeRegistry<EntityType<?>> entityRegistry );
|
||||
public interface IEntityRegistrationComponent extends IBootstrapComponent {
|
||||
void entityRegistration(IForgeRegistry<EntityType<?>> entityRegistry);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IInitComponent extends IBootstrapComponent
|
||||
{
|
||||
void initialize();
|
||||
public interface IInitComponent extends IBootstrapComponent {
|
||||
void initialize();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.client.renderer.color.ItemColors;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
public interface IItemColorRegistrationComponent extends IBootstrapComponent {
|
||||
|
||||
void register(ItemColors itemColors, BlockColors blockColors);
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IItemRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void itemRegistration( Dist dist, IForgeRegistry<Item> itemRegistry );
|
||||
public interface IItemRegistrationComponent extends IBootstrapComponent {
|
||||
void itemRegistration(Dist dist, IForgeRegistry<Item> itemRegistry);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
public interface IModelBakeComponent extends IBootstrapComponent {
|
||||
|
||||
void onModelBakeEvent(ModelBakeEvent event);
|
||||
|
||||
@@ -18,19 +18,16 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IModelRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void modelRegistration( Dist dist, IModelRegistry registry );
|
||||
public interface IModelRegistrationComponent extends IBootstrapComponent {
|
||||
void modelRegistration(Dist dist, IModelRegistry registry);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IPostInitComponent extends IBootstrapComponent
|
||||
{
|
||||
void postInitialize();
|
||||
public interface IPostInitComponent extends IBootstrapComponent {
|
||||
void postInitialize();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -9,9 +8,7 @@ import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IRecipeRegistrationComponent extends IBootstrapComponent
|
||||
{
|
||||
void recipeRegistration( Dist dist, IForgeRegistry<IRecipeSerializer<?>> recipeRegistry );
|
||||
public interface IRecipeRegistrationComponent extends IBootstrapComponent {
|
||||
void recipeRegistration(Dist dist, IForgeRegistry<IRecipeSerializer<?>> recipeRegistry);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ITileEntityRegistrationComponent extends IBootstrapComponent {
|
||||
void register(IForgeRegistry<TileEntityType<?>> registry);
|
||||
|
||||
@@ -18,28 +18,23 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.color.BlockColors;
|
||||
import net.minecraft.client.renderer.color.IItemColor;
|
||||
import net.minecraft.client.renderer.color.ItemColors;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ItemColorComponent implements IItemColorRegistrationComponent {
|
||||
private final Item item;
|
||||
|
||||
public class ItemColorComponent implements IItemColorRegistrationComponent
|
||||
{
|
||||
private final Item item;
|
||||
private final IItemColor itemColor;
|
||||
|
||||
private final IItemColor itemColor;
|
||||
public ItemColorComponent(Item item, IItemColor itemColor) {
|
||||
this.item = item;
|
||||
this.itemColor = itemColor;
|
||||
}
|
||||
|
||||
public ItemColorComponent( Item item, IItemColor itemColor )
|
||||
{
|
||||
this.item = item;
|
||||
this.itemColor = itemColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ItemColors itemColors, BlockColors blockColors)
|
||||
{
|
||||
itemColors.register( this.itemColor, this.item );
|
||||
}
|
||||
@Override
|
||||
public void register(ItemColors itemColors, BlockColors blockColors) {
|
||||
itemColors.register(this.itemColor, this.item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* Registers a custom item mesh definition that can be used to dynamically determine the item model based on
|
||||
* item stack properties.
|
||||
* Registers a custom item mesh definition that can be used to dynamically
|
||||
* determine the item model based on item stack properties.
|
||||
*/
|
||||
public class ItemMeshDefinitionComponent implements IModelRegistrationComponent
|
||||
{
|
||||
public class ItemMeshDefinitionComponent implements IModelRegistrationComponent {
|
||||
|
||||
// FIXME private final Item item;
|
||||
// FIXME
|
||||
@@ -42,9 +38,8 @@ public class ItemMeshDefinitionComponent implements IModelRegistrationComponent
|
||||
// FIXME this.meshDefinition = meshDefinition;
|
||||
// FIXME }
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Dist dist, IModelRegistry registry )
|
||||
{
|
||||
// FIXME registry.setCustomMeshDefinition( this.item, this.meshDefinition );
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Dist dist, IModelRegistry registry) {
|
||||
// FIXME registry.setCustomMeshDefinition( this.item, this.meshDefinition );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
@@ -27,24 +26,20 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
|
||||
public class ItemVariantsComponent implements IModelRegistrationComponent {
|
||||
|
||||
public class ItemVariantsComponent implements IModelRegistrationComponent
|
||||
{
|
||||
private final Item item;
|
||||
|
||||
private final Item item;
|
||||
private final Collection<ResourceLocation> resources;
|
||||
|
||||
private final Collection<ResourceLocation> resources;
|
||||
public ItemVariantsComponent(Item item, Collection<ResourceLocation> resources) {
|
||||
this.item = item;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
public ItemVariantsComponent( Item item, Collection<ResourceLocation> resources )
|
||||
{
|
||||
this.item = item;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Dist dist, IModelRegistry registry )
|
||||
{
|
||||
ResourceLocation[] resourceArr = this.resources.toArray( new ResourceLocation[0] );
|
||||
registry.registerItemVariants( this.item, resourceArr );
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Dist dist, IModelRegistry registry) {
|
||||
ResourceLocation[] resourceArr = this.resources.toArray(new ResourceLocation[0]);
|
||||
registry.registerItemVariants(this.item, resourceArr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -33,49 +32,40 @@ import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class ModelOverrideComponent implements IModelBakeComponent {
|
||||
|
||||
public class ModelOverrideComponent implements IModelBakeComponent
|
||||
{
|
||||
// Maps from resource path to customizer
|
||||
private final Map<String, BiFunction<ResourceLocation, IBakedModel, IBakedModel>> customizer = new HashMap<>();
|
||||
|
||||
// Maps from resource path to customizer
|
||||
private final Map<String, BiFunction<ResourceLocation, IBakedModel, IBakedModel>> customizer = new HashMap<>();
|
||||
public void addOverride(String resourcePath, BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer) {
|
||||
this.customizer.put(resourcePath, customizer);
|
||||
}
|
||||
|
||||
public void addOverride( String resourcePath, BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer )
|
||||
{
|
||||
this.customizer.put( resourcePath, customizer );
|
||||
}
|
||||
public void onModelBakeEvent(final ModelBakeEvent event) {
|
||||
Map<ResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
||||
Set<ResourceLocation> keys = Sets.newHashSet(modelRegistry.keySet());
|
||||
IBakedModel missingModel = modelRegistry.get(ModelBakery.MODEL_MISSING);
|
||||
|
||||
public void onModelBakeEvent( final ModelBakeEvent event )
|
||||
{
|
||||
Map<ResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
||||
Set<ResourceLocation> keys = Sets.newHashSet( modelRegistry.keySet() );
|
||||
IBakedModel missingModel = modelRegistry.get(ModelBakery.MODEL_MISSING);
|
||||
for (ResourceLocation location : keys) {
|
||||
if (!location.getNamespace().equals(AppEng.MOD_ID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( ResourceLocation location : keys )
|
||||
{
|
||||
if( !location.getNamespace().equals( AppEng.MOD_ID ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IBakedModel orgModel = modelRegistry.get(location);
|
||||
|
||||
IBakedModel orgModel = modelRegistry.get( location );
|
||||
// Don't customize the missing model. This causes Forge to swallow exceptions
|
||||
if (orgModel == missingModel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't customize the missing model. This causes Forge to swallow exceptions
|
||||
if( orgModel == missingModel )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer = this.customizer.get(location.getPath());
|
||||
if (customizer != null) {
|
||||
IBakedModel newModel = customizer.apply(location, orgModel);
|
||||
|
||||
BiFunction<ResourceLocation, IBakedModel, IBakedModel> customizer = this.customizer.get( location.getPath() );
|
||||
if( customizer != null )
|
||||
{
|
||||
IBakedModel newModel = customizer.apply( location, orgModel );
|
||||
|
||||
if( newModel != orgModel )
|
||||
{
|
||||
modelRegistry.put( location, newModel );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newModel != orgModel) {
|
||||
modelRegistry.put(location, newModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Sets the rendering type for a block.
|
||||
*/
|
||||
|
||||
@@ -18,19 +18,16 @@
|
||||
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* Registers a custom state mapper for a given block.
|
||||
*/
|
||||
public class StateMapperComponent implements IModelRegistrationComponent
|
||||
{
|
||||
public class StateMapperComponent implements IModelRegistrationComponent {
|
||||
|
||||
// FIXME private final Block block;
|
||||
|
||||
@@ -42,14 +39,15 @@ public class StateMapperComponent implements IModelRegistrationComponent
|
||||
// FIXME this.stateMapper = stateMapper;
|
||||
// FIXME }
|
||||
|
||||
@Override
|
||||
public void modelRegistration( Dist dist, IModelRegistry registry )
|
||||
{
|
||||
// FIXME registry.setCustomStateMapper( this.block, this.stateMapper );
|
||||
// FIXME if( this.stateMapper instanceof IResourceManagerReloadListener )
|
||||
// FIXME {
|
||||
// FIXME ( (IReloadableResourceManager) Minecraft.getInstance().getResourceManager() )
|
||||
// FIXME .registerReloadListener( (IResourceManagerReloadListener) this.stateMapper );
|
||||
// FIXME }
|
||||
}
|
||||
@Override
|
||||
public void modelRegistration(Dist dist, IModelRegistry registry) {
|
||||
// FIXME registry.setCustomStateMapper( this.block, this.stateMapper );
|
||||
// FIXME if( this.stateMapper instanceof IResourceManagerReloadListener )
|
||||
// FIXME {
|
||||
// FIXME ( (IReloadableResourceManager)
|
||||
// Minecraft.getInstance().getResourceManager() )
|
||||
// FIXME .registerReloadListener( (IResourceManagerReloadListener)
|
||||
// this.stateMapper );
|
||||
// FIXME }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
|
||||
package appeng.bootstrap.definitions;
|
||||
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import appeng.tile.AEBaseTile;
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
@@ -34,7 +33,7 @@ public class TileEntityDefinition {
|
||||
private final Consumer<Block> addBlockListener;
|
||||
|
||||
public TileEntityDefinition(Consumer<Block> addBlockListener) {
|
||||
this.addBlockListener = addBlockListener;
|
||||
this.addBlockListener = addBlockListener;
|
||||
}
|
||||
|
||||
public void addBlock(Block block) {
|
||||
|
||||
Reference in New Issue
Block a user