Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Research overhaul/tech tree #2829

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
21280e6
extremely crude tech list
NotAPenguin0 Aug 4, 2024
8f0526b
remove that singleblock
NotAPenguin0 Aug 4, 2024
ac8ac8b
Merge branch 'master' into tech-tree
NotAPenguin0 Aug 4, 2024
2f79052
Create accessor item that opens tech tree on right click
NotAPenguin0 Aug 4, 2024
0da3841
open tech tree with keybind
NotAPenguin0 Aug 5, 2024
00616cb
simple list of techs
NotAPenguin0 Aug 5, 2024
7d02488
add prereq interface and crude layouting
NotAPenguin0 Aug 5, 2024
8b0b009
keep track of currently selected tech
NotAPenguin0 Aug 5, 2024
5e6ccdb
only init keybinds on client side
NotAPenguin0 Aug 5, 2024
502cd70
Merge branch 'master' into tech-tree
Dream-Master Aug 18, 2024
77482c6
swap to togglebutton p1
NotAPenguin0 Aug 5, 2024
42f8975
Revert "swap to togglebutton p1"
NotAPenguin0 Aug 5, 2024
e85cb6f
more gui experiments
NotAPenguin0 Aug 7, 2024
9df766f
implement graph layering algorithm instead of dumb depth system
NotAPenguin0 Aug 19, 2024
ddb1619
spotless
NotAPenguin0 Aug 19, 2024
3a2f15b
update to new modularui api
NotAPenguin0 Aug 19, 2024
a920ede
very crude drawing of dependencies
NotAPenguin0 Aug 19, 2024
a72a486
slightly better lines
NotAPenguin0 Aug 19, 2024
75d31f9
remove tech f for debugging
NotAPenguin0 Aug 20, 2024
4dca85a
bake tech tree construction on game load and log its timing
NotAPenguin0 Aug 20, 2024
102c913
Merge branch 'master' into tech-tree
Dream-Master Aug 20, 2024
fcd2041
Merge branch 'master' into tech-tree
Dream-Master Aug 23, 2024
a7ddea2
Tech tree now with curvy lines (#2969)
CookieBrigade Aug 25, 2024
b0e3bea
Merge branch 'master' into tech-tree
Dream-Master Aug 26, 2024
28e738d
Merge branch 'master' into tech-tree
Dream-Master Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/gregtech/GT_Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cleanroommc.modularui.factory.GuiManager;
import com.google.common.base.Stopwatch;
import com.google.common.collect.SetMultimap;
import com.gtnewhorizon.gtnhlib.config.ConfigException;
Expand Down Expand Up @@ -77,6 +78,7 @@
import gregtech.api.util.GT_SpawnEventHandler;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.item.ItemHolder;
import gregtech.client.GT_KeyBindings;
import gregtech.common.GT_DummyWorld;
import gregtech.common.GT_Network;
import gregtech.common.GT_Proxy;
Expand Down Expand Up @@ -104,6 +106,8 @@
import gregtech.common.misc.spaceprojects.commands.SPM_Command;
import gregtech.common.misc.spaceprojects.commands.SP_Command;
import gregtech.common.misc.spaceprojects.commands.SpaceProject_Command;
import gregtech.common.misc.techtree.gui.GuiOpenEventHandler;
import gregtech.common.misc.techtree.gui.TechTreeGuiFactory;
import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_CraftingInput_ME;
import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase;
import gregtech.crossmod.holoinventory.HoloInventory;
Expand Down Expand Up @@ -137,6 +141,7 @@
import gregtech.loaders.preload.GT_Loader_MultiTileEntities;
import gregtech.loaders.preload.GT_Loader_OreDictionary;
import gregtech.loaders.preload.GT_Loader_OreProcessing;
import gregtech.loaders.preload.GT_Loader_Technologies;
import gregtech.loaders.preload.GT_PreLoad;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeOutput;
Expand Down Expand Up @@ -315,11 +320,20 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
.getParentFile());
GT_PreLoad.adjustScrap();

if (isClientSide()) {
GT_KeyBindings.registerBindings();
}

AEApi.instance()
.registries()
.interfaceTerminal()
.register(GT_MetaTileEntity_Hatch_CraftingInput_ME.class);

GuiManager.registerFactory(TechTreeGuiFactory.INSTANCE);
FMLCommonHandler.instance()
.bus()
.register(GuiOpenEventHandler.INSTANCE);

GT_PreLoad.runMineTweakerCompat();

