Skip to content

Commit 7ae67f4

Browse files
Merge remote-tracking branch 'origin/1.12.2-forge' into 1.14.4-forge
2 parents a4d7149 + 9d261e7 commit 7ae67f4

8 files changed

Lines changed: 351 additions & 171 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ In the past UMC has been packaged directly with ImmersiveRailroading as it is wa
2424
| [1.19.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.19.4-fabric) | ![Universal Mod Core 1.19.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.19.4-fabric) |
2525
| [1.20.1-forge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.1-forge) | ![Universal Mod Core 1.20.1-forge](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.1-forge) |
2626
| [1.20.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.1-fabric) | ![Universal Mod Core 1.20.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.1-fabric) |
27-
| [1.20.4-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-neoforge) | ![Universal Mod Core 1.20.4-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.4-neoforge) |
28-
| [1.20.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-fabric) | ![Universal Mod Core 1.20.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.4-fabric) |
27+
| [1.20.4-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-neoforge) | EOL |
28+
| [1.20.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-fabric) | EOL |
2929
| [1.21.1-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.21.1-neoforge) | ![Universal Mod Core 1.21.1-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.21.1-neoforge) |
3030
| [1.21.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.21.1-fabric) | ![Universal Mod Core 1.21.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.21.1-fabric) |
3131

src/main/java/cam72cam/mod/ModCore.java

Lines changed: 19 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package cam72cam.mod;
22

33
import java.io.*;
4-
import java.nio.charset.StandardCharsets;
54
import java.nio.file.Path;
65
import java.nio.file.Paths;
76
import java.util.*;
87

98
import net.minecraft.client.resources.ClientResourcePackInfo;
109
import net.minecraft.resources.*;
11-
import net.minecraft.resources.data.IMetadataSectionSerializer;
12-
import net.minecraft.util.ResourceLocation;
1310
import net.minecraft.util.text.StringTextComponent;
14-
import net.minecraftforge.fml.ModList;
1511
import org.apache.logging.log4j.LogManager;
1612
import org.apache.logging.log4j.Logger;
1713

@@ -23,6 +19,7 @@
2319
import cam72cam.mod.net.Packet;
2420
import cam72cam.mod.net.PacketDirection;
2521
import cam72cam.mod.render.Light;
22+
import cam72cam.mod.resource.BuiltinPack;
2623
import cam72cam.mod.resource.Identifier;
2724
import cam72cam.mod.text.Command;
2825
import cam72cam.mod.util.MinecraftFiles;
@@ -45,13 +42,10 @@
4542
import org.apache.commons.lang3.SystemUtils;
4643
import org.lwjgl.opengl.GL11;
4744

48-
import javax.annotation.Nullable;
4945
import java.io.File;
5046
import java.io.IOException;
5147
import java.util.ArrayList;
5248
import java.util.List;
53-
import java.util.function.Predicate;
54-
import java.util.stream.Collectors;
5549

5650
/** UMC Mod, do not touch... */
5751
@net.minecraftforge.fml.common.Mod(ModCore.MODID)
@@ -163,6 +157,10 @@ public static void catching(Throwable ex) {
163157
}
164158
}
165159

