Skip to content

Commit

Permalink
Fix #84
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Nov 23, 2023
1 parent 687da26 commit d2a99a6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 78 deletions.
32 changes: 16 additions & 16 deletions common/src/main/java/com/ultreon/devices/BuiltinApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

public class BuiltinApps {
public static void registerBuiltinApps() {
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "diagnostics"), () -> DiagnosticsApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "settings"), () -> SettingsApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "file_browser"), () -> FileBrowserApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "gitweb"), () -> GitWebApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "note_stash"), () -> NoteStashApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "pixel_painter"), () -> PixelPainterApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "ender_mail"), () -> EmailApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "app_store"), () -> AppStore::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "diagnostics"), () -> DiagnosticsApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "settings"), () -> SettingsApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "file_browser"), () -> FileBrowserApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "gitweb"), () -> GitWebApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "note_stash"), () -> NoteStashApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "pixel_painter"), () -> PixelPainterApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "ender_mail"), () -> EmailApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "app_store"), () -> AppStore::new, true);

if (Platform.isDevelopmentEnvironment()) {
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "bank"), () -> BankApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "boat_racers"), () -> BoatRacersApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "mine_bay"), () -> MineBayApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "snake"), () -> SnakeApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "themes"), () -> ThemesApp::new, false);
}
// if (Platform.isDevelopmentEnvironment()) {
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "bank"), () -> BankApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "boat_racers"), () -> BoatRacersApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "mine_bay"), () -> MineBayApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "snake"), () -> SnakeApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "themes"), () -> ThemesApp::new, false);
// }

ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "vulnerability"), () -> VulnerabilityApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "vulnerability"), () -> VulnerabilityApp::new, true);
}
}
68 changes: 37 additions & 31 deletions common/src/main/java/com/ultreon/devices/Devices.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import dev.architectury.registry.registries.RegistrarManager;
import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.MappedRegistry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
Expand Down Expand Up @@ -139,14 +141,13 @@ public void init() {
EnvExecutor.runInEnv(Env.CLIENT, () -> () -> {
ClientAppDebug.register();
ClientModEvents.clientSetup(); //todo
Devices.setupSiteRegistrations();
Devices.checkForVulnerabilities();
});

EnvExecutor.runInEnv(Env.CLIENT, () -> Devices::setupSiteRegistrations);
EnvExecutor.runInEnv(Env.CLIENT, () -> Devices::checkForVulnerabilities);

setupEvents();

EnvExecutor.runInEnv(Env.CLIENT, () -> Devices::setupClientEvents); //todo
EnvExecutor.runInEnv(Env.CLIENT, () -> () -> setupClientEvents()); //todo
if (!ArchitecturyTarget.getCurrentTarget().equals("forge")) {
loadComplete();
}
Expand Down Expand Up @@ -195,12 +196,12 @@ private void registerApplications() {
TaskManager.registerTask(TaskGetDevices::new);

// Bank
TaskManager.registerTask(TaskDeposit::new);
TaskManager.registerTask(TaskWithdraw::new);
TaskManager.registerTask(TaskGetBalance::new);
TaskManager.registerTask(TaskPay::new);
TaskManager.registerTask(TaskAdd::new);
TaskManager.registerTask(TaskRemove::new);
// TaskManager.registerTask(TaskDeposit::new);
// TaskManager.registerTask(TaskWithdraw::new);
// TaskManager.registerTask(TaskGetBalance::new);
// TaskManager.registerTask(TaskPay::new);
// TaskManager.registerTask(TaskAdd::new);
// TaskManager.registerTask(TaskRemove::new);

// File browser
TaskManager.registerTask(TaskSendAction::new);
Expand All @@ -213,35 +214,36 @@ private void registerApplications() {
TaskManager.registerTask(TaskInstallApp::new);

// Ender Mail
TaskManager.registerTask(TaskUpdateInbox::new);
TaskManager.registerTask(TaskSendEmail::new);
TaskManager.registerTask(TaskCheckEmailAccount::new);
TaskManager.registerTask(TaskRegisterEmailAccount::new);
TaskManager.registerTask(TaskDeleteEmail::new);
TaskManager.registerTask(TaskViewEmail::new);
// TaskManager.registerTask(TaskUpdateInbox::new);
// TaskManager.registerTask(TaskSendEmail::new);
// TaskManager.registerTask(TaskCheckEmailAccount::new);
// TaskManager.registerTask(TaskRegisterEmailAccount::new);
// TaskManager.registerTask(TaskDeleteEmail::new);
// TaskManager.registerTask(TaskViewEmail::new);

// Auction
TaskManager.registerTask(TaskAddAuction::new);
TaskManager.registerTask(TaskGetAuctions::new);
TaskManager.registerTask(TaskBuyItem::new);

if (DEVELOPER_MODE) {
// Applications (Developers)
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "example"), () -> ExampleApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "icons"), () -> IconsApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "text_area"), () -> TextAreaApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "test"), () -> TestApp::new, false);

TaskManager.registerTask(TaskNotificationTest::new);
}

