Skip to content

Commit

Permalink
1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed Mar 17, 2022
1 parent 572c15c commit 8666541
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 129 deletions.
38 changes: 18 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.6.0'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

minecraft {
loom {
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand All @@ -26,29 +27,26 @@ dependencies {
processResources {
inputs.property "version", project.version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
filesMatching("fabric.mod.json") {
expand "version": project.mod_version
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Minecraft 1.18 upwards uses Java 17.
it.options.release = 17
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=20w48a
yarn_mappings=20w48a+build.1
loader_version=0.10.8
minecraft_version=22w11a
yarn_mappings=22w11a+build.2
loader_version=0.13.3

# Mod Properties
mod_version = 1.2
mod_version = 1.4.66
maven_group = carpet
archives_base_name = quick-carpet
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pluginManagement {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
name = 'Cotton'
url = 'https://server.bbkr.space/artifactory/libs-release/'
}
gradlePluginPortal()
}
}
8 changes: 4 additions & 4 deletions src/main/java/carpet/commands/CounterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static int displayCounter(ServerCommandSource source, String color, bool
HopperCounter counter = HopperCounter.getCounter(color);
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color: "+color));

for (BaseText message: counter.format(source.getMinecraftServer(), realtime, false))
for (BaseText message: counter.format(source.getServer(), realtime, false))
{
source.sendFeedback(message, false);
}
Expand All @@ -53,22 +53,22 @@ private static int resetCounter(ServerCommandSource source, String color)
{
if (color == null)
{
HopperCounter.resetAll(source.getMinecraftServer());
HopperCounter.resetAll(source.getServer());
Messenger.m(source, "w Restarted all counters");
}
else
{
HopperCounter counter = HopperCounter.getCounter(color);
if (counter == null) throw new CommandException(Messenger.s("Unknown wool color"));
counter.reset(source.getMinecraftServer());
counter.reset(source.getServer());
Messenger.m(source, "w Restarted "+color+" counter");
}
return 1;
}

private static int listAllCounters(ServerCommandSource source, boolean realtime)
{
for (BaseText message: HopperCounter.formatAll(source.getMinecraftServer(), realtime))
for (BaseText message: HopperCounter.formatAll(source.getServer(), realtime))
{
source.sendFeedback(message, false);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/carpet/commands/PlayerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static Collection<String> getPlayers(ServerCommandSource source)
private static ServerPlayerEntity getPlayer(CommandContext<ServerCommandSource> context)
{
String playerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getMinecraftServer();
MinecraftServer server = context.getSource().getServer();
return server.getPlayerManager().getPlayer(playerName);
}

Expand All @@ -90,7 +90,7 @@ private static boolean cantManipulate(CommandContext<ServerCommandSource> contex
return false;
}

if (!context.getSource().getMinecraftServer().getPlayerManager().isOperator(sendingPlayer.getGameProfile()))
if (!context.getSource().getServer().getPlayerManager().isOperator(sendingPlayer.getGameProfile()))
{
if (sendingPlayer != player && !(player instanceof EntityPlayerMPFake))
{
Expand All @@ -113,15 +113,15 @@ private static boolean cantReMove(CommandContext<ServerCommandSource> context)
private static boolean cantSpawn(CommandContext<ServerCommandSource> context)
{
String playerName = StringArgumentType.getString(context, "player");
MinecraftServer server = context.getSource().getMinecraftServer();
MinecraftServer server = context.getSource().getServer();
PlayerManager manager = server.getPlayerManager();
PlayerEntity player = manager.getPlayer(playerName);
if (player != null)
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is already logged on");
return true;
}
GameProfile profile = server.getUserCache().findByName(playerName);
GameProfile profile = server.getUserCache().findByName(playerName).orElse(null);
if (manager.getUserBanList().contains(profile))
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is banned");
Expand Down Expand Up @@ -184,7 +184,7 @@ private static int spawn(CommandContext<ServerCommandSource> context) throws Com
}
catch (CommandSyntaxException ignored) {}
String playerName = StringArgumentType.getString(context, "player");
MinecraftServer server = source.getMinecraftServer();
MinecraftServer server = source.getServer();
PlayerEntity player = EntityPlayerMPFake.createFake(playerName, server, pos.x, pos.y, pos.z, facing.y, facing.x, dim, mode);
if (player == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/commands/TickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static int setWarp(ServerCommandSource source, int advance, String tail_
catch (CommandSyntaxException ignored)
{
}
BaseText message = TickSpeed.tickrate_advance(source.getMinecraftServer(), player, advance, tail_command, source);
BaseText message = TickSpeed.tickrate_advance(source.getServer(), player, advance, tail_command, source);
if (message != null)
{
source.sendFeedback(message, false);
Expand All @@ -98,7 +98,7 @@ private static int healthReport(ServerCommandSource source)
{
Messenger.m(source, String.format(
"w Avg tick time: %.2f ms",
average(source.getMinecraftServer().lastTickLengths) * 1.0E-6D)
average(source.getServer().lastTickLengths) * 1.0E-6D)
);
return 1;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/carpet/mixins/CommandManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import carpet.CarpetServer;
import carpet.CarpetSettings;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.class_7157;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -25,7 +26,7 @@ public abstract class CommandManagerMixin
private CommandDispatcher<ServerCommandSource> dispatcher;

@Inject(method = "<init>", at = @At("RETURN"))
private void onRegister(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
private void onRegister(CommandManager.RegistrationEnvironment environment, class_7157 arg, CallbackInfo ci) {
CarpetServer.registerCarpetCommands(this.dispatcher);
}

Expand All @@ -45,12 +46,12 @@ private void onExecuteEnd(ServerCommandSource serverCommandSource_1, String stri
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "execute", at = @At(
value = "INVOKE",
target = "Lorg/apache/logging/log4j/Logger;isDebugEnabled()Z"
target = "Lorg/slf4j/Logger;isDebugEnabled()Z"
))
private boolean doesOutputCommandStackTrace(Logger logger)
private boolean doesOutputCommandStackTrace(Logger instance)
{
if (CarpetSettings.superSecretSetting)
return true;
return logger.isDebugEnabled();
return instance.isDebugEnabled();
}
}
37 changes: 26 additions & 11 deletions src/main/java/carpet/mixins/MinecraftServer_tickspeedMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import net.minecraft.util.Util;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.thread.ReentrantThreadExecutor;
import org.apache.logging.log4j.Logger;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -26,8 +27,6 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec

@Shadow private long timeReference;

@Shadow @Final private static Logger LOGGER;

//@Shadow private boolean profilerStartQueued;

@Shadow @Final private Profiler profiler;
Expand All @@ -41,19 +40,29 @@ public MinecraftServer_tickspeedMixin(String string)

@Shadow protected abstract boolean shouldKeepTicking();

@Shadow private long field_19248;
//@Shadow private long field_19248;

@Shadow protected abstract void method_16208();
//@Shadow protected abstract void method_16208();

@Shadow private volatile boolean loading;

@Shadow protected abstract void startMonitor(TickDurationMonitor monitor);
//@Shadow protected abstract void startMonitor(TickDurationMonitor monitor);

@Shadow private long lastTimeReference;
@Shadow private boolean waitingForNextTick;

@Shadow public abstract Iterable<ServerWorld> getWorlds();

@Shadow private boolean needsDebugSetup;
@Shadow private boolean needsRecorderSetup;
@Shadow private int ticks;

@Shadow protected abstract void startTickMetrics();

@Shadow protected abstract void runTasksTillTickEnd();

@Shadow private long nextTickTimestamp;
@Shadow @Final private static Logger LOGGER;
private float carpetMsptAccum = 0.0f;

/**
Expand Down Expand Up @@ -109,10 +118,13 @@ private void modifiedRunLoop(CallbackInfo ci)
this.lastTimeReference = this.timeReference;
}

if (needsDebugSetup) {
this.needsDebugSetup = false;
this.profilerTimings = Pair.of(Util.getMeasuringTimeNano(), ticks);
}

this.timeReference += msThisTick;//50L;
TickDurationMonitor monitor = TickDurationMonitor.create("Server");
startMonitor(monitor);
this.profiler.startTick();
startTickMetrics();
this.profiler.push("tick");
this.tick(TickSpeed.time_warp_start_time != 0 ? ()->true : this::shouldKeepTicking);
this.profiler.swap("nextTickWait");
Expand All @@ -121,14 +133,17 @@ private void modifiedRunLoop(CallbackInfo ci)
while(this.runEveryTask()) {Thread.yield();}
}
this.waitingForNextTick = true;
this.field_19248 = Math.max(Util.getMeasuringTimeMs() + /*50L*/ msThisTick, this.timeReference);
this.method_16208();
this.nextTickTimestamp = Math.max(Util.getMeasuringTimeMs() + /*50L*/ msThisTick, this.timeReference);
this.runTasksTillTickEnd();
this.profiler.pop();
this.profiler.endTick();
this.loading = true;
}
}

// just because profilerTimings class is public
Pair<Long,Integer> profilerTimings = null;

private boolean runEveryTask() {
if (super.runTask()) {
return true;
Expand Down
35 changes: 2 additions & 33 deletions src/main/java/carpet/mixins/PlayerManagerMixin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package carpet.mixins;

import com.mojang.authlib.GameProfile;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.ClientConnection;
import net.minecraft.text.TranslatableText;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand All @@ -15,14 +13,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import carpet.patches.NetHandlerPlayServerFake;
import carpet.patches.EntityPlayerMPFake;

import java.util.Iterator;
import java.util.List;
import java.util.UUID;

@Mixin(PlayerManager.class)
public abstract class PlayerManagerMixin
{
Expand All @@ -31,7 +24,7 @@ public abstract class PlayerManagerMixin
private MinecraftServer server;

@Inject(method = "loadPlayerData", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
private void fixStartingPos(ServerPlayerEntity serverPlayerEntity_1, CallbackInfoReturnable<CompoundTag> cir)
private void fixStartingPos(ServerPlayerEntity serverPlayerEntity_1, CallbackInfoReturnable<NbtCompound> cir)
{
if (serverPlayerEntity_1 instanceof EntityPlayerMPFake)
{
Expand All @@ -52,28 +45,4 @@ private ServerPlayNetworkHandler replaceNetworkHandler(MinecraftServer server, C
return new ServerPlayNetworkHandler(this.server, clientConnection, playerIn);
}
}

@Redirect(method = "createPlayer", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z"))
private boolean cancelWhileLoop(Iterator iterator)
{
return false;
}

@Inject(method = "createPlayer", at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Ljava/util/Iterator;hasNext()Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private void newWhileLoop(GameProfile gameProfile_1, CallbackInfoReturnable<ServerPlayerEntity> cir, UUID uUID_1,
List list_1, Iterator var5)
{
while (var5.hasNext())
{
ServerPlayerEntity serverPlayerEntity_3 = (ServerPlayerEntity) var5.next();
if(serverPlayerEntity_3 instanceof EntityPlayerMPFake)
{
serverPlayerEntity_3.kill();
continue;
}
serverPlayerEntity_3.networkHandler.disconnect(new TranslatableText("multiplayer.disconnect.duplicate_login"));
}
}

}
Loading

0 comments on commit 8666541

Please sign in to comment.