Skip to content

Commit

Permalink
升级至MC1.20.1,mod版本1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloePrime committed Mar 2, 2024
1 parent 0badfa6 commit 737c42d
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mod.chloeprime.aaaparticles.api.client.effekseer;

import Effekseer.swig.EffekseerManagerCore;
import com.mojang.math.Matrix4f;
import org.joml.Matrix4f;

import java.nio.FloatBuffer;

Expand Down Expand Up @@ -83,7 +83,7 @@ public void setCameraMatrix(float[] m) {

public void setCameraMatrix(Matrix4f m) {
var buffer = FloatBuffer.wrap(MATRIX_BUFFER.get());
m.store(buffer);
m.get(buffer);
setCameraMatrix(buffer);
}

Expand All @@ -98,7 +98,7 @@ public void setCameraMatrix(FloatBuffer buf) {

public void setProjectionMatrix(Matrix4f m) {
var buffer = FloatBuffer.wrap(MATRIX_BUFFER.get());
m.store(buffer);
m.get(buffer);
setProjectionMatrix(buffer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void addParticle(Level level, double distance, ParticleEmitterInfo
}

private static void sendToPlayer(ServerPlayer player, Level level, S2CAddParticle packet, double sqrDistance) {
if (player.getLevel() != level) {
if (player.level() != level) {
return;
}
if (packet.isPositionSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void installNativeLibrary() {

public static void addParticle(Level level, ParticleEmitterInfo info) {
var player = Minecraft.getInstance().player;
if (player != null && player.level != level) {
if (player != null && player.level() != level) {
return;
}
info.spawnInWorld(level, player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class ModClientHooks {

public static void playLightningEffek(LightningBolt bolt) {
var info = LIGHTNING_EFFEK_TEMPLATE.clone().position(bolt.position());
AAALevel.addParticle(bolt.level, true, info);
AAALevel.addParticle(bolt.level(), true, info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.IntFunction;
Expand Down Expand Up @@ -48,38 +49,37 @@ public void forEach(BiConsumer<ResourceLocation, EffectDefinition> action) {
loadedEffects.forEach(action);
}

/**
* @param name the minecraft asset path of .efkefc files.
* @return the loaded effect.
*/
private EffekseerEffect loadEffect(ResourceManager manager, ResourceLocation name) {
String modid = name.getNamespace();
String path = "effeks/" + name.getPath() + ".efkefc";
ResourceLocation assetLocation = new ResourceLocation(modid, path);

try (Resource efkefc = manager.getResource(assetLocation)) {
private Optional<EffekseerEffect> loadEffect(ResourceManager manager, ResourceLocation name, Resource efkefc) {
try (var input = efkefc.open()) {
EffekseerEffect effect = new EffekseerEffect();
boolean success = effect.load(efkefc.getInputStream(), 1);
boolean success = effect.load(input, 1);
if (!success) {
throw new EffekLoadException("Failed to load " + assetLocation);
LOGGER.error("Failed to load " + name);
return Optional.empty();
}

for (TextureType texType : TextureType.values()) {
int count = effect.textureCount(texType);
load(
manager,
name, count,
i -> effect.getTexturePath(i, texType),
(b, len, i) -> effect.loadTexture(b, len, i, texType)
);
try {
for (TextureType texType : TextureType.values()) {
int count = effect.textureCount(texType);
load(
manager,
name, count,
i -> effect.getTexturePath(i, texType),
(b, len, i) -> effect.loadTexture(b, len, i, texType)
);
}
load(manager, name, effect.modelCount(), effect::getModelPath, effect::loadModel);
load(manager, name, effect.curveCount(), effect::getCurvePath, effect::loadCurve);
load(manager, name, effect.materialCount(), effect::getMaterialPath, effect::loadMaterial);
return Optional.of(effect);
} catch (FileNotFoundException ex) {
LOGGER.error("Failed to load " + name, ex);
effect.close();
return Optional.empty();
}
load(manager, name, effect.modelCount(), effect::getModelPath, effect::loadModel);
load(manager, name, effect.curveCount(), effect::getCurvePath, effect::loadCurve);
load(manager, name, effect.materialCount(), effect::getMaterialPath, effect::loadMaterial);
return effect;
} catch (IOException ex) {
handleCheckedException(ex);
return null;
return Optional.empty();
}
}

Expand All @@ -104,8 +104,10 @@ private void load(
var main = new LimitlessResourceLocation(modid, mcAssetPath);
var fallback = new LimitlessResourceLocation(modid, fallbackMcAssetPath);
// Load from disk.
try (var resource = getResourceOrUseFallbackPath(manager, main, fallback)) {
byte[] bytes = IOUtils.toByteArray(resource.getInputStream());
var resource = getResourceOrUseFallbackPath(manager, main, fallback)
.orElseThrow(() -> new FileNotFoundException("Failed to load %s or %s".formatted(main, fallback)));
try (var input = resource.open()) {
byte[] bytes = IOUtils.toByteArray(input);
boolean success = loadMethod.accept(bytes, bytes.length, i);
if (!success) {
String info = String.format("Failed to load effek data %s", effekAssetPath);
Expand All @@ -116,16 +118,12 @@ private void load(
}
}

private static Resource getResourceOrUseFallbackPath(
private static Optional<Resource> getResourceOrUseFallbackPath(
ResourceManager manager,
ResourceLocation path,
ResourceLocation fallback
) throws IOException {
try {
return manager.getResource(path);
} catch (FileNotFoundException ignored) {
return manager.getResource(fallback);
}
) {
return manager.getResource(path).or(() -> manager.getResource(fallback));
}

protected static class Preparations {
Expand Down Expand Up @@ -159,10 +157,10 @@ private static ResourceLocation createEffekName(ResourceLocation location) {
protected void apply(Preparations prep_, ResourceManager manager, ProfilerFiller profilerFiller) {
EffekRenderer.init();
var prep = new Preparations();
for (var effek : manager.listResources("effeks", s -> s.endsWith(".efkefc"))) {
var name = createEffekName(effek);
prep.loadedEffects.put(name, new EffectDefinition().setEffect(loadEffect(manager, name)));
}
manager.listResources("effeks", rl -> rl.getPath().endsWith(".efkefc")).forEach((location, resource) -> {
var name = createEffekName(location);
loadEffect(manager, name, resource).ifPresent(effect -> prep.loadedEffects.put(name, new EffectDefinition().setEffect(effect)));
});
unloadAll();
loadedEffects.putAll(prep.loadedEffects);
INSTANCE = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package mod.chloeprime.aaaparticles.client.render;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import mod.chloeprime.aaaparticles.api.client.effekseer.DeviceType;
import mod.chloeprime.aaaparticles.api.client.effekseer.Effekseer;
import mod.chloeprime.aaaparticles.client.loader.EffekAssetLoader;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import org.joml.Matrix4f;
import org.lwjgl.BufferUtils;

import java.nio.FloatBuffer;
Expand Down Expand Up @@ -52,15 +52,15 @@ private static void draw(float partialTick, PoseStack pose, Matrix4f projection,
int w = MINECRAFT.getWindow().getWidth();
int h = MINECRAFT.getWindow().getHeight();

projection.store(PROJECTION_BUFFER);
projection.get(PROJECTION_BUFFER);
transposeMatrix(PROJECTION_BUFFER);
PROJECTION_BUFFER.get(PROJECTION_MATRIX_DATA);

pose.pushPose();
{
pose.translate(-camera.getPosition().x(), -camera.getPosition().y(), -camera.getPosition().z());

pose.last().pose().store(CAMERA_TRANSFORM_BUFFER);
pose.last().pose().get(CAMERA_TRANSFORM_BUFFER);
transposeMatrix(CAMERA_TRANSFORM_BUFFER);
CAMERA_TRANSFORM_BUFFER.get(CAMERA_TRANSFORM_DATA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public void encode(FriendlyByteBuf buf) {
public void handle(Supplier<PacketContext> ctx) {
var context = ctx.get();
var player = context.getPlayer();
context.queue(() -> spawnInWorld(player.getLevel(), player));
context.queue(() -> spawnInWorld(player.level(), player));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.minecraft.resources.ResourceLocation;

/**
* Implementation moved to {@link mod.chloeprime.aaaparticles.mixin.MixinResourceLocation}
* 仍然需要 {@link mod.chloeprime.aaaparticles.mixin.MixinResourceLocation} 才能完全去除 Path 的有效性验证
*/
public class LimitlessResourceLocation extends ResourceLocation {
public LimitlessResourceLocation(String namespace, String path) {
super(namespace, path);
super(namespace, path, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = ResourceLocation.class, priority = Integer.MAX_VALUE - 5)
@Mixin(value = ResourceLocation.class, priority = Integer.MAX_VALUE)
public class MixinResourceLocation {
@Inject(method = "validPathChar", at = @At("HEAD"), cancellable = true)
private static void modernfixCompat(char c, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(true);
}

@Inject(method = "isValidPath", at = @At("HEAD"), cancellable = true)
private static void isValidPath(String string, CallbackInfoReturnable<Boolean> cir) {
if ("DUMMY".equals(string)) {
cir.setReturnValue(false);
}
if (string.startsWith("effeks/")) {
cir.setReturnValue(true);
}
private static void fixDfuCrash(String string, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(!"DUMMY".equals(string));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.forgespi.Environment;

@Mod(AAAParticles.MOD_ID)
public class AAAParticlesForge {
public AAAParticlesForge() {
var modbus = FMLJavaModLoadingContext.get().getModEventBus();
var forgebus = MinecraftForge.EVENT_BUS;
EventBuses.registerModEventBus(AAAParticles.MOD_ID, modbus);
AAAParticles.init();

DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
if (Environment.get().getDist().isClient()) {
AAAParticlesClient.init();
MinecraftForge.EVENT_BUS.addListener(AAAParticlesForgeClient::onClientSetup);
});
modbus.addListener(AAAParticlesForgeClient::onClientSetup);
if (AAAParticlesForgeClient.USE_RENDER_EVENT) {
forgebus.addListener(AAAParticlesForgeClient::onRenderStage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package mod.chloeprime.aaaparticles.forge;

import mod.chloeprime.aaaparticles.client.AAAParticlesClient;
import mod.chloeprime.aaaparticles.client.render.EffekRenderer;
import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

public class AAAParticlesForgeClient {
public static final boolean USE_RENDER_EVENT = false;
public static final RenderLevelStageEvent.Stage RENDER_STAGE = RenderLevelStageEvent.Stage.AFTER_LEVEL;

static void onRenderStage(RenderLevelStageEvent e) {
if (e.getStage() != RENDER_STAGE) {
return;
}
EffekRenderer.onRenderWorldLast(e.getPartialTick(), e.getPoseStack(), e.getProjectionMatrix(), e.getCamera());
}

static void onClientSetup(FMLClientSetupEvent e) {
AAAParticlesClient.setup();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package mod.chloeprime.aaaparticles.forge.mixin.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import mod.chloeprime.aaaparticles.client.render.EffekRenderer;
import mod.chloeprime.aaaparticles.forge.AAAParticlesForgeClient;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraftforge.client.MinecraftForgeClient;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -16,7 +17,10 @@
@Mixin(LevelRenderer.class)
public class MixinLevelRenderer {
@Inject(method = "renderLevel", at = @At("RETURN"))
private void onRenderLevelLast(PoseStack pose, float g, long m, boolean bl, Camera arg2, GameRenderer arg3, LightTexture arg4, Matrix4f arg5, CallbackInfo ci) {
EffekRenderer.onRenderWorldLast(MinecraftForgeClient.getPartialTick(), pose, arg5, arg2);
private void onRenderLevelLast(PoseStack pose, float g, long l, boolean bl, Camera camera, GameRenderer arg3, LightTexture arg4, Matrix4f projection, CallbackInfo ci) {
if (AAAParticlesForgeClient.USE_RENDER_EVENT) {
return;
}
EffekRenderer.onRenderWorldLast(Minecraft.getInstance().getPartialTick(), pose, projection, camera);
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ minecraft_version=1.20.1
enabled_platforms=fabric,forge

archives_base_name=aaa_particles
mod_version=1.20.1-1.0.6
mod_version=1.20.1-1.0.7
maven_group=mod.chloeprime

architectury_version=9.2.14

fabric_loader_version=0.15.7
fabric_api_version=0.90.4+1.20.1

forge_version=1.20.1-47.2.20
forge_version=1.20.1-47.2.1

0 comments on commit 737c42d

Please sign in to comment.