Skip to content

Commit

Permalink
Update ModPatcher dependency version. Patch WorldServer differently i…
Browse files Browse the repository at this point in the history
…f Sponge is present (it moved updateEntity/TE.update calls to WorldSErver not World)
  • Loading branch information
LunNova committed Jun 22, 2016
1 parent 49668ca commit f70e899
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
24 changes: 22 additions & 2 deletions src/main/java/nallar/tickprofiler/minecraft/CoreMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@IFMLLoadingPlugin.SortingIndex(1001)
public class CoreMod implements IFMLLoadingPlugin {
static {
ModPatcher.requireVersion("1.8.9.64");
ModPatcher.requireVersion("1.8.9.81");
}

@Override
Expand All @@ -28,9 +28,29 @@ public String getSetupClass() {
return ModPatcher.getSetupClass();
}

private Boolean spongePresent;

private boolean isSpongePresent() {
if (spongePresent == null) {
try {
Class.forName("org.spongepowered.asm.mixin.MixinEnvironment", false, CoreMod.class.getClassLoader());
spongePresent = true;
} catch (ClassNotFoundException e) {
spongePresent = false;
}
}

return spongePresent;
}

@Override
public void injectData(Map<String, Object> data) {
ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/profilinghook.xml"));
if (isSpongePresent())
ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/entityhook_sponge.xml"));
else
ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/entityhook.xml"));
// TODO: Not implemented
// ModPatcher.loadPatches(CoreMod.class.getResourceAsStream("/packethook.xml"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static String humanReadableName(String name) {
return name;
}

// called from profilinghook.xml
// called from packethook.xml
public static void record(final Packet packet, PacketBuffer buffer) {
if (!profiling) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,5 @@
updateEntities_withProfiling
</replaceMethodCall>
</class>
<!-- TODO: update packet profiling for 1.8.9
<class id="net.minecraft.util.MessageSerializer">
<replaceMethodCall method="^method:Packet/writePacketData^"
code="$_ = $0.^method:Packet/writePacketData^($1); nallar.tickprofiler.minecraft.profiling.PacketProfiler.record($0, $1);">
encode
</replaceMethodCall>
<insertCodeBefore code="nallar.tickprofiler.minecraft.TickProfiler.handlePacket($1);">
scheduleOutboundPacket
</insertCodeBefore>
</class>
-->
</minecraft>
</patchGroups>
19 changes: 19 additions & 0 deletions src/main/resources/entityhook_sponge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<patchGroups>
<minecraft>
<class id="net.minecraft.world.WorldServer">
<clone to="updateEntities_withProfiling">updateEntities</clone>
<insertCodeBefore
code="if (nallar.tickprofiler.minecraft.TickProfiler.shouldProfile(this)) { updateEntities_withProfiling(); return; }">
updateEntities
</insertCodeBefore>
<replaceMethodCall method="^method:ITickable/update^"
code="nallar.tickprofiler.minecraft.profiling.EntityTickProfiler.INSTANCE.profileTickable($0);">
updateEntities_withProfiling
</replaceMethodCall>
<replaceMethodCall method="^method:World/updateEntity^"
code="nallar.tickprofiler.minecraft.profiling.EntityTickProfiler.INSTANCE.profileEntity(this, $1);">
updateEntities_withProfiling
</replaceMethodCall>
</class>
</minecraft>
</patchGroups>
15 changes: 15 additions & 0 deletions src/main/resources/packethook.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<patchGroups>
<minecraft>
<!-- TODO: update packet profiling for 1.8.9
<class id="net.minecraft.util.MessageSerializer">
<replaceMethodCall method="^method:Packet/writePacketData^"
code="$_ = $0.^method:Packet/writePacketData^($1); nallar.tickprofiler.minecraft.profiling.PacketProfiler.record($0, $1);">
encode
</replaceMethodCall>
<insertCodeBefore code="nallar.tickprofiler.minecraft.TickProfiler.handlePacket($1);">
scheduleOutboundPacket
</insertCodeBefore>
</class>
-->
</minecraft>
</patchGroups>

0 comments on commit f70e899

Please sign in to comment.