Skip to content

Commit

Permalink
Did anyone say gradle? and paperweight? potentially even mojmap?!
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Jun 11, 2021
1 parent 65dcb53 commit 211b20f
Show file tree
Hide file tree
Showing 13 changed files with 540 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ Paperclip.jar
paperclip.jar
paperclip-*.jar
paperclip.properties

!gradle/wrapper/gradle-wrapper.jar
24 changes: 24 additions & 0 deletions build-data/additional-spigot-member-mappings.csrg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CraftBukkit maps all of (mojmap names):
# Merchant.getLevel()
# Hopper.getLevel()
# Entity.getCommandSenderWorld()
# to getWorld(), which confuses our ability to map this method properly. This patch disambiguates it
net/minecraft/world/level/block/entity/IHopper v ()Lnet/minecraft/world/level/World; getLevel
net/minecraft/world/entity/vehicle/EntityMinecartHopper v ()Lnet/minecraft/world/level/World; getLevel
net/minecraft/world/item/trading/IMerchant eV ()Lnet/minecraft/world/level/World; getLevel
net/minecraft/world/entity/npc/EntityVillagerAbstract eV ()Lnet/minecraft/world/level/World; getLevel

# CraftBukkit mappings sometimes have mappings for child classes and not parent classes
# We handle this fine for deobf but this breaks reobf. These Patches fix those cases

# BossBattle -> BossBattleServer
net/minecraft/world/BossBattle a (F)V setProgress
net/minecraft/world/BossBattle c (Z)Lnet/minecraft/world/BossBattle; setCreateFog
net/minecraft/world/BossBattle a (Z)Lnet/minecraft/world/BossBattle; setDarkenSky
net/minecraft/world/BossBattle b (Z)Lnet/minecraft/world/BossBattle; setPlayMusic

# IChunkProvider -> ChunkProviderServer
net/minecraft/world/level/chunk/IChunkProvider b (II)Z isLoaded

