Skip to content

Commit

Permalink
version 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Yancey2023 committed Apr 28, 2024
1 parent 993e915 commit e173976
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 198 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.5.7'
id 'fabric-loom' version '1.6.5'
id 'maven-publish'
}

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.10

#Fabric api
fabric_version=0.95.0+1.20.4
fabric_version=0.97.7+1.20.5

# Mod Properties
mod_version = 1.20.4-2.0
mod_version = 1.20.5-2.1
maven_group = yancey.openparticle
archives_base_name = OpenParticle
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 9 additions & 4 deletions src/main/java/yancey/openparticle/core/OpenParticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.logging.LogUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.client.MinecraftClient;
import net.minecraft.registry.Registries;
Expand All @@ -11,7 +13,7 @@
import org.slf4j.Logger;
import yancey.openparticle.core.command.CommandPar;
import yancey.openparticle.core.keys.KeyboardManager;
import yancey.openparticle.core.network.NetworkHandler;
import yancey.openparticle.core.network.KeyboardPayloadC2S;

import java.net.URL;
import java.nio.file.Files;
Expand All @@ -21,7 +23,7 @@

public class OpenParticle implements ModInitializer {

public static final boolean isDebug = true;
public static final boolean isDebug = false;
public static final String MOD_ID = "openparticle";
private static final Logger LOGGER = LogUtils.getLogger();

Expand All @@ -41,10 +43,13 @@ public void onInitialize() {
}
}
System.load(dest.toString());
NetworkHandler.initServer();
PayloadTypeRegistry.playC2S().register(KeyboardPayloadC2S.ID, KeyboardPayloadC2S.CODEC);
ServerPlayNetworking.registerGlobalReceiver(KeyboardPayloadC2S.ID, (payload, context) ->
context.player().server.execute(() ->
KeyboardManager.runInServe(payload.idList(), context.player())));
KeyboardManager.init(false);
Registry.register(Registries.PARTICLE_TYPE, new Identifier(MOD_ID, "better_particle"), FabricParticleTypes.simple());
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
CommandPar.init(dispatcher, true));
CommandPar.init(dispatcher));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package yancey.openparticle.core.client;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import yancey.openparticle.core.core.OpenParticleCore;
import yancey.openparticle.core.keys.KeyboardManager;
import yancey.openparticle.core.network.NetworkHandler;
import yancey.openparticle.core.network.RunTickPayloadS2C;

public class OpenParticleClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
NetworkHandler.initClient();
PayloadTypeRegistry.playS2C().register(RunTickPayloadS2C.ID, RunTickPayloadS2C.CODEC);
ClientPlayNetworking.registerGlobalReceiver(RunTickPayloadS2C.ID, (payload, context) -> {
if (context.player().getWorld() == null) {
return;
}
OpenParticleCore.runTick(payload.path(), payload.tick());
});
KeyboardManager.init(true);
// ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) ->
// CommandPar.init(dispatcher, false));
}
}
101 changes: 20 additions & 81 deletions src/main/java/yancey/openparticle/core/command/CommandPar.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,36 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.command.CommandSource;
import net.minecraft.network.PacketByteBuf;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import yancey.openparticle.core.core.OpenParticleCore;
import yancey.openparticle.core.network.NetworkHandler;

import java.util.function.Function;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;

