-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * move compass to ldlib * Update settings.gradle * compass for test * data gen * data gen compass sections * done * Update GTMachines.java
- Loading branch information
Showing
473 changed files
with
13,750 additions
and
48 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
common/src/main/java/com/gregtechceu/gtceu/api/gui/compass/GTRecipeViewCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.gregtechceu.gtceu.api.gui.compass; | ||
|
||
import com.gregtechceu.gtceu.api.gui.GuiTextures; | ||
import com.gregtechceu.gtceu.api.recipe.GTRecipe; | ||
import com.gregtechceu.gtceu.integration.GTRecipeWidget; | ||
import com.lowdragmc.lowdraglib.gui.compass.component.RecipeComponent; | ||
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.item.crafting.Recipe; | ||
|
||
/** | ||
* @author KilaBash | ||
* @date 2023/7/30 | ||
* @implNote GTRecipeViewCreator | ||
*/ | ||
public class GTRecipeViewCreator implements RecipeComponent.RecipeViewCreator { | ||
@Override | ||
public ItemStack getWorkstation(Recipe<?> recipe) { | ||
if (recipe instanceof GTRecipe gtRecipe) { | ||
if (gtRecipe.recipeType.getIconSupplier() != null) { | ||
return gtRecipe.recipeType.getIconSupplier().get(); | ||
} | ||
} | ||
return new ItemStack(Items.BARRIER); | ||
} | ||
|
||
@Override | ||
public WidgetGroup getViewWidget(Recipe<?> recipe) { | ||
if (recipe instanceof GTRecipe gtRecipe) { | ||
var widget = new GTRecipeWidget(gtRecipe); | ||
widget.addSelfPosition(4, 4); | ||
var recipeGroup = new WidgetGroup(0, 0, widget.getSize().width + 8, widget.getSize().height + 8); | ||
recipeGroup.setBackground(GuiTextures.BACKGROUND); | ||
recipeGroup.addWidget(widget); | ||
return recipeGroup; | ||
|
||
} | ||
return new WidgetGroup(); | ||
} | ||
|
||
@Override | ||
public boolean test(Recipe<?> recipe) { | ||
return recipe instanceof GTRecipe; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
common/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/CompassNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
package com.gregtechceu.gtceu.api.registry.registrate; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.api.registry.GTRegistries; | ||
import com.gregtechceu.gtceu.utils.FormattingUtil; | ||
import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; | ||
import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; | ||
import com.lowdragmc.lowdraglib.json.SimpleIGuiTextureJsonUtils; | ||
import com.lowdragmc.lowdraglib.utils.Position; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.data.CachedOutput; | ||
import net.minecraft.data.DataGenerator; | ||
import net.minecraft.data.DataProvider; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.*; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* @author KilaBash | ||
* @date 2023/7/31 | ||
* @implNote CompassSectionBuilder | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
@Accessors(fluent = true, chain = true) | ||
public class CompassNode { | ||
@Getter | ||
private final ResourceLocation sectionID; | ||
@Getter | ||
private final ResourceLocation nodeID; | ||
@Setter | ||
private ResourceLocation page; | ||
@Setter | ||
private int size = 24; | ||
@Setter @Nullable // null - auto layout | ||
private Position position = null; | ||
private final Set<ResourceLocation> preNodes = new HashSet<>(); | ||
private final List<Supplier<? extends Item>> items = new ArrayList<>(); | ||
@Setter @Nullable | ||
private Supplier<IGuiTexture> icon = null; | ||
@Setter @Getter | ||
private String lang; | ||
|
||
private CompassNode(ResourceLocation sectionID, String nodeID) { | ||
this.sectionID = sectionID; | ||
lang = FormattingUtil.toEnglishName(nodeID); | ||
this.nodeID = GTCEu.id(sectionID.getPath() + "/" + nodeID); | ||
this.page = this.nodeID; | ||
} | ||
|
||
public static CompassNode getOrCreate(ResourceLocation sectionID, String nodeID) { | ||
var exist = GTRegistries.COMPASS_NODES.get(GTCEu.id(sectionID.getPath() + "/" + nodeID)); | ||
return exist == null ? new CompassNode(sectionID, nodeID).register() : exist; | ||
} | ||
|
||
public static CompassNode getOrCreate(CompassSection section, String nodeID) { | ||
return getOrCreate(section.sectionID(), nodeID); | ||
} | ||
|
||
public static CompassNode getOrCreate(CompassSection section, Supplier<? extends Item> item) { | ||
return getOrCreate(section.sectionID(), Registry.ITEM.getKey(item.get()).getPath()).addItem(item); | ||
} | ||
|
||
private CompassNode register() { | ||
GTRegistries.COMPASS_NODES.register(nodeID, this); | ||
return this; | ||
} | ||
|
||
public String getUnlocalizedKey() { | ||
return nodeID.toLanguageKey("compass.node"); | ||
} | ||
|
||
public CompassNode position(int x, int y) { | ||
this.position = new Position(x, y); | ||
return this; | ||
} | ||
|
||
public CompassNode addPreNode(ResourceLocation... nodeID) { | ||
preNodes.addAll(Arrays.stream(nodeID).toList()); | ||
return this; | ||
} | ||
|
||
public CompassNode addPreNode(CompassNode... node) { | ||
preNodes.addAll(Arrays.stream(node).map(CompassNode::nodeID).toList()); | ||
return this; | ||
} | ||
|
||
public CompassNode addItem(Supplier<? extends Item> item) { | ||
items.add(item); | ||
return this; | ||
} | ||
|
||
public static class CompassNodeProvider implements DataProvider { | ||
private final DataGenerator generator; | ||
private final Predicate<ResourceLocation> existingHelper; | ||
|
||
public CompassNodeProvider(DataGenerator generator, Predicate<ResourceLocation> existingHelper) { | ||
this.generator = generator; | ||
this.existingHelper = existingHelper; | ||
} | ||
|
||
@Override | ||
public void run(CachedOutput cache) { | ||
generate(generator.getOutputFolder(), cache); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "GTCEU's Compass Nodes"; | ||
} | ||
|
||
public void generate(Path path, CachedOutput cache) { | ||
path = path.resolve("assets/" + GTCEu.MOD_ID); | ||
Map<ResourceLocation, List<CompassNode>> nodesNOPosition = new HashMap<>(); | ||
try { | ||
for (var node : GTRegistries.COMPASS_NODES) { | ||
if (node.position == null) { | ||
nodesNOPosition.computeIfAbsent(node.sectionID, k -> new ArrayList<>()).add(node); | ||
} else { | ||
genNodeData(path, cache, node); | ||
} | ||
} | ||
for (List<CompassNode> nodes : nodesNOPosition.values()) { | ||
var size = nodes.size(); | ||
var row = (int) Math.ceil(Math.sqrt(size)); | ||
for (int i = 0; i < row; i++) { | ||
boolean done = false; | ||
for (int j = 0; j < row; j++) { | ||
int index = i * row + j; | ||
if (index < nodes.size()) { | ||
var node = nodes.get(index); | ||
node.position = new Position(-(row * 50) + 50 * j, 50 * i); | ||
genNodeData(path, cache, node); | ||
} else { | ||
done = true; | ||
break; | ||
} | ||
} | ||
if (done) break; | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void genNodeData(Path path, CachedOutput cache, CompassNode node) throws IOException { | ||
if (node.position == null) return; | ||
var resourcePath = "compass/nodes/" + node.nodeID.getPath() + ".json"; | ||
if (existingHelper.test(GTCEu.id(resourcePath))) return; | ||
|
||
JsonObject json = new JsonObject(); | ||
json.addProperty("section", node.sectionID.toString()); | ||
json.addProperty("page", node.page.toString()); | ||
if (node.icon == null) { | ||
if (!node.items.isEmpty()) { | ||
node.icon = () -> new ItemStackTexture(node.items.get(0).get()); | ||
} else { | ||
node.icon = () -> IGuiTexture.EMPTY; | ||
} | ||
} | ||
json.add("button_texture",SimpleIGuiTextureJsonUtils.toJson(node.icon.get())); | ||
if (node.size != 24) { | ||
json.addProperty("size", node.size); | ||
} | ||
var pos = new JsonArray(); | ||
pos.add(node.position.x); | ||
pos.add(node.position.y); | ||
json.add("position", pos); | ||
if (!node.preNodes.isEmpty()) { | ||
var pre = new JsonArray(); | ||
for (var preNode : node.preNodes) { | ||
pre.add(preNode.toString()); | ||
} | ||
json.add("pre_nodes", pre); | ||
} | ||
if (!node.items.isEmpty()) { | ||
var items = new JsonArray(); | ||
for (var item : node.items) { | ||
items.add(Registry.ITEM.getKey(item.get()).toString()); | ||
} | ||
json.add("items", items); | ||
} | ||
|
||
DataProvider.saveStable(cache, json, path.resolve(resourcePath)); | ||
} | ||
|
||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
common/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/CompassSection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.gregtechceu.gtceu.api.registry.registrate; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.api.registry.GTRegistries; | ||
import com.gregtechceu.gtceu.utils.FormattingUtil; | ||
import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; | ||
import com.lowdragmc.lowdraglib.json.SimpleIGuiTextureJsonUtils; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
import net.minecraft.data.CachedOutput; | ||
import net.minecraft.data.DataGenerator; | ||
import net.minecraft.data.DataProvider; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* @author KilaBash | ||
* @date 2023/7/31 | ||
* @implNote CompassSectionBuilder | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
@Accessors(fluent = true, chain = true) | ||
public class CompassSection { | ||
@Getter | ||
private final ResourceLocation sectionID; | ||
@Setter | ||
private Supplier<IGuiTexture> icon = () -> IGuiTexture.EMPTY; | ||
@Setter | ||
private Supplier<IGuiTexture> background = () -> IGuiTexture.EMPTY; | ||
@Setter | ||
private int priority = 99; | ||
@Setter @Getter | ||
private String lang; | ||
|
||
private CompassSection(String section) { | ||
this.sectionID = GTCEu.id(section); | ||
lang = FormattingUtil.toEnglishName(section); | ||
} | ||
|
||
public static CompassSection create(String section) { | ||
return new CompassSection(section); | ||
} | ||
|
||
public CompassSection register() { | ||
GTRegistries.COMPASS_SECTIONS.register(sectionID, this); | ||
return this; | ||
} | ||
|
||
public String getUnlocalizedKey() { | ||
return sectionID.toLanguageKey("compass.section"); | ||
} | ||
|
||
public static class CompassSectionProvider implements DataProvider { | ||
private final DataGenerator generator; | ||
private final Predicate<ResourceLocation> existingHelper; | ||
|
||
public CompassSectionProvider(DataGenerator generator, Predicate<ResourceLocation> existingHelper) { | ||
this.generator = generator; | ||
this.existingHelper = existingHelper; | ||
} | ||
|
||
@Override | ||
public void run(CachedOutput cache) { | ||
generate(generator.getOutputFolder(), cache); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "GTCEU's Compass Sections"; | ||
} | ||
|
||
public void generate(Path path, CachedOutput cache) { | ||
path = path.resolve("assets/" + GTCEu.MOD_ID); | ||
|
||
try { | ||
for (var section : GTRegistries.COMPASS_SECTIONS) { | ||
var resourcePath = "compass/sections/" + section.sectionID.getPath() + ".json"; | ||
if (existingHelper.test(GTCEu.id(resourcePath))) { | ||
continue; | ||
} | ||
JsonObject json = new JsonObject(); | ||
json.add("button_texture",SimpleIGuiTextureJsonUtils.toJson(section.icon.get())); | ||
json.add("background_texture",SimpleIGuiTextureJsonUtils.toJson(section.background.get())); | ||
json.addProperty("priority", section.priority); | ||
DataProvider.saveStable(cache, json, path.resolve(resourcePath)); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.