EnvExecutor.runInEnv(Env.CLIENT, () -> () -> PrintingManager.registerPrint(new ResourceLocation(Reference.MOD_ID, "picture"), PixelPainterApp.PicturePrint.class));
// TaskManager.registerTask(TaskAddAuction::new);
// TaskManager.registerTask(TaskGetAuctions::new);
// TaskManager.registerTask(TaskBuyItem::new);

// if (DEVELOPER_MODE) {
// // Applications (Developers)
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "example"), () -> ExampleApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "icons"), () -> IconsApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "text_area"), () -> TextAreaApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "test"), () -> TestApp::new, false);
//
// TaskManager.registerTask(TaskNotificationTest::new);
// }
//
// EnvExecutor.runInEnv(Env.CLIENT, () -> () -> PrintingManager.registerPrint(new ResourceLocation(Reference.MOD_ID, "picture"), PixelPainterApp.PicturePrint.class));
}

public abstract int getBurnTime(ItemStack stack, RecipeType<?> type);

protected abstract void registerApplicationEvent();

@Environment(EnvType.CLIENT)
protected abstract List<Application> getApplications();

public static void setAllowedApps(List<AppInfo> allowedApps) {
Expand Down Expand Up @@ -299,6 +301,7 @@ public Application registerApplication(ResourceLocation identifier, ApplicationS
}

@NotNull
@Environment(EnvType.CLIENT)
private static AppInfo generateAppInfo(ResourceLocation identifier, Class<? extends Application> clazz) {
LOGGER.debug("Generating app info for " + identifier.toString());

Expand All @@ -307,10 +310,13 @@ private static AppInfo generateAppInfo(ResourceLocation identifier, Class<? exte
return info;
}

@Environment(EnvType.CLIENT)
protected abstract Map<String, IPrint.Renderer> getRegisteredRenders();

@Environment(EnvType.CLIENT)
protected abstract void setRegisteredRenders(Map<String, IPrint.Renderer> map);

@Environment(EnvType.CLIENT)
public boolean registerPrint(ResourceLocation identifier, Class<? extends IPrint> classPrint) {
LOGGER.debug("Registering print: " + identifier.toString());

Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }

modApi "curse.maven:emojiful-284324:3963433"
// modApi "curse.maven:emojiful-284324:3963433"

// forgeRuntimeLibrary "com.ultreon:ultranlang:0.1.0+6"
forgeRuntimeLibrary "com.jab125:apoint:1.0.0"
Expand Down
65 changes: 35 additions & 30 deletions forge/src/main/java/com/ultreon/devices/forge/DevicesForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import dev.architectury.platform.forge.EventBuses;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.MavenVersionStringHelper;
import net.minecraftforge.data.loading.DatagenModLoader;
Expand All @@ -36,8 +38,37 @@

// The value here should match an entry in the META-INF/mods.toml file
@Mod(Reference.MOD_ID)
public final class DevicesForge extends Devices {
public final class DevicesForge {
public static final Logger LOGGER = LogUtils.getLogger();
private final Devices instance = new Devices() {
@Override
protected void registerApplicationEvent() {
DevicesForge.this.modEventBus.post(new ForgeApplicationRegistration());
}

@Override
public int getBurnTime(ItemStack stack, RecipeType<?> type) {
return stack.getBurnTime(type);
}

@Override
protected List<Application> getApplications() {
return ObfuscationReflectionHelper.getPrivateValue(Laptop.class, null, "APPLICATIONS");
}

@Override
@OnlyIn(Dist.CLIENT)
@SuppressWarnings("DataFlowIssue")
protected void setRegisteredRenders(Map<String, IPrint.Renderer> map) {
ObfuscationReflectionHelper.setPrivateValue(PrintingManager.class, null, map, "registeredRenders");
}

@Override
@OnlyIn(Dist.CLIENT)
protected Map<String, IPrint.Renderer> getRegisteredRenders() {
return ObfuscationReflectionHelper.getPrivateValue(PrintingManager.class, null, "registeredRenders");
}
};

public IEventBus modEventBus;

Expand Down Expand Up @@ -80,41 +111,15 @@ public DevicesForge() throws LaunchException {
forgeEventBus.register(this);
}

@Override
public int getBurnTime(ItemStack stack, RecipeType<?> type) {
return stack.getBurnTime(type);
}

private void fmlCommonSetup(FMLCommonSetupEvent t) {
this.init();
this.instance.init();
}

private void fmlLoadComplete(FMLLoadCompleteEvent t) {
this.loadComplete();
this.instance.loadComplete();
}

private void fmlServerSetup(FMLDedicatedServerSetupEvent t) {
this.serverSetup();
}

@Override
protected void registerApplicationEvent() {
this.modEventBus.post(new ForgeApplicationRegistration());
}

@Override
protected List<Application> getApplications() {
return ObfuscationReflectionHelper.getPrivateValue(Laptop.class, null, "APPLICATIONS");
}

@Override
@SuppressWarnings("DataFlowIssue")
protected void setRegisteredRenders(Map<String, IPrint.Renderer> map) {
ObfuscationReflectionHelper.setPrivateValue(PrintingManager.class, null, map, "registeredRenders");
}

@Override
protected Map<String, IPrint.Renderer> getRegisteredRenders() {
return ObfuscationReflectionHelper.getPrivateValue(PrintingManager.class, null, "registeredRenders");
this.instance.serverSetup();
}
}

0 comments on commit d2a99a6

Please sign in to comment.