Skip to content

Commit 7ce24c5

Browse files
committed
Starting bringing SpectrumCommon over
1 parent 2879bf7 commit 7ce24c5

File tree

2 files changed

+74
-50
lines changed

2 files changed

+74
-50
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package de.dafuqs.spectrum;
2+
3+
import net.minecraft.resources.*;
4+
import net.minecraft.server.*;
5+
import net.minecraft.tags.*;
6+
import net.minecraft.world.item.*;
7+
import net.minecraft.world.item.crafting.*;
8+
import net.minecraft.world.level.*;
9+
import net.neoforged.bus.api.*;
10+
import net.neoforged.fml.common.*;
11+
import org.jetbrains.annotations.*;
12+
import org.slf4j.*;
13+
14+
import java.util.*;
15+
16+
@Mod(SpectrumCommon.MOD_ID)
17+
public class SpectrumCommon {
18+
19+
public static final String MOD_ID = "spectrum";
20+
21+
public static final Logger LOGGER = LoggerFactory.getLogger("Spectrum");
22+
public static final Map<ResourceLocation, TagKey<Item>> CACHED_ITEM_TAG_MAP = new HashMap<>();
23+
// TODO PORT
24+
// public static SpectrumConfig CONFIG;
25+
26+
public static void logInfo(String message) {
27+
LOGGER.info("[Spectrum] {}", message);
28+
}
29+
30+
public static void logWarning(String message) {
31+
LOGGER.warn("[Spectrum] {}", message);
32+
}
33+
34+
public static void logError(String message) {
35+
LOGGER.error("[Spectrum] {}", message);
36+
}
37+
38+
public static ResourceLocation locate(String name) {
39+
return ResourceLocation.fromNamespaceAndPath(MOD_ID, name);
40+
}
41+
42+
/**
43+
* This is the Spectrum analogue of Identifier.of, but instead of defaulting to the namespace 'minecraft', it defaults to 'spectrum'.
44+
*
45+
* @param id The stringified identifier to parse
46+
* @return The parsed identifier
47+
*/
48+
public static ResourceLocation ofSpectrumDefaulted(String id) {
49+
int i = id.indexOf(':');
50+
String path = id.substring(i + 1);
51+
String namespace = i > 0 ? id.substring(0, i) : SpectrumCommon.MOD_ID;
52+
return ResourceLocation.fromNamespaceAndPath(namespace, path);
53+
}
54+
55+
// Will be null when playing on a dedicated server!
56+
@Nullable
57+
public static MinecraftServer minecraftServer;
58+
59+
public SpectrumCommon(IEventBus modBus) {
60+
logInfo("Starting Common Startup");
61+
62+
}
63+
64+
/**
65+
* When initializing a block entity, world can still be null
66+
* Therefore we use the RecipeManager reference from MinecraftServer
67+
* This in turn does not work on clients connected to dedicated servers, though
68+
* since SpectrumCommon.minecraftServer is null
69+
*/
70+
public static Optional<RecipeManager> getRecipeManager(@Nullable Level world) {
71+
return world == null ? minecraftServer == null ? Optional.empty() : Optional.of(minecraftServer.getRecipeManager()) : Optional.of(world.getRecipeManager());
72+
}
73+
74+
}

src/main_disabled/java/de/dafuqs/spectrum/SpectrumCommon.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,6 @@
4242

4343
public class SpectrumCommon implements ModInitializer {
4444

45-
public static final String MOD_ID = "spectrum";
46-
47-
public static final Logger LOGGER = LoggerFactory.getLogger("Spectrum");
48-
public static final Map<ResourceLocation, TagKey<Item>> CACHED_ITEM_TAG_MAP = new HashMap<>();
49-
public static SpectrumConfig CONFIG;
50-
51-
public static void logInfo(String message) {
52-
LOGGER.info("[Spectrum] {}", message);
53-
}
54-
55-
public static void logWarning(String message) {
56-
LOGGER.warn("[Spectrum] {}", message);
57-
}
58-
59-
public static void logError(String message) {
60-
LOGGER.error("[Spectrum] {}", message);
61-
}
62-
63-
public static ResourceLocation locate(String name) {
64-
return ResourceLocation.fromNamespaceAndPath(MOD_ID, name);
65-
}
66-
67-
/**
68-
* This is the Spectrum analogue of Identifier.of, but instead of defaulting to the namespace 'minecraft', it defaults to 'spectrum'.
69-
*
70-
* @param id The stringified identifier to parse
71-
* @return The parsed identifier
72-
*/
73-
public static ResourceLocation ofSpectrumDefaulted(String id) {
74-
int i = id.indexOf(':');
75-
String path = id.substring(i + 1);
76-
String namespace = i > 0 ? id.substring(0, i) : SpectrumCommon.MOD_ID;
77-
return ResourceLocation.fromNamespaceAndPath(namespace, path);
78-
}
79-
80-
// Will be null when playing on a dedicated server!
81-
@Nullable
82-
public static MinecraftServer minecraftServer;
83-
8445
// Miscellaneous registrars
8546
public static final DeferredRegistrar FUEL_REGISTRAR = new DeferredRegistrar();
8647

@@ -94,7 +55,6 @@ public static ResourceLocation ofSpectrumDefaulted(String id) {
9455

9556
@Override
9657
public void onInitialize() {
97-
logInfo("Starting Common Startup");
9858

9959
// Register internals
10060
SpectrumRegistries.register();
@@ -276,14 +236,4 @@ public void onInitialize() {
276236
logInfo("Common startup completed!");
277237
}
278238

279-
/**
280-
* When initializing a block entity, world can still be null
281-
* Therefore we use the RecipeManager reference from MinecraftServer
282-
* This in turn does not work on clients connected to dedicated servers, though
283-
* since SpectrumCommon.minecraftServer is null
284-
*/
285-
public static Optional<RecipeManager> getRecipeManager(@Nullable Level world) {
286-
return world == null ? minecraftServer == null ? Optional.empty() : Optional.of(minecraftServer.getRecipeManager()) : Optional.of(world.getRecipeManager());
287-
}
288-
289239
}

0 commit comments

Comments
 (0)