Skip to content

Commit

Permalink
fix mixin issue, change version format
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Feb 3, 2025
1 parent cda9269 commit a2f0ffb
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 41 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = "$project.archives_base_name-${loom.getPlatform().get().id()}"
version = "$project.minecraft_version-$project.mod_version+v${new Date().format('yyMMdd')}"
version = "$project.mod_main_version.${new Date().format('yyMMdd')}+mc$project.minecraft_version"
group = project.maven_group

loom {
Expand Down Expand Up @@ -37,14 +37,15 @@ dependencies {
parchment("org.parchmentmc.data:parchment-${project.minecraft_version}:${project.parchment_mappings}@zip")
}
neoForge "net.neoforged:neoforge:${project.neoforge_version}"

compileOnly "com.google.code.findbugs:jsr305:${project.jsr305_version}"
}

processResources {
inputs.property "version", project.version+'+v'+new Date().format('yyMMdd')
inputs.property "version", project.version

filesMatching("META-INF/neoforge.mods.toml") {
expand "version": project.mod_version+'+v'+new Date().format('yyMMdd')
expand "version": project.version
}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ loom.platform = neoforge
parchment_mappings=2024.11.17

# Mod Properties
mod_version = 1.4.147
mod_main_version = 0.1.100
carpet_version = 1.4.147
maven_group = org.thinkingstudio.sheet
archives_base_name = sheet
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package carpet.mixins;

import carpet.helpers.CarpetTaintedList;
import carpet.network.CarpetClient;
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.PacketFlow;
//import carpet.helpers.CarpetTaintedList;
//import carpet.network.CarpetClient;
//import net.minecraft.network.ConnectionProtocol;
//import net.minecraft.network.FriendlyByteBuf;
//import net.minecraft.network.codec.StreamCodec;
//import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
//import org.spongepowered.asm.mixin.injection.At;
//import org.spongepowered.asm.mixin.injection.Inject;
//import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
//
//import java.util.List;

import java.util.List;

@Mixin(CustomPacketPayload.class)
@Mixin(value = CustomPacketPayload.class, priority = 9999)
public interface CustomPacketPayload_networkStuffMixin
{
//private static <B extends FriendlyByteBuf> void onCodec(final CustomPacketPayload.FallbackProvider<B> fallbackProvider, final List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, final CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
@Inject(method = "codec(Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload$FallbackProvider;Ljava/util/List;Lnet/minecraft/network/ConnectionProtocol;Lnet/minecraft/network/protocol/PacketFlow;)Lnet/minecraft/network/codec/StreamCodec;", at = @At("HEAD"), cancellable = true)
private static <B extends FriendlyByteBuf> void onCodec(CustomPacketPayload.FallbackProvider<B> fallbackProvider, List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, ConnectionProtocol protocol, PacketFlow packetFlow, CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
{
// this is stupid hack to make sure carpet payloads are always registered
// that might collide with other mods that do the same thing
// so we may need to adjust this in the future
if (!(list instanceof CarpetTaintedList))
{
List<CustomPacketPayload.TypeAndCodec<? super B, ?>> extendedList = new CarpetTaintedList<>(list);
extendedList.add(new CustomPacketPayload.TypeAndCodec<>(CarpetClient.CarpetPayload.TYPE, CarpetClient.CarpetPayload.STREAM_CODEC));
cir.setReturnValue(CustomPacketPayload.codec(fallbackProvider, extendedList, protocol, packetFlow));
}
}
// @Inject(method = "codec(Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload$FallbackProvider;Ljava/util/List;Lnet/minecraft/network/ConnectionProtocol;Lnet/minecraft/network/protocol/PacketFlow;)Lnet/minecraft/network/codec/StreamCodec;", at = @At("HEAD"), cancellable = true)
// private static <B extends FriendlyByteBuf> void onCodec(CustomPacketPayload.FallbackProvider<B> fallbackProvider, List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, ConnectionProtocol protocol, PacketFlow packetFlow, CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
// {
// // this is stupid hack to make sure carpet payloads are always registered
// // that might collide with other mods that do the same thing
// // so we may need to adjust this in the future
// if (!(list instanceof CarpetTaintedList))
// {
// List<CustomPacketPayload.TypeAndCodec<? super B, ?>> extendedList = new CarpetTaintedList<>(list);
// extendedList.add(new CustomPacketPayload.TypeAndCodec<>(CarpetClient.CarpetPayload.TYPE, CarpetClient.CarpetPayload.STREAM_CODEC));
// cir.setReturnValue(CustomPacketPayload.codec(fallbackProvider, extendedList, protocol, packetFlow));
// }
// }
}
6 changes: 3 additions & 3 deletions src/main/java/carpet/mixins/ExplosionAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public interface ExplosionAccessor {
@Accessor
RandomSource getRandom();

@Accessor
@Accessor(remap = false)
double getX();

@Accessor
@Accessor(remap = false)
double getY();

@Accessor
@Accessor(remap = false)
double getZ();

@Accessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;

@Mixin(value = Explosion.class)
@Mixin(Explosion.class)
public abstract class Explosion_optimizedTntMixin
{
@Shadow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void onExplosion(boolean spawnParticles, CallbackInfo ci)
{
if (EXPLOSION_OUTCOME.isNeeded() && !level.isClientSide())
{
EXPLOSION_OUTCOME.onExplosion((ServerLevel) level, source, this::getIndirectSourceEntity, x, y, z, radius, fire, toBlow, affectedEntities, blockInteraction);
EXPLOSION_OUTCOME.onExplosion((ServerLevel) level, source, this::getIndirectSourceEntity, this.x, this.y, this.z, radius, fire, toBlow, affectedEntities, blockInteraction);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/carpet/mixins/PerfCommand_permissionMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@Mixin(PerfCommand.class)
public class PerfCommand_permissionMixin
{
@Inject(method = "method_37340", at = @At("HEAD"), cancellable = true, remap = false)
// method_37340 = lambda$register$0
@Inject(method = { "method_37340(Lnet/minecraft/commands/CommandSourceStack;)Z", "lambda$register$0(Lnet/minecraft/commands/CommandSourceStack;)Z" }, at = @At("HEAD"), cancellable = true, remap = false)
private static void canRun(CommandSourceStack source, CallbackInfoReturnable<Boolean> cir)
{
cir.setReturnValue(source.hasPermission(CarpetSettings.perfPermissionLevel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

@Mixin(ReloadCommand.class)
public class ReloadCommand_reloadAppsMixin {
//method_13530(Lcom/mojang/brigadier/context/CommandContext;)I
// method_13530(Lcom/mojang/brigadier/context/CommandContext;)I = lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I
// internal of register.
@Inject(method = "method_13530", at = @At("TAIL"), remap = false)
@Inject(method = { "method_13530(Lcom/mojang/brigadier/context/CommandContext;)I", "lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I" }, at = @At("TAIL"), remap = false)
private static void onReload(CommandContext<CommandSourceStack> context, CallbackInfoReturnable<Integer> cir)
{
// can't fetch here the reference to the server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import carpet.CarpetServer;
import carpet.utils.CarpetRulePrinter;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.common.NeoForge;

@Mod(SheetModEntrypoint.MODID)
public class SheetModEntrypoint {
public static final String MODID = "sheet";

public SheetModEntrypoint() {
public SheetModEntrypoint(IEventBus modEventBus) {
CarpetServer.onGameStarted();
if (FMLLoader.getDist().isDedicatedServer()) {
CarpetRulePrinter.onInitializeServer();
}

SheetModEvents.registerEvents();
SheetModEvents.registerEvents(modEventBus, NeoForge.EVENT_BUS);
}
}
15 changes: 14 additions & 1 deletion src/main/java/org/thinkingstudio/sheet/SheetModEvents.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package org.thinkingstudio.sheet;

import carpet.CarpetServer;
import carpet.network.CarpetClient;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.entity.living.LivingSwapItemsEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.registration.PayloadRegistrar;

import static carpet.script.CarpetEventServer.Event.PLAYER_SWAPS_HANDS;

public class SheetModEvents {
public static void registerEvents() {
public static void registerEvents(IEventBus modEventBus, IEventBus forgeEventBus) {
NeoForge.EVENT_BUS.addListener(EventPriority.HIGHEST, RegisterCommandsEvent.class, event -> {
CarpetServer.registerCarpetCommands(event.getDispatcher(), event.getCommandSelection(), event.getBuildContext());
});
Expand All @@ -23,5 +27,14 @@ public static void registerEvents() {
event.isCanceled();
}
});

modEventBus.addListener(EventPriority.HIGHEST, RegisterPayloadHandlersEvent.class, event -> {
final PayloadRegistrar registrar = event.registrar(SheetModReference.MODID);

registrar.playBidirectional(
CarpetClient.CarpetPayload.TYPE, CarpetClient.CarpetPayload.STREAM_CODEC,
(payload, context) -> context.handle(payload)
);
});
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/thinkingstudio/sheet/util/PermissionHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.thinkingstudio.sheet.util;

import net.neoforged.fml.ModList;
import net.neoforged.neoforge.server.ServerLifecycleHooks;
import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent;
import net.neoforged.neoforge.server.permission.nodes.PermissionNode;
import org.thinkingstudio.sheet.SheetModReference;

import java.util.ArrayList;

// TODO
public class PermissionHooks {
private static final ArrayList<PermissionNode<?>> PENDING = makeRegisterQueue();

private static boolean hasPermissionAPI() {
// in version 1.18, the permission api only available on the service side.
return ServerLifecycleHooks.getCurrentServer() != null;
}

private static ArrayList<PermissionNode<?>> makeRegisterQueue() {
var modEventBus = ModList.get().getModContainerById(SheetModReference.MODID).orElseThrow().getEventBus();
modEventBus.addListener(PermissionGatherEvent.Nodes.class, event -> event.addNodes(PENDING));
return new ArrayList<>();
}
}
1 change: 0 additions & 1 deletion src/main/resources/carpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
"ChestBlock_customStickyMixin",
"PistonStructureResolver_customStickyMixin",

"CustomPacketPayload_networkStuffMixin",
"ServerGamePacketListenerimpl_connectionMixin"

],
Expand Down

0 comments on commit a2f0ffb

Please sign in to comment.