Skip to content

Commit

Permalink
Update mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Nov 12, 2024
1 parent 0c33c5c commit fddb3eb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package one.oktw.galaxy.mixin.tweak;

import net.minecraft.entity.player.PlayerPosition;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand Down Expand Up @@ -60,8 +61,8 @@ private void noBlockingMove(PlayerMoveC2SPacket packet, CallbackInfo ci) {
}
}

@Inject(method = "requestTeleport(DDDFFLjava/util/Set;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updatePositionAndAngles(DDDFF)V", shift = At.Shift.AFTER))
private void onTeleport(double x, double y, double z, float yaw, float pitch, Set<PositionFlag> set, CallbackInfo ci) {
@Inject(method = "requestTeleport(Lnet/minecraft/entity/player/PlayerPosition;Ljava/util/Set;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;setPosition(Lnet/minecraft/entity/player/PlayerPosition;Ljava/util/Set;)V", shift = At.Shift.AFTER))
private void onTeleport(PlayerPosition pos, Set<PositionFlag> flags, CallbackInfo ci) {
ServerWorld world = player.getServerWorld();
if (!world.getPlayers().contains(player)) return;
world.getChunkManager().updatePosition(this.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ private WorldChunk getExistingChunk(World world, int x, int z) {
WorldChunk chunk = (WorldChunk) world.getChunkAsView(chunkPos.x, chunkPos.z);
if (chunk != null) return chunk;
}
return new EmptyChunk(world, new ChunkPos(x, z), world.getRegistryManager().get(RegistryKeys.BIOME).entryOf(BiomeKeys.PLAINS));
return new EmptyChunk(world, new ChunkPos(x, z), world.getRegistryManager().getOrThrow(RegistryKeys.BIOME).getOrThrow(BiomeKeys.PLAINS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_RealTime {
),
to = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"
target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public abstract class EntityMixin_RealTime {
target = "Lnet/minecraft/entity/Entity;stopRiding()V"
),
to = @At(
value = "FIELD",
target = "Lnet/minecraft/entity/Entity;horizontalSpeed:F",
opcode = Opcodes.GETFIELD
value = "INVOKE",
target = "Lnet/minecraft/entity/Entity;tickPortalTeleportation()V"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import net.minecraft.server.network.ServerCommonNetworkHandler;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import org.objectweb.asm.Opcodes;
import net.minecraft.util.Cooldown;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -59,10 +59,6 @@
public abstract class ServerPlayNetworkHandlerMixin_RealTime extends ServerCommonNetworkHandler {
@Shadow
public ServerPlayerEntity player;
@Shadow
private int messageCooldown;
@Shadow
private int creativeItemDropThreshold;

public ServerPlayNetworkHandlerMixin_RealTime(MinecraftServer server, ClientConnection connection, ConnectedClientData clientData) {
super(server, connection, clientData);
Expand All @@ -71,27 +67,14 @@ public ServerPlayNetworkHandlerMixin_RealTime(MinecraftServer server, ClientConn
@Redirect(
method = "tick",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;messageCooldown:I",
opcode = Opcodes.PUTFIELD,
ordinal = 0
)
)
private void realTimeImpl$adjustForRealTimeChatSpamCheck(final ServerPlayNetworkHandler self, final int modifier) {
final int ticks = (int) ((RealTimeTrackingBridge) this.server).realTimeBridge$getRealTimeTicks();
this.messageCooldown = Math.max(0, this.messageCooldown - ticks);
}

@Redirect(
method = "tick",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;creativeItemDropThreshold:I",
opcode = Opcodes.PUTFIELD, ordinal = 0
value = "INVOKE",
target = "Lnet/minecraft/util/Cooldown;tick()V"
)
)
private void realTimeImpl$adjustForRealTimeDropSpamCheck(final ServerPlayNetworkHandler self, final int modifier) {
private void realTimeImpl$adjustForRealTimeCooldownTick(Cooldown instance) {
final int ticks = (int) ((RealTimeTrackingBridge) this.server).realTimeBridge$getRealTimeTicks();
this.creativeItemDropThreshold = Math.max(0, this.creativeItemDropThreshold - ticks);
for (int i = 0; i < ticks; i++) {
instance.tick();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,28 @@
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.world.GameRules;
import net.minecraft.world.MutableWorldProperties;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.level.ServerWorldProperties;
import org.jetbrains.annotations.Nullable;
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.common.bridge.RealTimeTrackingBridge;

import java.util.function.Supplier;

@Mixin(ServerWorld.class)
public abstract class WorldMixin_RealTime extends World implements RealTimeTrackingBridge {
protected WorldMixin_RealTime(MutableWorldProperties properties, RegistryKey<World> registryRef, DynamicRegistryManager registryManager, RegistryEntry<DimensionType> dimensionEntry, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long biomeAccess, int maxChainedNeighborUpdates) {
super(properties, registryRef, registryManager, dimensionEntry, profiler, isClient, debugWorld, biomeAccess, maxChainedNeighborUpdates);
@Shadow
@Final
private ServerWorldProperties worldProperties;

protected WorldMixin_RealTime(MutableWorldProperties properties, RegistryKey<World> registryRef, DynamicRegistryManager registryManager, RegistryEntry<DimensionType> dimensionEntry, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) {
super(properties, registryRef, registryManager, dimensionEntry, isClient, debugWorld, seed, maxChainedNeighborUpdates);
}

@Shadow
Expand All @@ -77,7 +80,7 @@ protected WorldMixin_RealTime(MutableWorldProperties properties, RegistryKey<Wor

@Inject(method = "tickTime", at = @At("HEAD"))
private void realTimeImpl$fixTimeOfDayForRealTime(CallbackInfo ci) {
if (this.properties.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE)) {
if (this.worldProperties.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE)) {
// Subtract the one the original tick method is going to add
long diff = this.realTimeBridge$getRealTimeTicks() - 1;
// Don't set if we're not changing it as other mods might be listening for changes
Expand Down

0 comments on commit fddb3eb

Please sign in to comment.