Implemented footstep particle in 1.13 -> 1.12.2 and fixed depthsuspend texture

This commit is contained in:
FlorianMichael 2024-01-02 01:28:22 +01:00
parent 65c17c8e94
commit 5f7a967d68
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
10 changed files with 228 additions and 4 deletions

View File

@ -60,6 +60,8 @@ dependencies {
modJij(fabricApi.module("fabric-networking-api-v1", project.fabric_api_version))
modJij(fabricApi.module("fabric-command-api-v2", project.fabric_api_version))
modJij(fabricApi.module("fabric-lifecycle-events-v1", project.fabric_api_version))
modJij(fabricApi.module("fabric-particles-v1", project.fabric_api_version))
modJij(fabricApi.module("fabric-registry-sync-v0", project.fabric_api_version))
// ViaVersion Libraries
jij "com.viaversion:viaversion-common:${project.viaversion_version}"

View File

@ -26,6 +26,7 @@ import de.florianmichael.viafabricplus.fixes.classic.CPEAdditions;
import de.florianmichael.viafabricplus.fixes.classic.GridItemSelectionScreen;
import de.florianmichael.viafabricplus.fixes.data.ResourcePackHeaderDiff;
import de.florianmichael.viafabricplus.fixes.entity.EntityDimensionReplacements;
import de.florianmichael.viafabricplus.fixes.particle.FootStepParticle;
import de.florianmichael.viafabricplus.injection.ViaFabricPlusMixinPlugin;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
@ -130,6 +131,9 @@ public class ClientsideFixes {
currentChatLength = Short.MAX_VALUE * 2;
}
});
// Register the footstep particle
FootStepParticle.init();
}
/**

View File

@ -0,0 +1,105 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.fixes.particle;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.client.particle.*;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
public class FootStepParticle extends AbstractSlowingParticle {
public static int ID;
protected FootStepParticle(ClientWorld clientWorld, double d, double e, double f, double g, double h, double i) {
super(clientWorld, d, e, f, g, h, i);
this.scale = 0.125F;
this.setMaxAge(200);
this.setVelocity(0, 0, 0);
}
@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
}
@Override
public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float tickDelta) {
final float strength = ((float) this.age + tickDelta) / (float) this.maxAge;
this.alpha = 2.0F - (strength * strength) * 2.0F;
if (this.alpha > 1.0F) {
this.alpha = 0.2F;
} else {
this.alpha *= 0.2F;
}
final Vec3d cameraPos = camera.getPos();
final float x = (float) (MathHelper.lerp(tickDelta, this.prevPosX, this.x) - cameraPos.getX());
final float y = (float) (MathHelper.lerp(tickDelta, this.prevPosY, this.y) - cameraPos.getY());
final float z = (float) (MathHelper.lerp(tickDelta, this.prevPosZ, this.z) - cameraPos.getZ());
final float minU = this.getMinU();
final float maxU = this.getMaxU();
final float minV = this.getMinV();
final float maxV = this.getMaxV();
final int light = this.getBrightness(tickDelta); // This is missing in the original code, that's why the particles are broken
vertexConsumer.vertex(x - scale, y, z + scale).texture(maxU, maxV).color(this.red, this.green, this.blue, this.alpha).light(light).next();
vertexConsumer.vertex(x + scale, y, z + scale).texture(maxU, minV).color(this.red, this.green, this.blue, this.alpha).light(light).next();
vertexConsumer.vertex(x + scale, y, z - scale).texture(minU, minV).color(this.red, this.green, this.blue, this.alpha).light(light).next();
vertexConsumer.vertex(x - scale, y, z - scale).texture(minU, maxV).color(this.red, this.green, this.blue, this.alpha).light(light).next();
}
public static void init() {
final DefaultParticleType footStepType = FabricParticleTypes.simple(true);
Registry.register(Registries.PARTICLE_TYPE, new Identifier("viafabricplus", "footprint"), footStepType);
ParticleFactoryRegistry.getInstance().register(footStepType, FootStepParticle.Factory::new); // Add some dummy factory
ID = Registries.PARTICLE_TYPE.getRawId(footStepType);
}
public static class Factory implements ParticleFactory<DefaultParticleType> {
private final SpriteProvider spriteProvider;
public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}
@Override
public Particle createParticle(DefaultParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
FootStepParticle particle = new FootStepParticle(world, x, y, z, velocityX, velocityY, velocityZ);
particle.setSprite(this.spriteProvider);
return particle;
}
}
}

View File

@ -30,7 +30,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Main.class)
public abstract class MixinMain {
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;initCrashReport()V"))
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;startTimerHack()V"))
private static void bootstrap(CallbackInfo ci) {
LoadCallback.EVENT.invoker().onLoad(LoadCallback.State.PRE);
ViaFabricPlus.global().bootstrap();

View File

@ -0,0 +1,43 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
import com.viaversion.viaversion.api.data.MappingDataBase;
import de.florianmichael.viafabricplus.fixes.particle.FootStepParticle;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(value = MappingDataBase.class, remap = false)
public abstract class MixinMappingDataBase {
@Shadow protected abstract int checkValidity(int id, int mappedId, String type);
@Redirect(method = "getNewParticleId", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/data/MappingDataBase;checkValidity(IILjava/lang/String;)I"))
private int passFoodStepParticle(MappingDataBase instance, int id, int mappedId, String type) {
if (id == FootStepParticle.ID) {
return id;
} else {
return checkValidity(id, mappedId, type);
}
}
}

View File

@ -0,0 +1,61 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
import de.florianmichael.viafabricplus.fixes.particle.FootStepParticle;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = ParticleRewriter.class, remap = false)
public abstract class MixinParticleRewriter {
@Unique
private static int viaFabricPlus$particleIndex = 0;
@ModifyArg(method = "add(I)V", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter$NewParticle;<init>(ILcom/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter$ParticleDataHandler;)V"))
private static int replaceIds(int id) {
viaFabricPlus$particleIndex++;
final int oldId = viaFabricPlus$particleIndex - 1;
if (oldId == 8) { // minecraft:depthsuspend -> minecraft:mycelium
return 32;
} else if (oldId == 28) { // minecraft:footstep -> viafabricplus:footstep
return FootStepParticle.ID;
} else {
return id;
}
}
@Inject(method = "rewriteParticle", at = @At("HEAD"), cancellable = true)
private static void updateFootStepId(int particleId, Integer[] data, CallbackInfoReturnable<Particle> cir) {
// Don't allow the server to send footstep particles directly as this would allow the server
// to crash ViaFabricPlus clients without annoying vanilla clients
if (particleId == FootStepParticle.ID) {
cir.setReturnValue(null);
}
}
}

View File

@ -0,0 +1,5 @@
{
"textures": [
"viafabricplus:footprint"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 B

View File

@ -2,7 +2,6 @@
"schemaVersion": 1,
"id": "viafabricplus",
"version": "${version}",
"name": "ViaFabricPlus",
"description": "Fabric mod to connect to EVERY Minecraft server version (Release, Beta, Alpha, Classic, Snapshots, Bedrock) with QoL fixes to the gameplay",
"authors": [
@ -34,7 +33,6 @@
"sources": "https://github.com/ViaVersion/ViaFabricPlus",
"issues": "https://github.com/ViaVersion/ViaFabricPlus/issues"
},
"license": "GPL-v3",
"icon": "assets/viafabricplus/icon.png",
"environment": "client",
@ -53,6 +51,8 @@
"fabric-networking-api-v1": ">=3.1.1",
"fabric-command-api-v2": ">=2.2.18",
"fabric-lifecycle-events-v1": ">=2.2.28",
"fabric-particles-v1": ">=1.1.6",
"fabric-registry-sync-v0": ">=4.0.13",
"minecraft": ">=1.20.3",
"java": ">=17"
},

View File

@ -182,6 +182,7 @@
"fixes.viaversion.MixinMetadataRewriter1_15To1_14_4",
"fixes.viaversion.MixinMetadataRewriter1_9To1_8",
"fixes.viaversion.MixinNamedCompoundTagType",
"fixes.viaversion.MixinParticleRewriter",
"fixes.viaversion.MixinProtocol1_11To1_10",
"fixes.viaversion.MixinProtocol1_12To1_11_1",
"fixes.viaversion.MixinProtocol1_20_2To1_20",
@ -204,5 +205,8 @@
},
"overwrites": {
"requireAnnotations": true
}
},
"mixins": [
"fixes.viaversion.MixinMappingDataBase"
]
}