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.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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user