Moving code around
This commit is contained in:
@@ -1,202 +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.bootstrap;
|
||||
|
||||
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.definitions.TileEntityDefinition;
|
||||
import appeng.core.AEItemGroup;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.features.BlockDefinition;
|
||||
import appeng.core.features.TileDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class BlockDefinitionBuilder implements IBlockBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
private final Supplier<? extends Block> blockSupplier;
|
||||
|
||||
private final List<BiFunction<Block, Item, IBootstrapComponent>> bootstrapComponents = new ArrayList<>();
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
|
||||
private TileEntityDefinition tileEntityDefinition;
|
||||
|
||||
private boolean disableItem = false;
|
||||
|
||||
private BiFunction<Block, Item.Settings, BlockItem> itemFactory;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private BlockRendering blockRendering;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
BlockDefinitionBuilder(FeatureFactory factory, String id, Supplier<? extends Block> blockSupplier) {
|
||||
this.factory = factory;
|
||||
this.id = new Identifier(AppEng.MOD_ID, id);
|
||||
this.blockSupplier = blockSupplier;
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.blockRendering = new BlockRendering(this.id);
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockDefinitionBuilder rendering(BlockRenderingCustomizer callback) {
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition) {
|
||||
this.tileEntityDefinition = tileEntityDefinition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder item(BiFunction<Block, Item.Settings, BlockItem> factory) {
|
||||
this.itemFactory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder disableItem() {
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void customizeForClient(BlockRenderingCustomizer callback) {
|
||||
callback.customize(this.blockRendering, this.itemRendering);
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
// Register the item and block with the game
|
||||
Registry.register(Registry.BLOCK, id, block);
|
||||
BlockItem item = this.constructItemFromBlock(block);
|
||||
if (item != null) {
|
||||
Registry.register(Registry.ITEM, id, item);
|
||||
}
|
||||
|
||||
// Register all extra handlers
|
||||
this.bootstrapComponents.forEach(component -> this.factory.addBootstrapComponent(component.apply(block, item)));
|
||||
|
||||
if (this.tileEntityDefinition != null) {
|
||||
// Tell the block entity definition about the block we've registered
|
||||
this.tileEntityDefinition.addBlock(block);
|
||||
}
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.blockRendering.apply(this.factory, block);
|
||||
|
||||
if (item != null) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
}
|
||||
|
||||
T definition;
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
definition = (T) new TileDefinition(this.id.getPath(), (AEBaseTileBlock<?>) block, item, features);
|
||||
} else {
|
||||
definition = (T) new BlockDefinition(this.id.getPath(), block, item, features);
|
||||
}
|
||||
|
||||
if (itemGroup instanceof AEItemGroup) {
|
||||
((AEItemGroup) itemGroup).add(definition);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private BlockItem constructItemFromBlock(Block block) {
|
||||
if (this.disableItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Item.Settings itemProperties = new Item.Settings();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
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.AEBaseBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
/**
|
||||
* Used to define our block entities and all of their properties that are
|
||||
* relevant to registering them.
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class BlockEntityBuilder<T extends AEBaseBlockEntity> {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
// The block entity class
|
||||
private final Class<T> tileClass;
|
||||
|
||||
private BlockEntityType<T> type;
|
||||
|
||||
// The factory for creating block entity objects
|
||||
private final Function<BlockEntityType<T>, T> supplier;
|
||||
|
||||
private TileEntityRendering<T> tileEntityRendering;
|
||||
|
||||
private final List<Block> blocks = new ArrayList<>();
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
public BlockEntityBuilder(FeatureFactory factory, String id, Class<T> tileClass,
|
||||
Function<BlockEntityType<T>, T> supplier) {
|
||||
this.factory = factory;
|
||||
this.id = AppEng.makeId(id);
|
||||
this.tileClass = tileClass;
|
||||
this.supplier = supplier;
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.tileEntityRendering = new TileEntityRendering<>();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockEntityBuilder<T> features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockEntityBuilder<T> addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockEntityBuilder<T> rendering(TileEntityRenderingCustomizer<T> customizer) {
|
||||
customizer.customize(tileEntityRendering);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public TileEntityDefinition build() {
|
||||
|
||||
this.factory.addBootstrapComponent((ITileEntityRegistrationComponent) () -> {
|
||||
if (blocks.isEmpty()) {
|
||||
throw new IllegalStateException("No blocks make use of this block entity: " + tileClass);
|
||||
}
|
||||
|
||||
Supplier<T> factory = () -> supplier.apply(type);
|
||||
type = BlockEntityType.Builder.create(factory, blocks.toArray(new Block[0])).build(null);
|
||||
|
||||
Registry.register(Registry.BLOCK_ENTITY_TYPE, id, type);
|
||||
|
||||
AEBaseBlockEntity.registerTileItem(tileClass, new BlockStackSrc(blocks.get(0), ActivityState.Enabled));
|
||||
|
||||
for (Block block : blocks) {
|
||||
if (block instanceof AEBaseTileBlock) {
|
||||
AEBaseTileBlock<T> baseTileBlock = (AEBaseTileBlock<T>) block;
|
||||
baseTileBlock.setTileEntity(tileClass, factory);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
buildClient();
|
||||
}
|
||||
|
||||
return new TileEntityDefinition(this::addBlock);
|
||||
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void buildClient() {
|
||||
this.factory.addBootstrapComponent((IClientSetupComponent) () -> {
|
||||
if (tileEntityRendering.tileEntityRenderer != null) {
|
||||
BlockEntityRendererRegistry.INSTANCE.register(type, tileEntityRendering.tileEntityRenderer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addBlock(Block block) {
|
||||
Preconditions.checkState(type == null, "No more blocks can be added after registration completed.");
|
||||
this.blocks.add(block);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +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.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockColorComponent;
|
||||
import appeng.bootstrap.components.RenderTypeComponent;
|
||||
import appeng.client.render.model.AutoRotatingBakedModel;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
class BlockRendering implements IBlockRendering {
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private BiFunction<Identifier, BakedModel, BakedModel> modelCustomizer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private BlockColorProvider blockColor;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private RenderLayer renderType;
|
||||
|
||||
public BlockRendering(Identifier id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public IBlockRendering modelCustomizer(BiFunction<Identifier, BakedModel, BakedModel> customizer) {
|
||||
this.modelCustomizer = customizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public IBlockRendering blockColor(BlockColorProvider blockColor) {
|
||||
this.blockColor = blockColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockRendering renderType(RenderLayer type) {
|
||||
this.renderType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
void apply(FeatureFactory factory, Block block) {
|
||||
if (this.modelCustomizer != null) {
|
||||
factory.addModelOverride(id.getPath(), this.modelCustomizer);
|
||||
} else if (block instanceof AEBaseTileBlock) {
|
||||
// This is a default rotating model if the base-block uses an AE block entity
|
||||
// which exposes UP/FRONT as
|
||||
// extended props
|
||||
factory.addModelOverride(id.getPath(), (l, m) -> new AutoRotatingBakedModel(m));
|
||||
}
|
||||
|
||||
if (this.blockColor != null) {
|
||||
factory.addBootstrapComponent(new BlockColorComponent(block, this.blockColor));
|
||||
}
|
||||
|
||||
if (this.renderType != null) {
|
||||
factory.addBootstrapComponent(new RenderTypeComponent(block, this.renderType));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +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.bootstrap;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract void customize(IBlockRendering rendering, IItemRendering itemRendering);
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Helper to register a custom Entity with Minecraft.
|
||||
*/
|
||||
public class EntityBuilder<T extends Entity> {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final String id;
|
||||
|
||||
private final EntityType.Builder<T> builder;
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
public EntityBuilder(FeatureFactory factory, String id, EntityType.EntityFactory<T> entityFactory,
|
||||
SpawnGroup classification) {
|
||||
this.factory = factory;
|
||||
this.id = id;
|
||||
this.builder = EntityType.Builder.create(entityFactory, classification);
|
||||
}
|
||||
|
||||
public EntityBuilder<T> features(AEFeature... features) {
|
||||
this.features.clear();
|
||||
this.addFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityBuilder<T> addFeatures(AEFeature... features) {
|
||||
Collections.addAll(this.features, features);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityBuilder<T> customize(Consumer<EntityType.Builder<T>> function) {
|
||||
function.accept(builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityType<T> build() {
|
||||
String fullId = "appliedenergistics2:" + this.id;
|
||||
EntityType<T> entityType = builder.build(fullId);
|
||||
Registry.register(Registry.ENTITY_TYPE, fullId, entityType);
|
||||
return entityType;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +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.bootstrap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.ModelOverrideComponent;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class FeatureFactory {
|
||||
|
||||
private final AEFeature[] defaultFeatures;
|
||||
|
||||
private final Map<Class<? extends IBootstrapComponent>, List<IBootstrapComponent>> bootstrapComponents;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ModelOverrideComponent modelOverrideComponent;
|
||||
|
||||
public FeatureFactory() {
|
||||
this.defaultFeatures = new AEFeature[] { AEFeature.CORE };
|
||||
this.bootstrapComponents = new HashMap<>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public IBlockBuilder block(String id, Supplier<Block> block) {
|
||||
return new BlockDefinitionBuilder(this, id, block).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public IItemBuilder item(String id, Function<Item.Settings, Item> itemFactory) {
|
||||
return new ItemDefinitionBuilder(this, id, itemFactory).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public <T extends Entity> EntityBuilder<T> entity(String id, EntityType.EntityFactory<T> factory,
|
||||
SpawnGroup classification) {
|
||||
return new EntityBuilder<T>(this, id, factory, classification).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
public <T extends AEBaseBlockEntity> BlockEntityBuilder<T> tileEntity(String id, Class<T> teClass,
|
||||
Function<BlockEntityType<T>, T> factory) {
|
||||
return new BlockEntityBuilder<>(this, id, teClass, factory).features(this.defaultFeatures);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private <T extends IBootstrapComponent> void addBootstrapComponent(Class<? extends IBootstrapComponent> eventType,
|
||||
T component) {
|
||||
this.bootstrapComponents.computeIfAbsent(eventType, c -> new ArrayList<IBootstrapComponent>()).add(component);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
void addModelOverride(String resourcePath, BiFunction<Identifier, BakedModel, BakedModel> 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();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +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.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
|
||||
public interface IBlockBuilder {
|
||||
IBlockBuilder bootstrap(BiFunction<Block, Item, IBootstrapComponent> component);
|
||||
|
||||
IBlockBuilder features(AEFeature... features);
|
||||
|
||||
IBlockBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IBlockBuilder rendering(BlockRenderingCustomizer callback);
|
||||
|
||||
IBlockBuilder tileEntity(TileEntityDefinition tileEntityDefinition);
|
||||
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
|
||||
IBlockBuilder item(BiFunction<Block, Item.Settings, BlockItem> factory);
|
||||
|
||||
<T extends IBlockDefinition> T build();
|
||||
}
|
||||
@@ -1,46 +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.bootstrap;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
/**
|
||||
* Allows for client-side rendering to be customized in the context of
|
||||
* block/item registration.
|
||||
*/
|
||||
public interface IBlockRendering {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
IBlockRendering modelCustomizer(BiFunction<Identifier, BakedModel, BakedModel> customizer);
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
IBlockRendering blockColor(BlockColorProvider blockColor);
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
IBlockRendering renderType(RenderLayer type);
|
||||
|
||||
}
|
||||
@@ -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.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.
|
||||
*/
|
||||
public interface IBootstrapComponent {
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, 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.bootstrap;
|
||||
|
||||
import net.minecraft.advancement.criterion.Criterion;
|
||||
import net.minecraft.advancement.criterion.CriterionConditions;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ICriterionTriggerRegistry {
|
||||
void register(Criterion<? extends CriterionConditions> trigger);
|
||||
}
|
||||
@@ -1,55 +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.bootstrap;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.item.Item;
|
||||
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.
|
||||
*/
|
||||
public interface IItemBuilder {
|
||||
IItemBuilder bootstrap(Function<Item, IBootstrapComponent> component);
|
||||
|
||||
IItemBuilder features(AEFeature... features);
|
||||
|
||||
IItemBuilder addFeatures(AEFeature... features);
|
||||
|
||||
IItemBuilder itemGroup(ItemGroup tab);
|
||||
|
||||
IItemBuilder props(Consumer<Item.Settings> customizer);
|
||||
|
||||
IItemBuilder rendering(ItemRenderingCustomizer callback);
|
||||
|
||||
/**
|
||||
* Registers a custom dispenser behavior for this item.
|
||||
*/
|
||||
IItemBuilder dispenserBehavior(Supplier<DispenserBehavior> behavior);
|
||||
|
||||
ItemDefinition build();
|
||||
}
|
||||
@@ -1,37 +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.bootstrap;
|
||||
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
/**
|
||||
* Allows the rendering of an item to be customized.
|
||||
*/
|
||||
public interface IItemRendering {
|
||||
|
||||
/**
|
||||
* Registers a custom item color definition that inspects an item stack and tint
|
||||
* and returns a color multiplier.
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
IItemRendering color(ItemColorProvider itemColor);
|
||||
|
||||
}
|
||||
@@ -1,159 +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.bootstrap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.bootstrap.components.IInitComponent;
|
||||
import appeng.core.AEItemGroup;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CreativeTab;
|
||||
import appeng.core.features.ItemDefinition;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
class ItemDefinitionBuilder implements IItemBuilder {
|
||||
|
||||
private final FeatureFactory factory;
|
||||
|
||||
private final Identifier id;
|
||||
|
||||
private final Function<Item.Settings, Item> itemFactory;
|
||||
|
||||
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
|
||||
|
||||
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
|
||||
|
||||
private final Item.Settings props = new Item.Settings();
|
||||
|
||||
private Supplier<DispenserBehavior> dispenserBehaviorSupplier;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ItemRendering itemRendering;
|
||||
|
||||
private ItemGroup itemGroup = CreativeTab.INSTANCE;
|
||||
|
||||
ItemDefinitionBuilder(FeatureFactory factory, String id, Function<Item.Settings, Item> itemFactory) {
|
||||
this.factory = factory;
|
||||
this.id = AppEng.makeId(id);
|
||||
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 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 itemGroup(ItemGroup itemGroup) {
|
||||
this.itemGroup = itemGroup;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder props(Consumer<Item.Settings> consumer) {
|
||||
consumer.accept(props);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder rendering(ItemRenderingCustomizer callback) {
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.customizeForClient(callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemBuilder dispenserBehavior(Supplier<DispenserBehavior> behavior) {
|
||||
this.dispenserBehaviorSupplier = behavior;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void customizeForClient(ItemRenderingCustomizer callback) {
|
||||
callback.customize(this.itemRendering);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDefinition build() {
|
||||
props.group(itemGroup);
|
||||
|
||||
Item item = this.itemFactory.apply(props);
|
||||
|
||||
ItemDefinition definition = new ItemDefinition(id.getPath(), item, features);
|
||||
|
||||
// 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) () -> {
|
||||
DispenserBehavior behavior = this.dispenserBehaviorSupplier.get();
|
||||
DispenserBlock.registerBehavior(item, behavior);
|
||||
});
|
||||
}
|
||||
|
||||
Registry.register(Registry.ITEM, id, item);
|
||||
|
||||
if (Platform.hasClientClasses()) {
|
||||
this.itemRendering.apply(this.factory, item);
|
||||
}
|
||||
|
||||
if (itemGroup instanceof AEItemGroup) {
|
||||
((AEItemGroup) itemGroup).add(definition);
|
||||
}
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +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.bootstrap;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.bootstrap.components.ItemColorComponent;
|
||||
|
||||
class ItemRendering implements IItemRendering {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private ItemColorProvider itemColor;
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public IItemRendering color(ItemColorProvider itemColor) {
|
||||
this.itemColor = itemColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
void apply(FeatureFactory factory, Item item) {
|
||||
if (this.itemColor != null) {
|
||||
factory.addBootstrapComponent(new ItemColorComponent(item, this.itemColor));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +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.bootstrap;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public abstract void customize(IItemRendering rendering);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package appeng.bootstrap;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ModelsReloadCallback {
|
||||
|
||||
Event<ModelsReloadCallback> EVENT = EventFactory.createArrayBacked(ModelsReloadCallback.class,
|
||||
(listeners) -> (loadedModels) -> {
|
||||
for (ModelsReloadCallback listener : listeners) {
|
||||
listener.onModelsReloaded(loadedModels);
|
||||
}
|
||||
});
|
||||
|
||||
void onModelsReloaded(Map<Identifier, BakedModel> loadedModels);
|
||||
|
||||
}
|
||||
@@ -1,42 +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.bootstrap;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
public class TileEntityRendering<T extends AEBaseBlockEntity> {
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
Function<BlockEntityRenderDispatcher, BlockEntityRenderer<T>> tileEntityRenderer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public TileEntityRendering<T> tileEntityRenderer(
|
||||
Function<BlockEntityRenderDispatcher, BlockEntityRenderer<T>> tileEntityRenderer) {
|
||||
this.tileEntityRenderer = tileEntityRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +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.bootstrap;
|
||||
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
/**
|
||||
* A callback that allows the rendering of a block 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 interface TileEntityRenderingCustomizer<T extends AEBaseBlockEntity> {
|
||||
|
||||
/**
|
||||
* Declared as a default method because we will carve out the implementations that
|
||||
* override this method on the Server side.
|
||||
*/
|
||||
default void customize(TileEntityRendering<T> rendering) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +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.bootstrap.components;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
|
||||
public class BlockColorComponent implements IInitComponent {
|
||||
|
||||
private final Block block;
|
||||
|
||||
private final BlockColorProvider blockColor;
|
||||
|
||||
public BlockColorComponent(Block block, BlockColorProvider blockColor) {
|
||||
this.block = block;
|
||||
this.blockColor = blockColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
MinecraftClient.getInstance().getBlockColors().registerColorProvider(this.blockColor, this.block);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
/**
|
||||
* Will be run during
|
||||
* {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}.
|
||||
*/
|
||||
public interface IClientSetupComponent extends IBootstrapComponent {
|
||||
|
||||
void setup();
|
||||
|
||||
}
|
||||
@@ -1,26 +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.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IInitComponent extends IBootstrapComponent {
|
||||
void initialize();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
public interface IItemColorRegistrationComponent extends IBootstrapComponent {
|
||||
|
||||
void register(ItemColors itemColors, BlockColors blockColors);
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IModelBakeComponent extends IBootstrapComponent {
|
||||
|
||||
void onModelsReloaded(Map<Identifier, BakedModel> loadedModels);
|
||||
|
||||
}
|
||||
@@ -1,26 +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.bootstrap.components;
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IPostInitComponent extends IBootstrapComponent {
|
||||
void postInitialize();
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
|
||||
import appeng.bootstrap.IBootstrapComponent;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ITileEntityRegistrationComponent extends IBootstrapComponent {
|
||||
void register();
|
||||
}
|
||||
@@ -1,40 +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.bootstrap.components;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ItemColorComponent implements IItemColorRegistrationComponent {
|
||||
private final Item item;
|
||||
|
||||
private final ItemColorProvider itemColor;
|
||||
|
||||
public ItemColorComponent(Item item, ItemColorProvider itemColor) {
|
||||
this.item = item;
|
||||
this.itemColor = itemColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ItemColors itemColors, BlockColors blockColors) {
|
||||
itemColors.register(this.itemColor, this.item);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +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.bootstrap.components;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
|
||||
public class ModelOverrideComponent implements IModelBakeComponent {
|
||||
|
||||
// Maps from resource path to customizer
|
||||
private final Map<String, BiFunction<Identifier, BakedModel, BakedModel>> customizer = new HashMap<>();
|
||||
|
||||
public void addOverride(String resourcePath, BiFunction<Identifier, BakedModel, BakedModel> customizer) {
|
||||
this.customizer.put(resourcePath, customizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModelsReloaded(final Map<Identifier, BakedModel> loadedModels) {
|
||||
Set<Identifier> keys = Sets.newHashSet(loadedModels.keySet());
|
||||
BakedModel missingModel = loadedModels.get(ModelLoader.MISSING);
|
||||
|
||||
for (Identifier location : keys) {
|
||||
if (!location.getNamespace().equals(AppEng.MOD_ID)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BakedModel orgModel = loadedModels.get(location);
|
||||
|
||||
// Don't customize the missing model. This causes Forge to swallow exceptions
|
||||
if (orgModel == missingModel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BiFunction<Identifier, BakedModel, BakedModel> customizer = this.customizer.get(location.getPath());
|
||||
if (customizer != null) {
|
||||
BakedModel newModel = customizer.apply(location, orgModel);
|
||||
|
||||
if (newModel != orgModel) {
|
||||
loadedModels.put(location, newModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
|
||||
/**
|
||||
* Sets the rendering type for a block.
|
||||
*/
|
||||
public class RenderTypeComponent implements IClientSetupComponent {
|
||||
|
||||
private final Block block;
|
||||
|
||||
private final RenderLayer renderType;
|
||||
|
||||
public RenderTypeComponent(Block block, RenderLayer renderType) {
|
||||
this.block = block;
|
||||
this.renderType = Preconditions.checkNotNull(renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
BlockRenderLayerMap.INSTANCE.putBlock(block, renderType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, 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.bootstrap.definitions;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
/**
|
||||
* @author GuntherDW
|
||||
*/
|
||||
public class TileEntityDefinition {
|
||||
|
||||
// To be notified when a Block declares that it uses this block entity
|
||||
private final Consumer<Block> addBlockListener;
|
||||
|
||||
public TileEntityDefinition(Consumer<Block> addBlockListener) {
|
||||
this.addBlockListener = addBlockListener;
|
||||
}
|
||||
|
||||
public void addBlock(Block block) {
|
||||
this.addBlockListener.accept(block);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user