Files
Applied-Energistics-2/src/main/java/appeng/bootstrap/ItemDefinitionBuilder.java
T
shartte d1ba26311b One Spatial Dimension (#4570)
* Ported the "one spatial dimension" concept from pre-1.15

* Apply lighting updates after moving chunks.
Mark world data as dirty when changing it.

* Consolidated naming of spatial storage world/dimension.
Use server light manager to update lighting info in chunk.

* Save last transition information,
and add ae2 spatial command to interact with spatial storage.

* Formatting fixes.

* Improved docs for the origin generation.

Inverted condition on when the x/z axis are flipped.
Also added a helper to map a plot to a region file

* Remove TransitionResult since it's only used in lieu of a boolean.
Rework transition to make the checks BEFORE allocating a new cell.

* Removed unused imports.

Co-authored-by: yueh <yueh@users.noreply.github.com>
2020-08-10 11:29:07 +02:00

160 lines
5.0 KiB
Java

/*
* 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.dispenser.IDispenseItemBehavior;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
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 {
private final FeatureFactory factory;
private final String registryName;
private final Function<Item.Properties, Item> itemFactory;
private final EnumSet<AEFeature> features = EnumSet.noneOf(AEFeature.class);
private final List<Function<Item, IBootstrapComponent>> boostrapComponents = new ArrayList<>();
private final Item.Properties props = new Item.Properties();
private Supplier<IDispenseItemBehavior> dispenserBehaviorSupplier;
@OnlyIn(Dist.CLIENT)
private ItemRendering itemRendering;
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();
}
}
@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.Properties> 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<IDispenseItemBehavior> behavior) {
this.dispenserBehaviorSupplier = behavior;
return this;
}
@OnlyIn(Dist.CLIENT)
private void customizeForClient(ItemRenderingCustomizer callback) {
callback.customize(this.itemRendering);
}
@Override
public ItemDefinition build() {
props.group(itemGroup);
Item item = this.itemFactory.apply(props);
item.setRegistryName(AppEng.MOD_ID, this.registryName);
ItemDefinition definition = new ItemDefinition(this.registryName, 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) () -> {
IDispenseItemBehavior behavior = this.dispenserBehaviorSupplier.get();
DispenserBlock.registerDispenseBehavior(item, behavior);
});
}
this.factory.addBootstrapComponent((IItemRegistrationComponent) (side, reg) -> reg.register(item));
if (Platform.hasClientClasses()) {
this.itemRendering.apply(this.factory, item);
}
if (itemGroup instanceof AEItemGroup) {
((AEItemGroup) itemGroup).add(definition);
}
return definition;
}
}