160+
public List<Mod> getLoadedMods() {
161+
return mods;
162+
}
163+
166164
private static Proxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);
167165
/** Hooked into forge's proxy system and fires off corresponding events */
168166
public static class Proxy {
@@ -209,39 +207,24 @@ public void setup() {
209207
}
210208
Config.getMaxTextureSize(); //populate
211209

212-
List<ResourcePack> packs = new ArrayList<>();
213-
packs.add(new TranslationResourcePack());
214-
215-
for (Mod m : mods) {
216-
ResourcePack modPack = createPack(ModList.get().getModFileById(m.modID()).getFile().getFilePath().toFile());
217-
packs.add(modPack);
218-
String configDir = FMLPaths.CONFIGDIR.get().toString();
219-
new File(configDir).mkdirs();
220-
221-
File folder = new File(configDir + File.separator + m.modID());
222-
if (folder.exists()) {
223-
if (folder.isDirectory()) {
224-
File[] files = folder.listFiles((dir, name) -> name.endsWith(".zip"));
225-
for (File file : files) {
226-
packs.add(createPack(file));
227-
}
228-
229-
File[] folders = folder.listFiles((dir, name) -> dir.isDirectory());
230-
for (File dir : folders) {
231-
packs.add(createPack(dir));
232-
}
233-
}
234-
} else {
235-
folder.mkdirs();
236-
}
237-
packs.add(modPack);
210+
List<IResourcePack> packs = new ArrayList<>();
211+
212+
for (Mod mod : instance.mods) {
213+
BuiltinPack.loadModResource(mod);
238214
}
239215

240-
// Force first and last (and inject mod time) BUG: sounds can still be overridden by resource packs
216+
IResourcePack modPack = BuiltinPack.attach();
217+
// Ensure people will get our result first via getResourceStream() and getLastResourceStream()
218+
// (Also injects last modified time access)
219+
// BUG: sounds can still be overridden by resource packs
220+
packs.add(1, modPack);
221+
packs.add(modPack);
222+
BuiltinPack.onConstruct(packs);
223+
241224
Minecraft.getInstance().getResourcePackList().addPackFinder(new IPackFinder() {
242225
@Override
243226
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> nameToPackMap, ResourcePackInfo.IFactory<T> packInfoFactory) {
244-
for (ResourcePack pack : packs) {
227+
for (IResourcePack pack : packs) {
245228
//noinspection unchecked
246229
nameToPackMap.put(pack.getName(), (T) new ClientResourcePackInfo(pack.getName(),
247230
true,
@@ -264,108 +247,6 @@ public void event(ModEvent event, Mod m) {
264247
m.clientEvent(event);
265248
}
266249

267-
private static class TranslationResourcePack extends ResourcePack {
268-
public TranslationResourcePack() {
269-
super(null);
270-
}
271-
272-
private ResourceLocation toLang(String path) {
273-
// assets/mod/location
274-
//return String.format("%s/%s/%s", type.getDirectoryName(), location.getNamespace(), location.getPath());
275-
String[] parts = path.split("/");
276-
String type = parts[0];
277-
String namespace = parts[1];
278-
String prefix = String.format("%s/%s/", type, namespace);
279-
path = path.replace(prefix, "").replace(".json", ".lang");
280-
String lang = path.split("_")[1].replace(".lang", "");
281-
path = path.replace("_" + lang, "_" + lang.toUpperCase(Locale.ROOT));
282-
return new ResourceLocation(namespace, path.toLowerCase(Locale.ROOT)) {
283-
@Override
284-
public String getPath() {
285-
// Very evil...
286-
return path;
287-
}
288-
};
289-
}
290-
291-
@Override
292-
public boolean resourceExists(String resourcePath) {
293-
if (resourcePath.contains("/lang/") && resourcePath.endsWith(".json")) {
294-
ResourceLocation lang = toLang(resourcePath);
295-
return Minecraft.getInstance().getResourceManager().hasResource(lang);
296-
}
297-
return false;
298-
}
299-
300-
@Override
301-
public InputStream getInputStream(String resourcePath) throws IOException {
302-
if (resourcePath.contains("/lang/") && resourcePath.endsWith(".json")) {
303-
// Magical Translations!
304-
ResourceLocation lang = toLang(resourcePath);
305-
if (Minecraft.getInstance().getResourceManager().hasResource(lang)) {
306-
Map<String, String> translationMap = new HashMap<>();
307-
for (IResource resource : Minecraft.getInstance().getResourceManager().getAllResources(lang)) {
308-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) {
309-
String line;
310-
while ((line = reader.readLine()) != null) {
311-
//Remove comment
312-
line = line.trim();
313-
int comment = line.indexOf("#");
314-
if (line.isEmpty() || comment == 0) {
315-
continue;
316-
}
317-
318-
String[] splits = line.split("=", 2);
319-
if (splits.length == 2) {
320-
translationMap.put(splits[0].trim(), splits[1].trim());
321-
}
322-
}
323-
}
324-
}
325-
326-
Set<String> translations = new HashSet<>();
327-
translationMap.forEach((key, value) -> {
328-
if (!key.isEmpty()) {
329-
translations.add(String.format("\"%s\": \"%s\"", key, value));
330-
translations.add(String.format("\"%s\": \"%s\"", key.replace(":", "."), value));
331-
translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", ""), value));
332-
translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", "").replace(":", "."), value));
333-
}
334-
});
335-
String output = "{" + String.join(",", translations) + "}";
336-
return new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8));
337-
}
338-
}
339-
return null;
340-
}
341-
342-
@Override
343-
public Collection<ResourceLocation> getAllResourceLocations(ResourcePackType type, String pathIn, int maxDepth, Predicate<String> filter) {
344-
return Collections.emptyList();
345-
}
346-
347-
@Override
348-
public Set<String> getResourceNamespaces(ResourcePackType type) {
349-
return mods.stream().map(Mod::modID).collect(Collectors.toSet());
350-
}
351-
352-
@Override
353-
public void close() throws IOException {
354-
355-
}
356-
357-
@Override
358-
public String getName() {
359-
return "Translation Hackery";
360-
}
361-
362-
@Nullable
363-
@Override
364-
public <T> T getMetadata(IMetadataSectionSerializer<T> p_195760_1_) throws IOException {
365-
return getResourceMetadata(p_195760_1_, new ByteArrayInputStream("{}".getBytes()));
366-
}
367-
}
368-
369250
private static class UMCFolderPack extends FolderPack {
370251
public UMCFolderPack(File folder) {
371252
super(folder);
@@ -458,7 +339,7 @@ public void clientEvent(ModEvent event) {
458339
// Instance can be null during data gen
459340
if (Minecraft.getInstance() != null) {
460341
((IReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener((stage, resourceManager, preparationsProfiler, reloadProfiler, backgroundExecutor, gameExecutor) ->
461-
stage.markCompleteAwaitingOthers(Unit.INSTANCE).thenRun(ClientEvents::fireReload));
342+
stage.markCompleteAwaitingOthers(Unit.INSTANCE).thenRun(ClientEvents::fireReload).thenRun(BuiltinPack::reload));
462343
Light.register();
463344
}
464345
break;

src/main/java/cam72cam/mod/gui/screen/ScreenBuilder.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
public class ScreenBuilder extends Screen implements IScreenBuilder {
2121
private final IScreen screen;
2222
private final Map<Widget, Button> buttonMap = new HashMap<>();
23-
private final Map<TextFieldWidget, TextField> textFieldMap = new HashMap<>();
23+
private final List<TextField> textFields = new ArrayList<>();
24+
private TextField active = null;
2425
private final Supplier<Boolean> valid;
2526

2627
public ScreenBuilder(IScreen screen, Supplier<Boolean> valid) {
@@ -63,7 +64,7 @@ public void addButton(Button btn) {
6364
@Override
6465
public void addTextField(TextField textField) {
6566
super.addButton(textField.internal());
66-
this.textFieldMap.put(textField.internal(), textField);
67+
this.textFields.add(textField);
6768
}
6869

6970
@Override
@@ -101,7 +102,7 @@ public void show() {
101102
@Override
102103
public void init() {
103104
buttonMap.clear();
104-
textFieldMap.clear();
105+
textFields.clear();
105106
screen.init(this);
106107
}
107108

@@ -135,20 +136,13 @@ public boolean keyPressed(int typedChar, int keyCode, int mods) {
135136
return true;
136137
}
137138

138-
if (this.textFieldMap.keySet().stream()
139-
.noneMatch(txt -> txt.keyPressed(typedChar, keyCode, mods))) {
140-
screen.onKeyType(this, Keyboard.KeyCode.of(typedChar));
139+
if (this.active != null && !active.internal.keyPressed(typedChar, keyCode, mods)) {
140+
screen.onKeyType(this, Keyboard.KeyCode.of(keyCode));
141141
}
142142

143143
return true;
144144
}
145145

146-
@Override
147-
public boolean charTyped(char p_charTyped_1_, int p_charTyped_2_) {
148-
return this.textFieldMap.keySet().stream()
149-
.anyMatch(txt -> txt.charTyped(p_charTyped_1_, p_charTyped_2_));
150-
}
151-
152146
@Override
153147
public boolean mouseClicked(double x, double y, int button) {
154148
Player.Hand hand = button == 0 ? Player.Hand.PRIMARY : Player.Hand.SECONDARY;
@@ -157,15 +151,16 @@ public boolean mouseClicked(double x, double y, int button) {
157151
return true;
158152
}
159153

160-
if (this.textFieldMap.keySet().stream().noneMatch(txt -> {
161-
if (txt.mouseClicked(x, y, button)) {
162-
txt.setFocused2(true);
154+
for (TextField field : textFields) {
155+
if (field.isVisible() && field.internal.mouseClicked(x, y, hand == Player.Hand.PRIMARY ? 0 : 1)) {
156+
active = field;
157+
field.setFocused(true);
163158
return true;
164159
}
165-
return false;
166-
})) {
167-
screen.onMouseClick((int) x, (int) y, hand);
160+
field.setFocused(false);
168161
}
162+
163+
screen.onMouseClick((int) x, (int) y, hand);
169164
return true;
170165
}
171166

src/main/java/cam72cam/mod/gui/screen/TextField.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import java.util.function.Predicate;
77

88
/** Base text field */
9-
public class TextField implements IWidget{
10-
protected final TextFieldWidget textfield;
9+
public class TextField implements IWidget {
10+
protected final TextFieldWidget internal;
1111
/** Standard constructor */
1212
public TextField(IScreenBuilder builder, int x, int y, int width, int height) {
1313
this(builder,
@@ -16,28 +16,29 @@ public TextField(IScreenBuilder builder, int x, int y, int width, int height) {
1616

1717
/** Internal, can be overridden to support custom GuiTextFields */
1818
protected TextField(IScreenBuilder builder, TextFieldWidget internal) {
19-
this.textfield = internal;
19+
this.internal = internal;
20+
this.internal.setMaxStringLength(256);
2021
builder.addTextField(this);
2122
}
2223

2324
TextFieldWidget internal() {
24-
return textfield;
25+
return internal;
2526
}
2627

2728
@Override
2829
public void setText(String s) {
29-
textfield.setText(s);
30+
internal.setText(s);
3031
}
3132

3233
@Override
3334
public String getText() {
34-
return textfield.getText();
35+
return internal.getText();
3536
}
3637

3738
@Override
3839
public void setVisible(boolean visible) {
39-
textfield.setVisible(visible);
40-
textfield.setEnabled(visible);
40+
internal.setVisible(visible);
41+
internal.setEnabled(visible);
4142
}
4243

4344
@Deprecated
@@ -47,17 +48,17 @@ public void setVisible(Boolean visible) {
4748

4849
@Override
4950
public boolean isVisible() {
50-
return textfield.getVisible();
51+
return internal.getVisible();
5152
}
5253

5354
@Override
5455
public void setEnabled(boolean enabled) {
55-
textfield.setEnabled(enabled);
56+
internal.setEnabled(enabled);
5657
}
5758

5859
@Override
5960
public boolean isEnabled() {
60-
return textfield.active;
61+
return internal.active;
6162
}
6263

6364
/** Validator that can block a string from being entered */

src/main/java/cam72cam/mod/render/EntityRenderer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ public static void register(Class<? extends Entity> type, IEntityRender render)
5555

5656
/**
5757
* Sooo this is a fun one...
58-
*
58+
* <p>
5959
* MC culls out entities in chunks that are not in view, which breaks when entities span chunk boundaries
60+
* <p>
6061
* For 1-2 block entities, this is barely noticeable. For large entities it's a problem.
62+
* <p>
6163
* We try to detect entities in this edge case and render them here to prevent the issue.
6264
*/
6365
private static void renderLargeEntities(RenderState state, float partialTicks) {
@@ -85,6 +87,7 @@ private static void renderLargeEntities(RenderState state, float partialTicks) {
8587
AxisAlignedBB chunk = new AxisAlignedBB(min.internal(), max.internal());
8688
if (!camera.isBoundingBoxInFrustum(chunk) && camera.isBoundingBoxInFrustum(entity.internal.getRenderBoundingBox())) {
8789
Minecraft.getInstance().getRenderManager().renderEntityStatic(entity.internal, partialTicks, true);
90+
Minecraft.getInstance().getRenderManager().renderMultipass(entity.internal, partialTicks);
8891
}
8992
}
9093

0 commit comments

Comments
 (0)