new GT_Loader_OreProcessing().run();
Expand All @@ -335,6 +349,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
new GT_CoverBehaviorLoader().run();
new GT_SonictronLoader().run();
new GT_SpawnEventHandler();
new GT_Loader_Technologies().run();

// populate itemstack instance for NBT check in GT_Recipe
setItemStacks();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/enums/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,7 @@ public enum ItemList implements IItemContainer {
BlockQuarkPipe,
BlockQuarkReleaseChamber,
BlockQuarkContainmentCasing,
TechTreeAccessor,
LargeFluidExtractor,
AcceleratorLV,
AcceleratorMV,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gregtech.api.gui.modularui2;

public class UITextureAdapter extends com.cleanroommc.modularui.drawable.UITexture {

public UITextureAdapter(com.gtnewhorizons.modularui.api.drawable.UITexture texture) {
super(texture.location, texture.u0, texture.v0, texture.u1, texture.v1, false);
}
}
21 changes: 21 additions & 0 deletions src/main/java/gregtech/api/gui/modularui2/UITextures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package gregtech.api.gui.modularui2;

import com.cleanroommc.modularui.drawable.AdaptableUITexture;
import com.cleanroommc.modularui.drawable.UITexture;

import gregtech.api.enums.Mods;
import gregtech.api.gui.modularui.GT_UITextures;

public class UITextures {

public static final UITexture BACKGROUND_SCREEN_BLUE = AdaptableUITexture.builder()
.location(Mods.TecTech.ID, "gui/background/screen_blue")
.adaptable(2)
.imageSize(90, 72)
.build();

public static final UITexture BUTTON_STANDARD_TOGGLE_UP = new UITextureAdapter(
GT_UITextures.BUTTON_STANDARD_TOGGLE.getSubArea(0f, 0f, 0.5f, 0.5f));
public static final UITexture BUTTON_STANDARD_TOGGLE_DOWN = new UITextureAdapter(
GT_UITextures.BUTTON_STANDARD_TOGGLE.getSubArea(0.5f, 0.5f, 1f, 1f));
}
29 changes: 29 additions & 0 deletions src/main/java/gregtech/api/net/PacketOpenTechTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gregtech.api.net;

import net.minecraft.entity.player.EntityPlayerMP;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import gregtech.common.misc.techtree.gui.TechTreeGuiFactory;
import io.netty.buffer.ByteBuf;

public class PacketOpenTechTree implements IMessage, IMessageHandler<PacketOpenTechTree, IMessage> {

@Override
public void fromBytes(ByteBuf buf) {
// No need to do anything here
}

@Override
public void toBytes(ByteBuf buf) {
// No need to do anything here
}

@Override
public IMessage onMessage(PacketOpenTechTree message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
TechTreeGuiFactory.open(player, player.serverPosX, player.serverPosY, player.serverPosZ);
return null;
}
}
19 changes: 19 additions & 0 deletions src/main/java/gregtech/client/GT_KeyBindings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gregtech.client;

import static gregtech.api.enums.Mods.GregTech;

import net.minecraft.client.settings.KeyBinding;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.client.registry.ClientRegistry;

public class GT_KeyBindings {

public static KeyBinding openTechTree;

public static void registerBindings() {
openTechTree = new KeyBinding("Open Tech Tree", Keyboard.KEY_GRAVE, GregTech.name());
ClientRegistry.registerKeyBinding(openTechTree);
}
}
45 changes: 45 additions & 0 deletions src/main/java/gregtech/common/items/ItemTechAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package gregtech.common.items;

import static gregtech.api.enums.Mods.GregTech;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;

import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.util.GT_LanguageManager;
import gregtech.common.misc.techtree.gui.TechTreeGui;
import gregtech.common.misc.techtree.gui.TechTreeGuiData;
import gregtech.common.misc.techtree.gui.TechTreeGuiFactory;

public class ItemTechAccessor extends Item implements IGuiHolder<TechTreeGuiData> {

public ItemTechAccessor() {
super();
setUnlocalizedName("gt.techaccessor");
setMaxStackSize(1);
GameRegistry.registerItem(this, this.getUnlocalizedName(), GregTech.ID);
GT_LanguageManager.addStringLocalization("item.gt.techaccessor.name", "Tech Tree Accessor");
}

@Override
public ModularScreen createScreen(TechTreeGuiData data, ModularPanel mainPanel) {
return new ModularScreen(mainPanel);
}

public ModularPanel buildUI(TechTreeGuiData data, PanelSyncManager syncManager) {
return TechTreeGui.buildUI(data, syncManager);
}

@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer player) {
TechTreeGuiFactory.open(player, player.serverPosX, player.serverPosY, player.serverPosZ);
return itemStackIn;
}
}
16 changes: 16 additions & 0 deletions src/main/java/gregtech/common/misc/techtree/TechList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gregtech.common.misc.techtree;

