Port more stuff

This commit is contained in:
Sebastian Hartte
2020-07-25 02:24:36 +02:00
parent 5bf05f6cb1
commit 8306f5bf0a
21 changed files with 240 additions and 438 deletions
@@ -1,6 +1,6 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
* 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
@@ -18,70 +18,61 @@
package appeng.client.render;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import appeng.client.render.cablebus.FacadeBuilder;
import appeng.items.parts.FacadeItem;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Direction;
import appeng.client.render.cablebus.FacadeBuilder;
import java.util.Objects;
import java.util.Random;
import java.util.function.Supplier;
/**
* This model used the provided FacadeBuilder to "slice" the item quads for the
* facade provided.
*
* @author covers1624
* This baked model class is used as a dispatcher to redirect the renderer to
* the *real* model that should be used based on the item stack. A custom Item
* Override List is used to accomplish this.
*/
public class FacadeBakedItemModel extends ForwardingBakedModel implements FabricBakedModel {
private final ItemStack textureStack;
public class FacadeBakedItemModel extends ForwardingBakedModel {
private final FacadeBuilder facadeBuilder;
private List<BakedQuad> quads = null;
private final Int2ObjectMap<Mesh> cache = new Int2ObjectArrayMap<>();
protected FacadeBakedItemModel(BakedModel base, ItemStack textureStack, FacadeBuilder facadeBuilder) {
this.wrapped = base;
this.textureStack = textureStack;
public FacadeBakedItemModel(BakedModel baseModel, FacadeBuilder facadeBuilder) {
this.wrapped = baseModel;
this.facadeBuilder = facadeBuilder;
}
@Override
public boolean isVanillaAdapter() {
return false;
}
@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
if (!(stack.getItem() instanceof FacadeItem)) {
return;
}
super.emitItemQuads(stack, randomSupplier, context);
if (quads == null) {
quads = new ArrayList<>();
quads.addAll(this.facadeBuilder.buildFacadeItemQuads(this.textureStack, Direction.NORTH));
quads = Collections.unmodifiableList(quads);
FacadeItem itemFacade = (FacadeItem) stack.getItem();
ItemStack textureItem = itemFacade.getTextureItem(stack);
int itemId = Item.getRawId(textureItem.getItem());
int hash = Objects.hash(itemId, textureItem.getTag());
Mesh mesh = this.cache.get(hash);
if (mesh == null) {
mesh = this.facadeBuilder.buildFacadeItemQuads(textureItem, Direction.NORTH);
this.cache.put(hash, mesh);
}
}
@Override
public boolean hasDepth() {
return false;
}
context.meshConsumer().accept(mesh);
@Override
public boolean isSideLit() {
return false;
}
@Override
public boolean isBuiltin() {
return false;
}
@Override
public ModelOverrideList getOverrides() {
return ModelOverrideList.EMPTY;
}
}
@@ -1,75 +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.client.render;
import appeng.client.render.cablebus.FacadeBuilder;
import appeng.items.parts.FacadeItem;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.Objects;
import java.util.Random;
import java.util.function.Supplier;
/**
* This baked model class is used as a dispatcher to redirect the renderer to
* the *real* model that should be used based on the item stack. A custom Item
* Override List is used to accomplish this.
*/
public class FacadeDispatcherBakedModel extends ForwardingBakedModel {
private final FacadeBuilder facadeBuilder;
private final Int2ObjectMap<FacadeBakedItemModel> cache = new Int2ObjectArrayMap<>();
public FacadeDispatcherBakedModel(BakedModel baseModel, FacadeBuilder facadeBuilder) {
this.wrapped = baseModel;
this.facadeBuilder = facadeBuilder;
}
@Override
public boolean isVanillaAdapter() {
return false;
}
@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
if (!(stack.getItem() instanceof FacadeItem)) {
return;
}
FacadeItem itemFacade = (FacadeItem) stack.getItem();
ItemStack textureItem = itemFacade.getTextureItem(stack);
int itemId = Item.getRawId(textureItem.getItem());
int hash = Objects.hash(itemId, textureItem.getTag());
FacadeBakedItemModel model = FacadeDispatcherBakedModel.this.cache.get(hash);
if (model == null) {
model = new FacadeBakedItemModel(FacadeDispatcherBakedModel.this.wrapped, textureItem,
FacadeDispatcherBakedModel.this.facadeBuilder);
FacadeDispatcherBakedModel.this.cache.put(hash, model);
}
context.fallbackConsumer().accept(model);
}
}
@@ -47,7 +47,7 @@ public class FacadeItemModel implements BasicUnbakedModel {
BakedModel bakedBaseModel = loader.bake(MODEL_BASE, rotationContainer);
FacadeBuilder facadeBuilder = new FacadeBuilder(loader);
return new FacadeDispatcherBakedModel(bakedBaseModel, facadeBuilder);
return new FacadeBakedItemModel(bakedBaseModel, facadeBuilder);
}
@Override
@@ -20,6 +20,7 @@ package appeng.client.render.cablebus;
import appeng.api.util.AEAxisAlignedBB;
import appeng.core.Api;
import appeng.mixins.MinecraftClientAccessor;
import appeng.parts.misc.CableAnchorPart;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadClamper;
import appeng.thirdparty.codechicken.lib.model.pipeline.transformers.QuadCornerKicker;
@@ -33,10 +34,10 @@ import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
@@ -138,26 +139,9 @@ public class FacadeBuilder {
return stems;
}
// private final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> BakedPipeline.builder()
// // Clamper is responsible for clamping the vertex to the bounds specified.
// .addElement("clamper", QuadClamper.FACTORY)
// // Strips faces if they match a mask.
// .addElement("face_stripper", QuadFaceStripper.FACTORY)
// // Kicks the edge inner corners in, solves Z fighting
// .addElement("corner_kicker", QuadCornerKicker.FACTORY)
// // Re-Interpolates the UV's for the quad.
// .addElement("interp", QuadReInterpolator.FACTORY)
// // Tints the quad if we need it to. Disabled by default.
// .addElement("tinter", QuadTinter.FACTORY, false)
// // Overrides the quad's alpha if we are forcing transparent facades.
// .addElement("transparent", QuadAlphaOverride.FACTORY, false, e -> e.setAlphaOverride(0x4C / 255F)).build()//
// );
public Mesh getFacadeMesh(CableBusRenderState renderState,
Supplier<Random> rand,
Function<Identifier, BakedModel> modelLookup) {
//FIXME BakedPipeline pipeline = this.pipelines.get();
//FIXME Quad collectorQuad = this.collectors.get();
boolean transparent = Api.instance().partHelper().getCableRenderMode().transparentFacades;
Map<Direction, FacadeRenderState> facadeStates = renderState.getFacades();
List<Box> partBoxes = renderState.getBoundingBoxes();
@@ -225,7 +209,7 @@ public class FacadeBuilder {
tmpBB.maxX -= offset;
break;
default:
throw new RuntimeException("Switch falloff. " + String.valueOf(face));
throw new RuntimeException("Switch falloff. " + face);
}
}
}
@@ -299,10 +283,10 @@ public class FacadeBuilder {
interpolator.transform(emitter);
// Tints the quad if we need it to. Disabled by default.
if (quadTinter != null) {
quadTinter.transform(emitter);
}
// Tints the quad if we need it to. Disabled by default.
if (quadTinter != null) {
quadTinter.transform(emitter);
}
// // Overrides the quad's alpha if we are forcing transparent facades.
// .addElement("transparent", QuadAlphaOverride.FACTORY, false, e -> e.setAlphaOverride(0x4C / 255F)).build()//
@@ -311,34 +295,6 @@ public class FacadeBuilder {
}
}
}
// FIXME FABRIC List<BakedQuad> modelQuads = new ArrayList<>();
// FIXME FABRIC modelQuads.addAll(gatherQuads(model, blockState, rand));
// FIXME FABRIC // No quads.. Cool, next!
// FIXME FABRIC if (modelQuads.isEmpty()) {
// FIXME FABRIC continue;
// FIXME FABRIC }
// FIXME FABRIC
// FIXME FABRIC // Grab out pipeline elements.
// FIXME FABRIC QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
// FIXME FABRIC QuadFaceStripper edgeStripper = pipeline.getElement("face_stripper", QuadFaceStripper.class);
// FIXME FABRIC QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
// FIXME FABRIC QuadCornerKicker kicker = pipeline.getElement("corner_kicker", QuadCornerKicker.class);
// FIXME FABRIC
// FIXME FABRIC // Set global element states.
// FIXME FABRIC
// FIXME FABRIC // Setup the kicker.
// FIXME FABRIC kicker.setSide(sideIndex);
// FIXME FABRIC kicker.setFacadeMask(facadeMask);
// FIXME FABRIC kicker.setBox(fullBounds);
// FIXME FABRIC kicker.setThickness(thinFacades ? THIN_THICKNESS : THICK_THICKNESS);
// FIXME FABRIC
// FIXME FABRIC for (BakedQuad quad : modelQuads) {
// FIXME FABRIC // lookup the format in CachedFormat.
// FIXME FABRIC CachedFormat format = CachedFormat.lookup(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
// FIXME FABRIC }
}
return meshBuilder.build();
@@ -350,12 +306,14 @@ public class FacadeBuilder {
*
* @return The model.
*/
public List<BakedQuad> buildFacadeItemQuads(ItemStack textureItem, Direction side) {
List<BakedQuad> facadeQuads = new ArrayList<>();
public Mesh buildFacadeItemQuads(ItemStack textureItem, Direction side) {
MeshBuilder meshBuilder = renderer.meshBuilder();
QuadEmitter emitter = meshBuilder.getEmitter();
BakedModel model = MinecraftClient.getInstance().getItemRenderer().getHeldItemModel(textureItem, null,
null);
List<BakedQuad> modelQuads = gatherQuads(model, null, new Random());
List<BakedQuad> modelQuads = model.getQuads(null, null, new Random());
//FIXME BakedPipeline pipeline = this.pipelines.get();
//FIXME Quad collectorQuad = this.collectors.get();
@@ -364,7 +322,45 @@ public class FacadeBuilder {
// FIXME QuadClamper clamper = pipeline.getElement("clamper", QuadClamper.class);
// FIXME QuadTinter tinter = pipeline.getElement("tinter", QuadTinter.class);
QuadReInterpolator interpolator = new QuadReInterpolator();
ItemColors itemColors = ((MinecraftClientAccessor) MinecraftClient.getInstance()).getItemColors();
QuadClamper clamper = new QuadClamper(THICK_FACADE_BOXES[side.ordinal()]);
for (int cullFaceIdx = 0; cullFaceIdx <= ModelHelper.NULL_FACE_ID; cullFaceIdx++) {
Direction cullFace = ModelHelper.faceFromIndex(cullFaceIdx);
List<BakedQuad> quads = model.getQuads(null, cullFace, new Random());
for (BakedQuad quad : quads) {
QuadTinter quadTinter = null;
// Prebake the color tint into the quad
if (quad.getColorIndex() != -1) {
quadTinter = new QuadTinter(itemColors.getColorMultiplier(textureItem, quad.getColorIndex()));
}
emitter.fromVanilla(quad.getVertexData(), 0, false);
emitter.cullFace(cullFace);
emitter.nominalFace(quad.getFace());
interpolator.setInputQuad(emitter);
if (!clamper.transform(emitter)) {
continue;
}
interpolator.transform(emitter);
// Tints the quad if we need it to. Disabled by default.
if (quadTinter != null) {
quadTinter.transform(emitter);
}
emitter.emit();
}
}
for (BakedQuad quad : modelQuads) {
// Lookup the CachedFormat for this quads format.
// FIXME CachedFormat format = CachedFormat.lookup(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
// Reset the pipeline.
@@ -390,17 +386,7 @@ public class FacadeBuilder {
// FIXME facadeQuads.add(collectorQuad.bake());
// FIXME }
}
return facadeQuads;
}
// Helper to gather all quads from a model into a list.
private static List<BakedQuad> gatherQuads(BakedModel model, BlockState state, Random rand) {
List<BakedQuad> modelQuads = new ArrayList<>();
for (Direction face : Direction.values()) {
modelQuads.addAll(model.getQuads(state, face, rand));
}
modelQuads.addAll(model.getQuads(state, null, rand));
return modelQuads;
return meshBuilder.build();
}
/**
+1 -1
View File
@@ -72,7 +72,7 @@ public final class AEConfig {
// Config instance
private static AEConfig instance;
static void load(File configFolder) {
public static void load(File configFolder) {
if (instance != null) {
throw new IllegalStateException();
}
+3 -9
View File
@@ -73,7 +73,6 @@ import appeng.fluids.container.FluidLevelEmitterContainer;
import appeng.fluids.container.FluidStorageBusContainer;
import appeng.fluids.container.FluidTerminalContainer;
import appeng.fluids.registries.BasicFluidCellGuiHandler;
import appeng.forge.data.AE2DataGenerators;
import appeng.hooks.RegisterDimensionTypeCallback;
import appeng.hooks.ToolItemHook;
import appeng.items.parts.FacadeItem;
@@ -168,7 +167,7 @@ public abstract class AppEngBase implements AppEng {
AEConfig.load(FabricLoader.getInstance().getConfigDirectory());
CreativeTab.init();
// FIXME FABRIC new FacadeItemGroup(); // This call has a side-effect (adding it to the creative screen)
FacadeCreativeTab.init() ;// This call has a side-effect (adding it to the creative screen)
AeStats.register();
advancementTriggers = new AdvancementTriggers(CriteriaRegisterMixin::callRegister);
@@ -188,11 +187,6 @@ public abstract class AppEngBase implements AppEng {
setupInternalRegistries();
if (System.getProperty("appeng2.generatedataendexit", "false").equals("true")) {
AE2DataGenerators.dump();
System.exit(0);
}
}
public static void setupInternalRegistries() {
@@ -643,11 +637,11 @@ public abstract class AppEngBase implements AppEng {
false,
false,
true,
true,
false,
false,
256,
BlockTags.INFINIBURN_OVERWORLD.getId(),
0.5f
1.0f
)
);
});
@@ -0,0 +1,86 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core;
import appeng.items.parts.FacadeItem;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;
import java.util.ArrayList;
import java.util.List;
public final class FacadeCreativeTab {
private static List<ItemStack> subTypes = null;
public static void init() {
FabricItemGroupBuilder.create(AppEng.makeId("facades"))
.icon(() -> {
calculateSubTypes();
if (subTypes.isEmpty()) {
return new ItemStack(Items.CAKE);
}
return subTypes.get(0);
})
.appendItems(FacadeCreativeTab::fill)
.build();
}
private static void fill(List<ItemStack> items) {
calculateSubTypes();
items.addAll(subTypes);
}
private static void calculateSubTypes() {
if (subTypes != null) {
return;
}
subTypes = new ArrayList<>(1000);
FacadeItem itemFacade = (FacadeItem) Api.INSTANCE.definitions().items().facade().item();
for (final Block b : Registry.BLOCK) {
try {
final Item item = Item.fromBlock(b);
if (item == Items.AIR) {
continue;
}
Item blockItem = b.asItem();
if (blockItem != Items.AIR && blockItem.getGroup() != null) {
final DefaultedList<ItemStack> tmpList = DefaultedList.of();
b.addStacksForDisplay(blockItem.getGroup(), tmpList);
for (final ItemStack l : tmpList) {
final ItemStack facade = itemFacade.createFacadeForItem(l, false);
if (!facade.isEmpty()) {
subTypes.add(facade);
}
}
}
} catch (final Throwable t) {
// just absorb..
}
}
}
}
@@ -1,29 +0,0 @@
package appeng.forge.data;
import appeng.forge.data.providers.loot.BlockDropProvider;
import appeng.forge.data.providers.recipes.SlabStairRecipes;
import appeng.forge.data.providers.tags.ConventionTagProvider;
import net.minecraft.data.DataGenerator;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
public class AE2DataGenerators {
public static void dump() {
Path output = Paths.get("../src/generated/resources");
DataGenerator generator = new DataGenerator(output, Collections.emptyList());
generator.install(new BlockDropProvider(output));
generator.install(new SlabStairRecipes(output));
generator.install(new ConventionTagProvider(output));
try {
generator.run();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -1,14 +0,0 @@
package appeng.forge.data.providers;
import net.minecraft.data.DataProvider;
import appeng.api.definitions.IBlocks;
import appeng.api.definitions.IItems;
import appeng.api.definitions.IMaterials;
import appeng.core.Api;
public interface IAE2DataProvider extends DataProvider {
IBlocks BLOCKS = Api.instance().definitions().blocks();
IItems ITEMS = Api.instance().definitions().items();
IMaterials MATERIALS = Api.instance().definitions().materials();
}
@@ -1,100 +0,0 @@
package appeng.forge.data.providers.loot;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nonnull;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import net.minecraft.block.Block;
import net.minecraft.data.DataCache;
import net.minecraft.data.DataProvider;
import net.minecraft.data.server.BlockLootTableGenerator;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.loot.*;
import net.minecraft.loot.condition.SurvivesExplosionLootCondition;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.entry.LeafEntry;
import net.minecraft.loot.function.ApplyBonusLootFunction;
import net.minecraft.loot.function.SetCountLootFunction;
import net.minecraft.util.Identifier;
import appeng.core.AppEng;
import appeng.forge.data.providers.IAE2DataProvider;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
public class BlockDropProvider extends BlockLootTableGenerator implements IAE2DataProvider {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final Path outputFolder;
private Map<Block, Function<Block, LootTable.Builder>> overrides = ImmutableMap.<Block, Function<Block, LootTable.Builder>>builder()
.put(BLOCKS.matrixFrame().block(), $ -> LootTable.builder())
.put(BLOCKS.quartzOre().block(),
b -> dropsWithSilkTouch(BLOCKS.quartzOre().block(),
applyExplosionDecay(BLOCKS.quartzOre().block(),
ItemEntry.builder(MATERIALS.certusQuartzCrystal().item())
.apply(SetCountLootFunction.builder(UniformLootTableRange.between(1.0F, 2.0F)))
.apply(ApplyBonusLootFunction.uniformBonusCount(Enchantments.FORTUNE)))))
.put(BLOCKS.quartzOreCharged().block(),
b -> dropsWithSilkTouch(BLOCKS.quartzOreCharged().block(),
applyExplosionDecay(BLOCKS.quartzOreCharged().block(),
ItemEntry.builder(MATERIALS.certusQuartzCrystalCharged().item())
.apply(SetCountLootFunction.builder(UniformLootTableRange.between(1.0F, 2.0F)))
.apply(ApplyBonusLootFunction.uniformBonusCount(Enchantments.FORTUNE)))))
.build();
public BlockDropProvider(Path outputFolder) {
this.outputFolder = outputFolder;
}
@Override
public void run(DataCache cache) throws IOException {
for (Map.Entry<RegistryKey<Block>, Block> entry : Registry.BLOCK.getEntries()) {
LootTable.Builder builder;
Identifier id = entry.getKey().getValue();
if (id.getNamespace().equals(AppEng.MOD_ID)) {
builder = overrides.getOrDefault(entry.getValue(), this::defaultBuilder).apply(entry.getValue());
DataProvider.writeToPath(GSON, cache, toJson(builder), getPath(outputFolder, id));
}
}
}
private LootTable.Builder defaultBuilder(Block block) {
LeafEntry.Builder<?> entry = ItemEntry.builder(block);
LootPool.Builder pool = LootPool.builder().rolls(ConstantLootTableRange.create(1)).with(entry)
.conditionally(SurvivesExplosionLootCondition.builder());
return LootTable.builder().pool(pool);
}
private Path getPath(Path root, Identifier id) {
return root.resolve("data/" + id.getNamespace() + "/loot_tables/blocks/" + id.getPath() + ".json");
}
public JsonElement toJson(LootTable.Builder builder) {
return LootManager.toJson(finishBuilding(builder));
}
@Nonnull
public LootTable finishBuilding(LootTable.Builder builder) {
return builder.type(LootContextTypes.BLOCK).build();
}
@Nonnull
@Override
public String getName() {
return AppEng.MOD_NAME + " Block Drops";
}
}
@@ -1,96 +0,0 @@
package appeng.forge.data.providers.recipes;
import appeng.api.definitions.IBlockDefinition;
import appeng.core.AppEng;
import appeng.forge.data.providers.IAE2DataProvider;
import com.google.gson.JsonObject;
import net.minecraft.block.Block;
import net.minecraft.data.DataCache;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.data.server.recipe.ShapedRecipeJsonFactory;
import net.minecraft.data.server.recipe.SingleItemRecipeJsonFactory;
import net.minecraft.recipe.Ingredient;
import net.minecraft.util.Identifier;
import java.nio.file.Path;
import java.util.function.Consumer;
import static net.minecraft.data.server.RecipesProvider.conditionsFromItem;
import static net.minecraft.data.server.RecipesProvider.saveRecipe;
import static net.minecraft.data.server.RecipesProvider.saveRecipeAdvancement;
public class SlabStairRecipes implements IAE2DataProvider {
IBlockDefinition[][] blocks = {{BLOCKS.skyStoneBlock(), BLOCKS.skyStoneSlab(), BLOCKS.skyStoneStairs()},
{BLOCKS.smoothSkyStoneBlock(), BLOCKS.smoothSkyStoneSlab(), BLOCKS.smoothSkyStoneStairs()},
{BLOCKS.skyStoneBrick(), BLOCKS.skyStoneBrickSlab(), BLOCKS.skyStoneBrickStairs()},
{BLOCKS.skyStoneSmallBrick(), BLOCKS.skyStoneSmallBrickSlab(), BLOCKS.skyStoneSmallBrickStairs()},
{BLOCKS.fluixBlock(), BLOCKS.fluixSlab(), BLOCKS.fluixStairs()},
{BLOCKS.quartzBlock(), BLOCKS.quartzSlab(), BLOCKS.quartzStairs()},
{BLOCKS.chiseledQuartzBlock(), BLOCKS.chiseledQuartzSlab(), BLOCKS.chiseledQuartzStairs()},
{BLOCKS.quartzPillar(), BLOCKS.quartzPillarSlab(), BLOCKS.quartzPillarStairs()},};
private final Path outputPath;
private final Consumer<RecipeJsonProvider> consumer;
private DataCache cache;
public SlabStairRecipes(Path outputPath) {
this.outputPath = outputPath;
this.consumer = this::provideRecipe;
}
public void run(DataCache cache) {
this.cache = cache;
for (IBlockDefinition[] block : blocks) {
slabRecipe(block[0], block[1]);
stairRecipe(block[0], block[2]);
}
}
private void slabRecipe(IBlockDefinition block, IBlockDefinition slabs) {
Block inputBlock = block.block();
Block outputBlock = slabs.block();
ShapedRecipeJsonFactory.create(slabs.block(), 6).pattern("###").input('#', inputBlock)
.criterion(criterionName(block), conditionsFromItem(inputBlock))
.offerTo(consumer, new Identifier(AppEng.MOD_ID, "shaped/slabs/" + block.identifier()));
SingleItemRecipeJsonFactory.create(Ingredient.ofItems(inputBlock), outputBlock, 2)
.create(criterionName(block), conditionsFromItem(inputBlock))
.offerTo(consumer, new Identifier(AppEng.MOD_ID, "block_cutter/slabs/" + slabs.identifier()));
}
private void stairRecipe(IBlockDefinition block, IBlockDefinition stairs) {
Block inputBlock = block.block();
Block outputBlock = stairs.block();
ShapedRecipeJsonFactory.create(outputBlock, 4).pattern("# ").pattern("## ").pattern("###")
.input('#', inputBlock).criterion(criterionName(block), conditionsFromItem(inputBlock))
.offerTo(consumer, new Identifier(AppEng.MOD_ID, "shaped/stairs/" + block.identifier()));
SingleItemRecipeJsonFactory.create(Ingredient.ofItems(inputBlock), outputBlock)
.create(criterionName(block), conditionsFromItem(inputBlock))
.offerTo(consumer, new Identifier(AppEng.MOD_ID, "block_cutter/stairs/" + stairs.identifier()));
}
private void provideRecipe(RecipeJsonProvider recipeJsonProvider) {
saveRecipe(cache, recipeJsonProvider.toJson(), outputPath.resolve("data/" + recipeJsonProvider.getRecipeId().getNamespace() + "/recipes/" + recipeJsonProvider.getRecipeId().getPath() + ".json"));
JsonObject jsonObject = recipeJsonProvider.toAdvancementJson();
if (jsonObject != null) {
saveRecipeAdvancement(cache, jsonObject, outputPath.resolve("data/" + recipeJsonProvider.getRecipeId().getNamespace() + "/advancements/" + recipeJsonProvider.getAdvancementId().getPath() + ".json"));
}
}
private String criterionName(IBlockDefinition block) {
return String.format("has_%s", block.identifier());
}
@Override
public String getName() {
return AppEng.MOD_NAME + " Slabs and Stairs";
}
}
@@ -1,112 +0,0 @@
package appeng.forge.data.providers.tags;
import appeng.core.AppEng;
import net.minecraft.block.Blocks;
import net.minecraft.item.Items;
import java.io.IOException;
import java.nio.file.Path;
public class ConventionTagProvider extends TagProvider {
public ConventionTagProvider(Path outputPath) {
super(outputPath);
}
@Override
protected void generate() throws IOException {
// Dyes
addItemTag("white_dyes", Items.WHITE_DYE);
addItemTag("orange_dyes", Items.ORANGE_DYE);
addItemTag("magenta_dyes", Items.MAGENTA_DYE);
addItemTag("light_blue_dyes", Items.LIGHT_BLUE_DYE);
addItemTag("yellow_dyes", Items.YELLOW_DYE);
addItemTag("lime_dyes", Items.LIME_DYE);
addItemTag("pink_dyes", Items.PINK_DYE);
addItemTag("gray_dyes", Items.GRAY_DYE);
addItemTag("light_gray_dyes", Items.LIGHT_GRAY_DYE);
addItemTag("cyan_dyes", Items.CYAN_DYE);
addItemTag("purple_dyes", Items.PURPLE_DYE);
addItemTag("blue_dyes", Items.BLUE_DYE);
addItemTag("brown_dyes", Items.BROWN_DYE);
addItemTag("green_dyes", Items.GREEN_DYE);
addItemTag("red_dyes", Items.RED_DYE);
addItemTag("black_dyes", Items.BLACK_DYE);
addItemTag("iron_ingots", Items.IRON_INGOT);
addItemTag("iron_ores", Items.IRON_ORE);
addItemTag("gold_ingots", Items.GOLD_INGOT);
addItemTag("gold_ores", Items.GOLD_ORE);
addItemTag("glowstone_dusts", Items.GLOWSTONE_DUST);
addItemTag("wooden_rods", Items.STICK);
addItemTag("nether_quartz_ores", Items.NETHER_QUARTZ_ORE);
addItemTag("nether_quartz_crystals", Items.QUARTZ);
addItemTag("sand_blocks", Items.SAND, Items.RED_SAND);
addItemTag("diamonds", Items.DIAMOND);
addItemTag("wooden_chests", Items.CHEST, Items.TRAPPED_CHEST);
addItemTag("wheat_crops", Items.WHEAT);
addItemTag("redstone_dusts", Items.REDSTONE);
addItemTag("ender_pearls", Items.ENDER_PEARL);
addItemTag("terracotta_blocks", Items.TERRACOTTA,
Items.WHITE_TERRACOTTA,
Items.ORANGE_TERRACOTTA,
Items.MAGENTA_TERRACOTTA,
Items.LIGHT_BLUE_TERRACOTTA,
Items.YELLOW_TERRACOTTA,
Items.LIME_TERRACOTTA,
Items.PINK_TERRACOTTA,
Items.GRAY_TERRACOTTA,
Items.LIGHT_GRAY_TERRACOTTA,
Items.CYAN_TERRACOTTA,
Items.PURPLE_TERRACOTTA,
Items.BLUE_TERRACOTTA,
Items.BROWN_TERRACOTTA,
Items.GREEN_TERRACOTTA,
Items.RED_TERRACOTTA,
Items.BLACK_TERRACOTTA
);
addItemTag("glass_blocks", Items.GLASS,
Items.WHITE_STAINED_GLASS,
Items.ORANGE_STAINED_GLASS,
Items.MAGENTA_STAINED_GLASS,
Items.LIGHT_BLUE_STAINED_GLASS,
Items.YELLOW_STAINED_GLASS,
Items.LIME_STAINED_GLASS,
Items.PINK_STAINED_GLASS,
Items.GRAY_STAINED_GLASS,
Items.LIGHT_GRAY_STAINED_GLASS,
Items.CYAN_STAINED_GLASS,
Items.PURPLE_STAINED_GLASS,
Items.BLUE_STAINED_GLASS,
Items.BROWN_STAINED_GLASS,
Items.GREEN_STAINED_GLASS,
Items.RED_STAINED_GLASS,
Items.BLACK_STAINED_GLASS
);
addBlockTag("glass_blocks", Blocks.GLASS,
Blocks.WHITE_STAINED_GLASS,
Blocks.ORANGE_STAINED_GLASS,
Blocks.MAGENTA_STAINED_GLASS,
Blocks.LIGHT_BLUE_STAINED_GLASS,
Blocks.YELLOW_STAINED_GLASS,
Blocks.LIME_STAINED_GLASS,
Blocks.PINK_STAINED_GLASS,
Blocks.GRAY_STAINED_GLASS,
Blocks.LIGHT_GRAY_STAINED_GLASS,
Blocks.CYAN_STAINED_GLASS,
Blocks.PURPLE_STAINED_GLASS,
Blocks.BLUE_STAINED_GLASS,
Blocks.BROWN_STAINED_GLASS,
Blocks.GREEN_STAINED_GLASS,
Blocks.RED_STAINED_GLASS,
Blocks.BLACK_STAINED_GLASS
);
}
@Override
public String getName() {
return AppEng.MOD_NAME + " Convention Tags";
}
}
@@ -1,84 +0,0 @@
package appeng.forge.data.providers.tags;
import appeng.core.AppEng;
import appeng.forge.data.providers.IAE2DataProvider;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.block.Block;
import net.minecraft.data.DataCache;
import net.minecraft.data.DataProvider;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public abstract class TagProvider implements IAE2DataProvider {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
protected static final String CONVENTION_NAMESPACE = "c";
protected static final String TYPE_ITEMS = "items";
protected static final String TYPE_BLOCKS = "blocks";
private final Path outputPath;
private DataCache cache;
protected TagProvider(Path outputPath) {
this.outputPath = outputPath;
}
@Override
public void run(DataCache cache) throws IOException {
this.cache = cache;
try {
generate();
} finally {
this.cache = null;
}
}
protected abstract void generate() throws IOException;
protected void addItemTag(String name, ItemConvertible... items) throws IOException {
List<String> itemIds = Arrays.stream(items)
.map(ItemConvertible::asItem)
.map(Registry.ITEM::getId)
.map(Identifier::toString)
.collect(Collectors.toList());
writeTagFile(CONVENTION_NAMESPACE, TYPE_ITEMS, name, itemIds);
}
protected void addBlockTag(String name, Block... blocks) throws IOException {
List<String> itemIds = Arrays.stream(blocks)
.map(Registry.BLOCK::getId)
.map(Identifier::toString)
.collect(Collectors.toList());
writeTagFile(CONVENTION_NAMESPACE, TYPE_BLOCKS, name, itemIds);
}
protected void writeTagFile(String namespace, String tagType, String tagName, List<String> entries) throws IOException {
JsonObject rootObj = new JsonObject();
JsonArray valuesArr = new JsonArray();
for (String entry : entries) {
valuesArr.add(entry);
}
rootObj.add("values", valuesArr);
Path path = outputPath.resolve("data/" + namespace + "/tags/" + tagType + "/" + tagName + ".json");
DataProvider.writeToPath(GSON, this.cache, rootObj, path);
}
@Override
public String getName() {
return AppEng.MOD_NAME + " Convention Tags";
}
}
@@ -0,0 +1,14 @@
package appeng.mixins;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.item.ItemColors;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(MinecraftClient.class)
public interface MinecraftClientAccessor {
@Accessor
ItemColors getItemColors();
}
@@ -51,8 +51,8 @@ public final class SpatialDimensionManager implements ISpatialDimension {
public static final SkyProperties STORAGE_SKY = new SkyProperties(
Float.NaN /* disables clouds */,
false,
SkyProperties.SkyType.NORMAL /* we use a custom render mixin */,
false,
SkyProperties.SkyType.NONE /* we use a custom render mixin */,
true,
false
) {
@Override