public class CommandPar {

public static <T extends CommandSource> void init(CommandDispatcher<T> dispatcher, boolean isInitInServer) {
if (isInitInServer) {
command(dispatcher, true, false);
}
command(dispatcher, isInitInServer, true);
public static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
RequiredArgumentBuilder<ServerCommandSource, String> path = argument("path", StringArgumentType.greedyString());
dispatcher.register(literal("par")
.requires(source -> source.hasPermissionLevel(2))
.then(literal("loadAndRun").then(path.executes(context -> execute(context, true, true))))
.then(literal("load").then(path.executes(context -> execute(context, true, false))))
.then(literal("run").executes(context -> execute(context, false, true))));
}

private static <T extends CommandSource> void command(CommandDispatcher<T> dispatcher, boolean isInitInServer, boolean isRunInClient) {
LiteralArgumentBuilder<T> builder = LiteralArgumentBuilder.literal(isRunInClient ? "parc" : "par");
Function<String, LiteralArgumentBuilder<T>> literal = LiteralArgumentBuilder::literal;
if (isInitInServer) {
builder.requires(source -> source.hasPermissionLevel(2));
} else {
builder.then(literal.apply("stop").executes(context -> {
OpenParticleCore.stop();
return 1;
}));
}
RequiredArgumentBuilder<T, String> path = RequiredArgumentBuilder.argument("path", StringArgumentType.greedyString());
Function<Identifier, RequiredArgumentBuilder<T, String>> execute = identifier ->
path.executes(executeFile(identifier, isRunInClient));
dispatcher.register(builder
.then(literal.apply("loadAndRun")
.then(execute.apply(NetworkHandler.ID_LOAD_AND_RUN)))
.then(literal.apply("load")
.then(execute.apply(NetworkHandler.ID_LOAD)))
.then(literal.apply("run")
.executes(executeFile(NetworkHandler.ID_RUN, isRunInClient)))
);
}

private static <T extends CommandSource> Command<T> executeFile(Identifier identifier, boolean isRunInClient) {
return context -> {
String path = null;
if (identifier != NetworkHandler.ID_RUN) {
path = StringArgumentType.getString(context, "path");
}
World world;
CommandSource source = context.getSource();
if (source instanceof FabricClientCommandSource clientCommandSource) {
world = clientCommandSource.getWorld();
} else if (source instanceof ServerCommandSource serverCommandSource) {
world = serverCommandSource.getWorld();
if (isRunInClient) {
PacketByteBuf packetByteBuf = PacketByteBufs.create();
if (path != null) {
packetByteBuf.writeString(path);
}
for (ServerPlayerEntity serverPlayerEntity : serverCommandSource.getServer().getPlayerManager().getPlayerList()) {
ServerPlayNetworking.send(serverPlayerEntity, identifier, packetByteBuf);
}
return 1;
}
} else {
throw new RuntimeException("unknown command source");
public static int execute(CommandContext<ServerCommandSource> context, boolean isLoad, boolean isRun) {
if (isLoad) {
String path = StringArgumentType.getString(context, "path");
if (!OpenParticleCore.loadFile(path)) {
return 2;
}
if (world.isClient) {
return -1;
}
ServerWorld serverWorld = (ServerWorld) world;
boolean isSuccess = true;
if (identifier == NetworkHandler.ID_LOAD) {
isSuccess = OpenParticleCore.loadFile(path);
} else if (identifier == NetworkHandler.ID_RUN) {
OpenParticleCore.run(serverWorld);
} else if (identifier == NetworkHandler.ID_LOAD_AND_RUN) {
isSuccess = OpenParticleCore.loadAndRun(path, serverWorld);
} else {
throw new RuntimeException("unknown identifier -> " + identifier);
}
return isSuccess ? 1 : -1;
};
}
if (isRun && !OpenParticleCore.run(context.getSource().getWorld())) {
return 3;
}
return Command.SINGLE_SUCCESS;
}

}
15 changes: 12 additions & 3 deletions src/main/java/yancey/openparticle/core/core/OpenParticleCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import com.mojang.logging.LogUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.mixin.client.particle.ParticleManagerAccessor.SimpleSpriteProviderAccessor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Camera;
import net.minecraft.client.texture.Sprite;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
Expand All @@ -22,7 +24,7 @@
import yancey.openparticle.core.events.RunningEventManager;
import yancey.openparticle.core.mixin.BufferBuilderAccessor;
import yancey.openparticle.core.mixin.ParticleManagerAccessor;
import yancey.openparticle.core.network.NetworkHandler;
import yancey.openparticle.core.network.RunTickPayloadS2C;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -60,6 +62,7 @@ public class OpenParticleCore {
private OpenParticleCore() {

}

private static float lastRunTick = -1;
private static float lastTickDelta = -1;

Expand Down Expand Up @@ -118,9 +121,12 @@ public static void stop() {
RunningEventManager.INSTANCE.stop();
}

public static void run(ServerWorld world) {
public static boolean run(ServerWorld world) {
if (openParticleProject != null) {
run(openParticleProject.path, world);
return true;
} else {
return false;
}
}

Expand All @@ -134,7 +140,10 @@ public static void run(String path, ServerWorld world) {
stop();
return;
}
NetworkHandler.runTick(world, path, nextTick++);
RunTickPayloadS2C payload = new RunTickPayloadS2C(path, nextTick++);
for (ServerPlayerEntity serverPlayerEntity : world.getServer().getPlayerManager().getPlayerList()) {
ServerPlayNetworking.send(serverPlayerEntity, payload);
}
} finally {
LOCK.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import org.lwjgl.glfw.GLFW;
import yancey.openparticle.core.core.OpenParticleCore;
import yancey.openparticle.core.mixin.KeyBindingAccessor;
import yancey.openparticle.core.network.NetworkHandler;
import yancey.openparticle.core.network.KeyboardPayloadC2S;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -51,7 +52,7 @@ public static void init(boolean isClient) {
}
}
if (idList != null) {
NetworkHandler.keyBoardToServer(idList);
ClientPlayNetworking.send(new KeyboardPayloadC2S(idList));
}
});
}
Expand All @@ -65,8 +66,8 @@ public static void register(boolean isClient, String description, int keyCode, b
}
}