import gregtech.common.misc.techtree.base.Technology;

public class TechList {

// If a technology has no requirements, this will be used as a prerequisite instead.
public static Technology HiddenRoot;
public static Technology TechA;
public static Technology TechB;
public static Technology TechC;
public static Technology TechD;
public static Technology TechE;
public static Technology TechF;
public static Technology TechG;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gregtech.common.misc.techtree;

import java.util.Collection;
import java.util.HashMap;

import gregtech.common.misc.techtree.interfaces.ITechnology;

public class TechnologyRegistry {

private static final HashMap<String, ITechnology> registeredTechs = new HashMap<>();

/**
* Check if a technology exists
*
* @param name The name of the technology to look up
* @return True if the technology exists and is registered, false otherwise
*/
public static boolean technologyExists(String name) {
return registeredTechs.containsKey(name);
}

/**
* Register a new technology into the system
*
* @param tech The technology to register.
* @throws RuntimeException if there already is a technology with the same internal name
*/
public static void register(ITechnology tech) {
if (technologyExists(tech.getInternalName())) {
throw new RuntimeException("Technology with internal name" + tech.getInternalName() + " already exists.");
}
registeredTechs.put(tech.getInternalName(), tech);
}

/**
* @return A list of all registered technologies
*/
public static Collection<ITechnology> getTechnologies() {
return registeredTechs.values();
}

public static ITechnology findTechnology(String internalName) {
return registeredTechs.get(internalName);
}

public static int numTechnologies() {
return registeredTechs.size();
}
}
114 changes: 114 additions & 0 deletions src/main/java/gregtech/common/misc/techtree/base/Technology.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package gregtech.common.misc.techtree.base;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;

import net.minecraft.util.StatCollector;

import gregtech.common.misc.techtree.interfaces.IPrerequisite;
import gregtech.common.misc.techtree.interfaces.ITechnology;

/**
* @author NotAPenguin0
*/
public class Technology implements ITechnology, IPrerequisite {

/**
* Internal name of the technology.
*/
private final String internalName;
/**
* Unlocalized name of the technology
*/
private final String unlocalizedName;

/**
* Prerequisite technologies required to research this technology.
*/
private final IPrerequisite[] prerequisites;

/**
* Depth of the technology
*/
private int depth = 0;

/**
* Technologies of which this technology is a prerequisite
*/
private final ArrayList<ITechnology> children = new ArrayList<>();

/**
* Create a new researchable technology
*
* @param name The internal name of the technology
* @param unlocalizedName The unlocalized name of the technology
* @param prerequisites The technologies required to unlock this technology. This cannot be changed afterwards.
*/
public Technology(String name, String unlocalizedName, IPrerequisite[] prerequisites) {
this.internalName = name;
this.unlocalizedName = unlocalizedName;
this.prerequisites = prerequisites;

// Calculate depth based on depth of prerequisite technologies.
// The depth into the tree is one more than the depth of the deepest prerequisite technology.
// Note that we can do this, because you cannot add prerequisite technologies after construction,
// so the depth of all prerequisite techs is final once we reach this constructor.
for (IPrerequisite prereq : prerequisites) {
// If this prerequisite is a technology, modify depth and children for it.
ITechnology tech = prereq.getTechnology();
if (tech != null) {
depth = Math.max(depth, tech.getDepth() + 1);
// Also store this technology as a child tech of each prerequisite, since this makes graph traversal
// a lot easier
tech.addChildTechnology(this);
}
}
}

@Override
public void addChildTechnology(ITechnology tech) {
this.children.add(tech);
}

@Override
public String getInternalName() {
return internalName;
}

@Override
public String getUnlocalizedName() {
return unlocalizedName;
}

@Override
public String getLocalizedName() {
return StatCollector.translateToLocal(getUnlocalizedName());
}

@Override
public int getDepth() {
return depth;
}

@Override
public Collection<IPrerequisite> getPrerequisites() {
return Arrays.asList(this.prerequisites);
}

@Override
public Collection<ITechnology> getChildren() {
return children;
}

@Override
public boolean isSatisfied(UUID playerUuid) {
return false;
}

@Override
public ITechnology getTechnology() {
return this;
}
}
Loading
Loading