Skip to content

Commit

Permalink
Add MadParticle support
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Aug 1, 2023
1 parent 6a598b8 commit 55f9549
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import cn.zbx1425.mtrsteamloco.MainClient;
import cn.zbx1425.mtrsteamloco.render.scripting.eyecandy.EyeCandyScriptContext;
import cn.zbx1425.mtrsteamloco.render.scripting.train.TrainScriptContext;
import cn.zbx1425.mtrsteamloco.render.scripting.util.GraphicsTexture;
import cn.zbx1425.mtrsteamloco.render.scripting.util.ScriptTimingUtil;
import cn.zbx1425.mtrsteamloco.render.scripting.util.StateTracker;
import cn.zbx1425.sowcer.math.Matrices;
import cn.zbx1425.sowcer.math.Matrix4f;
import cn.zbx1425.sowcer.math.Vector3f;
import cn.zbx1425.sowcerext.model.RawMesh;
import cn.zbx1425.sowcerext.model.RawModel;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import org.mozilla.javascript.*;

Expand Down Expand Up @@ -49,6 +53,27 @@ public void load(Map<ResourceLocation, String> scripts) {
scope.put("Matrix4f", scope, new NativeJavaClass(scope, Matrix4f.class));
scope.put("Vector3f", scope, new NativeJavaClass(scope, Vector3f.class));

try {
String[] classesToLoad = {
"util.AddParticleHelper",
"particle.MadParticleOption",
"particle.SpriteFrom",
"command.inheritable.InheritableBoolean",
"particle.ParticleRenderTypes",
"particle.ChangeMode"
};
for (String classToLoad : classesToLoad) {
Class<?> classToLoadClass = Class.forName("cn.ussshenzhou.madparticle." + classToLoad);
scope.put(classToLoad.substring(classToLoad.lastIndexOf(".") + 1), scope,
new NativeJavaClass(scope, classToLoadClass));
}
scope.put("CompoundTag", scope, new NativeJavaClass(scope, CompoundTag.class));
scope.put("installedMadParticle", scope, true);
} catch (ClassNotFoundException ignored) {
Main.LOGGER.warn("MadParticle", ignored);
scope.put("installedMadParticle", scope, false);
}

ScriptResourceUtil.scriptsToExecute = new ArrayList<>(scripts.entrySet());
for (int i = 0; i < ScriptResourceUtil.scriptsToExecute.size(); i++) {
Map.Entry<ResourceLocation, String> entry = ScriptResourceUtil.scriptsToExecute.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import cn.zbx1425.mtrsteamloco.render.font.FontTextureCache;
import cn.zbx1425.mtrsteamloco.render.integration.MtrModelRegistryUtil;
import cn.zbx1425.sowcerext.util.ResourceUtil;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;

Expand All @@ -11,6 +13,7 @@
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class ScriptResourceUtil {

Expand Down Expand Up @@ -44,4 +47,9 @@ public static void includeScript(ResourceLocation identifier) throws IOException
public static Font getBuiltinFont(boolean supportCjk, boolean serif) {
return FontTextureCache.FONT_SERIF;
}

public static int getParticleTypeId(ResourceLocation identifier) {
Optional<ParticleType<?>> particleType = BuiltInRegistries.PARTICLE_TYPE.getOptional(identifier);
return particleType.map(BuiltInRegistries.PARTICLE_TYPE::getId).orElse(-1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void renderCar(int carIndex, double x, double y, double z, float yaw, flo

trainScripting.trainExtraWriting.doorLeftOpen[carIndex] = doorLeftOpen;
trainScripting.trainExtraWriting.doorRightOpen[carIndex] = doorRightOpen;
trainScripting.trainExtraWriting.lastWorldPose[carIndex] = worldPose;
if (carIndex == train.trainCars - 1) {
trainScripting.extraFinished();
trainScripting.tryCallRender(typeScripting);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.zbx1425.mtrsteamloco.render.scripting.train;

import cn.zbx1425.mtrsteamloco.Main;
import cn.zbx1425.mtrsteamloco.mixin.TrainAccessor;
import cn.zbx1425.sowcer.math.Matrix4f;
import mtr.client.ClientData;
import mtr.data.DataCache;
import mtr.data.Route;
Expand All @@ -15,6 +15,7 @@ public class TrainExtra {

public boolean[] doorLeftOpen;
public boolean[] doorRightOpen;
public Matrix4f[] lastWorldPose;

private final TrainClient train;
private StationIndexMap trainStations;
Expand All @@ -23,6 +24,7 @@ public class TrainExtra {
public TrainExtra(TrainClient train) {
doorLeftOpen = new boolean[train.trainCars];
doorRightOpen = new boolean[train.trainCars];
lastWorldPose = new Matrix4f[train.trainCars];
this.train = train;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.zbx1425.mtrsteamloco.render.scripting;
package cn.zbx1425.mtrsteamloco.render.scripting.util;

import cn.zbx1425.mtrsteamloco.Main;
import cn.zbx1425.mtrsteamloco.mixin.NativeImageAccessor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.zbx1425.mtrsteamloco.render.scripting;
package cn.zbx1425.mtrsteamloco.render.scripting.util;

import mtr.MTRClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.zbx1425.mtrsteamloco.render.scripting;
package cn.zbx1425.mtrsteamloco.render.scripting.util;

public class StateTracker {

Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ shadowJar {
exclude "*.bmp"

relocate 'de.javagl', 'vendor.cn.zbx1425.sowcerext.de.javagl'
relocate 'org.mozilla', 'vendor.cn.zbx1425.mtrsteamloco.org.mozilla'
// relocate 'org.mozilla', 'vendor.cn.zbx1425.mtrsteamloco.org.mozilla'

configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"
Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ shadowJar {
exclude "*.bmp"

relocate 'de.javagl', 'vendor.cn.zbx1425.sowcerext.de.javagl'
relocate 'org.mozilla', 'vendor.cn.zbx1425.mtrsteamloco.org.mozilla'
// relocate 'org.mozilla', 'vendor.cn.zbx1425.mtrsteamloco.org.mozilla'

configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"
Expand Down

0 comments on commit 55f9549

Please sign in to comment.