# BehaviorWorkComposter -> BehaviorWork
net/minecraft/world/entity/ai/behavior/BehaviorWorkComposter a (Lnet/minecraft/server/level/WorldServer;Lnet/minecraft/world/entity/npc/EntityVillager;)V doWork
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- a/net/minecraft/world/entity/ai/behavior/BehaviorWorkComposter.patch
+++ b/net/minecraft/world/entity/ai/behavior/BehaviorWorkComposter.patch
@@ -1,14 +1,5 @@
--- a/net/minecraft/world/entity/ai/behavior/BehaviorWorkComposter.java
+++ b/net/minecraft/world/entity/ai/behavior/BehaviorWorkComposter.java
-@@ -24,7 +24,7 @@
- public BehaviorWorkComposter() {}
-
- @Override
-- protected void a(WorldServer worldserver, EntityVillager entityvillager) {
-+ protected void doWork(WorldServer worldserver, EntityVillager entityvillager) { // PAIL
- Optional<GlobalPos> optional = entityvillager.getBehaviorController().getMemory(MemoryModuleType.JOB_SITE);
-
- if (optional.isPresent()) {
@@ -43,7 +43,7 @@
BlockPosition blockposition = globalpos.getBlockPosition();

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--- a/net/minecraft/server/level/ChunkProviderServer.patch
+++ b/net/minecraft/server/level/ChunkProviderServer.patch
@@ -74,8 +74,8 @@
+ return playerchunk == null || playerchunk.oldTicketLevel > i; // CraftBukkit using oldTicketLevel for isLoaded checks
}

- public boolean isLoaded(int i, int j) {
-@@ -282,19 +308,19 @@
+ @Override
+@@ -283,19 +309,19 @@
public boolean a(Entity entity) {
long i = ChunkCoordIntPair.pair(MathHelper.floor(entity.locX()) >> 4, MathHelper.floor(entity.locZ()) >> 4);

@@ -98,7 +98,7 @@
}

private boolean a(long i, Function<PlayerChunk, CompletableFuture<Either<Chunk, PlayerChunk.Failure>>> function) {
-@@ -316,11 +342,31 @@
+@@ -317,11 +343,31 @@

@Override
public void close() throws IOException {
@@ -131,7 +131,7 @@
public void tick(BooleanSupplier booleansupplier) {
this.world.getMethodProfiler().enter("purge");
this.chunkMapDistance.purgeTickets();
-@@ -340,12 +386,12 @@
+@@ -341,12 +387,12 @@
this.lastTickTime = i;
WorldData worlddata = this.world.getWorldData();
boolean flag = this.world.isDebugWorld();
@@ -146,7 +146,7 @@

this.world.getMethodProfiler().enter("naturalSpawnCount");
int l = this.chunkMapDistance.b();
-@@ -532,12 +578,18 @@
+@@ -533,12 +579,18 @@

@Override
protected boolean executeNext() {
5 changes: 5 additions & 0 deletions build-data/library-imports.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
authlib com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java
datafixerupper com/mojang/datafixers/DataFixerBuilder.java
datafixerupper com/mojang/datafixers/util/Either.java
datafixerupper com/mojang/serialization/codecs/KeyDispatchCodec.java
datafixerupper com/mojang/serialization Dynamic.java
76 changes: 76 additions & 0 deletions build-data/mappings-patch.tiny
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
tiny 2 0 spigot mojang+yarn

# Originally DistanceManager, which also implements DistanceManager, so clashes since the implemented class
# is imported and not fully qualified. Easiest fix is to just change the name
c net/minecraft/server/level/PlayerChunkMap$a net/minecraft/server/level/ChunkMap$ChunkDistanceManager

# CraftBukkit adds the getServer() method, clashes with a Mojang method
c net/minecraft/world/level/World net/minecraft/world/level/Level
m ()Lorg/bukkit/craftbukkit/CraftServer; getServer getCraftServer

# CraftBukkit adds the server field, clashes with a Mojang field
c net/minecraft/server/network/PlayerConnection net/minecraft/server/network/ServerGamePacketListenerImpl
f Lorg/bukkit/craftbukkit/CraftServer; server craftServer

# CraftBukkit adds the player field, clashes with a Mojang field
c net/minecraft/world/inventory/ContainerWorkbench net/minecraft/world/inventory/CraftingMenu
f Lnet/minecraft/world/entity/player/PlayerInventory; player playerInventory

# CraftBukkit adds the getType() method, clashes with a Mojang method
c net/minecraft/world/entity/EntityAreaEffectCloud net/minecraft/world/entity/AreaEffectCloud
m ()Ljava/lang/String; getType getTypeCb

# CraftBukkit adds the getType() method, clashes with a Mojang method
c net/minecraft/world/entity/projectile/EntityTippedArrow net/minecraft/world/entity/projectile/Arrow
m ()Ljava/lang/String; getType getTypeCb

# CraftBukkit adds the getLevel() method, clashes with original method
c net/minecraft/world/level/block/entity/TileEntityBeacon net/minecraft/world/level/block/entity/BeaconBlockEntity
m ()I getLevel getLevelCb

# CraftBukkit adds the getLootTable() method, clashes with original method
c net/minecraft/world/entity/EntityInsentient net/minecraft/world/entity/Mob
m ()Lnet/minecraft/resources/MinecraftKey; getLootTable getLootTableCb

# CraftBukkit adds the canCollideWith() method, clashes with original method
c net/minecraft/world/entity/Entity net/minecraft/world/entity/Entity
m (Lnet/minecraft/world/entity/Entity;)Z canCollideWith canCollideWithCb

# CraftBukkit adds a new `a` method which allows passing the Entity parameter
# It uses `a` to match the original method (with just 1 param), so this patch makes them match
c net/minecraft/server/level/WorldServer net/minecraft/server/level/ServerLevel
m (Lnet/minecraft/server/level/WorldServer;Lnet/minecraft/world/entity/Entity;)V a makeObsidianPlatform

# CraftBukkit adds `getMinecraftWorld()` to `GeneratorAccess`, which matches `WorldAccess.getMinecraftWorld()`
# But that method in `WorldAccess` is called `getLevel()` in Mojang mappings
c net/minecraft/world/level/GeneratorAccess net/minecraft/world/level/LevelAccessor
m ()Lnet/minecraft/server/level/WorldServer; getMinecraftWorld getLevel

# SpecialSource2 automatically maps methods to the name of synthetic methods that point to it in an attempt to
# normalize method names with what is expected by the super class. This is _extremely_ stupid and flawed however
# because synthetic methods by definition have different descriptors than the base method, which means method
# signature clashes become possible, which is what happens here.
#
# LootEntryAbstract$Serializer has a synthetic method pointing to the base serialize() method with the following descriptor:
#
# (JsonObject,Object,JsonSerializationContext)V <-- ProGuard names this method `a`
#
# and this synthetic method points to another method with the specialized descriptor:
#
# (JsonObject,LootEntryAbstract,JsonSerializationContext)V <-- ProGuard names this method `b`
#
# SpecialSource2 automatically maps the second method name to the name of the first method, in this case `a`.
#
# LootEntryAbstract$Serializer also has another method with the same descriptor as serialize(), which Spigot calls
# serializeCustom(). Of course ProGuard strips the names and since this method is the first time it's seen this
# descriptor, it renamed that method also to `a`.
#
# This is allowed because the synthetic method for serialize() has a different descriptor, using Object as the second
# parameter. This breaks when SpecialSource2 does it's "magic" of course. This patch manually fixes this case by adding
# both correct mappings
c net/minecraft/world/level/storage/loot/entries/LootEntryAbstract$Serializer net/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer$Serializer
m (Lcom/google/gson/JsonObject;Lnet/minecraft/world/level/storage/loot/entries/LootEntryAbstract;Lcom/google/gson/JsonSerializationContext;)V a serialize
p 0 json
p 1 entry
p 2 context
m (Lcom/google/gson/JsonObject;Lnet/minecraft/world/level/storage/loot/entries/LootEntryAbstract;Lcom/google/gson/JsonSerializationContext;)V serializeType serializeCustom
83 changes: 83 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
plugins {
java
id("com.github.johnrengelman.shadow") version "7.0.0" apply false
id("io.papermc.paperweight") version "1.0.0-SNAPSHOT"
}

group = "com.destroystokyo.paper"
version = providers.gradleProperty("projectVersion").forUseAtConfigurationTime().get()

val mcVersion = providers.gradleProperty("mcVersion")
val packageVersion = providers.gradleProperty("packageVersion")

allprojects {
apply(plugin = "java")

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
}

subprojects {
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(16)
}

if (name == "Paper-MojangAPI") {
return@subprojects
}

repositories {
mavenCentral()
maven("https://repo1.maven.org/maven2/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://ci.emc.gs/nexus/content/groups/aikar/")
maven("https://repo.md-5.net/content/repositories/releases/")
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
}
}

repositories {
mavenLocal()

maven("https://wav.jfrog.io/artifactory/repo/") {
content {
onlyForConfigurations("paperclip")
}
}
maven("https://maven.quiltmc.org/repository/release/") {
content {
onlyForConfigurations("paramMappings", "remapper")
}
}
maven("https://files.minecraftforge.net/maven/") {
content {
onlyForConfigurations("decompiler")
}
}
}

dependencies {
paramMappings("org.quiltmc:yarn:1.16.5+build.6:mergedv2")
remapper("org.quiltmc:tiny-remapper:0.3.2:fat@jar")
decompiler("net.minecraftforge:forgeflower:1.5.498.5@jar")
paperclip("io.papermc:paperclip:2.0.0-SNAPSHOT@jar")
}

paperweight {
minecraftVersion.set(mcVersion)
versionPackage.set(packageVersion)
serverProject.set(project(":Paper-Server"))

paper {
mappingsPatch.set(file("build-data/mappings-patch.tiny"))

additionalSpigotMemberMappings.set(file("build-data/additional-spigot-member-mappings.csrg"))

craftBukkitPatchPatchesDir.set(file("build-data/craftbukkit-patch-patches"))
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mcVersion = 1.16
projectVersion = 1.17-R0.1-SNAPSHOT
packageVersion = 1_17_R1
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 211b20f

Please sign in to comment.