public static void runInServe(int[] idList, ServerPlayerEntity entityPlayerMP) {
for (Integer id : idList) {
public static void runInServe(List<Integer> idList, ServerPlayerEntity entityPlayerMP) {
for (int id : idList) {
onKeyPressedListenerList.get(id).onKeyPressed(entityPlayerMP);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.render.*;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Final;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import yancey.openparticle.core.core.OpenParticleCore;

@Mixin(ParticleManager.class)
Expand All @@ -22,14 +22,10 @@ public abstract class ParticleManagerMixin {
private TextureManager textureManager;


@Inject(method = "renderParticles", at = @At(value = "HEAD"))
private void injectRenderParticles(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers, LightmapTextureManager lightmapTextureManager, Camera camera, float tickDelta, CallbackInfo ci) {
@Inject(method = "renderParticles", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;depthMask(Z)V", shift = At.Shift.BEFORE))
private void injectRenderParticles(LightmapTextureManager lightmapTextureManager, Camera camera, float tickDelta, CallbackInfo ci) {
lightmapTextureManager.enable();
RenderSystem.enableDepthTest();
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix());
RenderSystem.applyModelViewMatrix();

RenderSystem.setShader(GameRenderer::getParticleProgram);
Tessellator tessellator = Tessellator.getInstance();
Expand All @@ -38,8 +34,6 @@ private void injectRenderParticles(MatrixStack matrices, VertexConsumerProvider.
OpenParticleCore.render(camera, tickDelta, bufferBuilder);
ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT.draw(tessellator);

matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.depthMask(true);
RenderSystem.disableBlend();
lightmapTextureManager.disable();
Expand All @@ -50,4 +44,9 @@ private void injectTick(CallbackInfo ci) {
OpenParticleCore.tick();
}

@Inject(method = "getDebugString", at = @At(value = "RETURN"), cancellable = true)
private void injectGetDebugString(CallbackInfoReturnable<String> cir) {
cir.setReturnValue(String.valueOf(Integer.parseInt(cir.getReturnValue()) + OpenParticleCore.getParticleSize()));
}

}
Loading

0 comments on commit e173976

Please sign in to comment.