Skip to content

Commit

Permalink
new: check wither visibility before spawning particles
Browse files Browse the repository at this point in the history
  • Loading branch information
asbyth committed Nov 9, 2020
1 parent 8b8693c commit 823523e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/main/java/club/sk1er/patcher/Patcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,27 +306,21 @@ public void connectToServer(FMLNetworkEvent.ClientConnectedToServerEvent event)
return;
}

String serverIP = Minecraft.getMinecraft().getCurrentServerData().serverIP;
final String serverIP = Minecraft.getMinecraft().getCurrentServerData().serverIP;
if (blacklistedServers.contains(serverIP)) {
logger.info("Current server supports 1.11+, but doesn't allow for 1.8.9 to use a high chat length, setting to 100.");
GuiChatTransformer.maxChatLength = 100;
return;
}

CompletableFuture<Boolean> future = ProtocolDetector.instance.isCompatibleWithVersion(
final CompletableFuture<Boolean> future = ProtocolDetector.instance.isCompatibleWithVersion(
serverIP,
315 // 1.11
);

Multithreading.runAsync(() -> {
try {
if (future.get()) {
logger.info("Server supports 1.11+, setting string length to 256.");
GuiChatTransformer.maxChatLength = 256;
} else {
logger.info("Server doesn't support 1.11+, setting string length to 100.");
GuiChatTransformer.maxChatLength = 100;
}
GuiChatTransformer.maxChatLength = future.get() ? 256 : 100;
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/club/sk1er/patcher/config/PatcherConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ public class PatcherConfig extends Vigilant {
public static boolean futureHitBoxes = true;

@Property(
type = PropertyType.SWITCH, name = "Clean Text Shadow",
type = PropertyType.SWITCH, name = "Alternate Text Shadow",
description = "Change the text shadow to only move down rather than moving to the side.",
category = "Miscellaneous", subcategory = "Rendering"
)
public static boolean cleanTextShadow;
public static boolean alternateTextShadow;

@Property(
type = PropertyType.SWITCH, name = "Add Text Shadow to Nametags",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import club.sk1er.patcher.tweaker.asm.lwjgl.WindowsDisplayTransformer;
import club.sk1er.patcher.tweaker.asm.lwjgl.WindowsKeycodesTransformer;
import club.sk1er.patcher.tweaker.asm.optifine.InventoryPlayerTransformer;
import club.sk1er.patcher.tweaker.asm.optifine.witherfix.EntityWitherTransformer;
import club.sk1er.patcher.tweaker.asm.util.ForcePublicTransformer;
import club.sk1er.patcher.tweaker.transform.PatcherTransformer;
import com.google.common.collect.ArrayListMultimap;
Expand Down Expand Up @@ -302,6 +303,7 @@ public ClassTransformer() {
registerTransformer(new ArmorStandRendererTransformer());
registerTransformer(new BlockFluidRendererTransformer());
registerTransformer(new GuiOptionsTransformer());
registerTransformer(new EntityWitherTransformer());

// forge classes
registerTransformer(new ClientCommandHandlerTransformer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

package club.sk1er.patcher.tweaker.asm;

import club.sk1er.patcher.config.PatcherConfig;
import club.sk1er.patcher.tweaker.transform.PatcherTransformer;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
Expand Down Expand Up @@ -83,7 +82,7 @@ public void transform(ClassNode classNode, String name) {

private InsnList insertCleanShadowLabel() {
final InsnList list = new InsnList();
list.add(new FieldInsnNode(Opcodes.GETSTATIC, getPatcherConfigClass(), "cleanTextShadow", "Z"));
list.add(new FieldInsnNode(Opcodes.GETSTATIC, getPatcherConfigClass(), "alternateTextShadow", "Z"));
final LabelNode ifeq = new LabelNode();
list.add(new JumpInsnNode(Opcodes.IFEQ, ifeq));
list.add(new VarInsnNode(Opcodes.FLOAD, 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package club.sk1er.patcher.tweaker.asm.optifine.witherfix;

import club.sk1er.patcher.tweaker.transform.PatcherTransformer;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;

import java.util.ListIterator;

public class EntityWitherTransformer implements PatcherTransformer {
@Override
public String[] getClassName() {
return new String[]{"net.minecraft.entity.boss.EntityWither"};
}

@Override
public void transform(ClassNode classNode, String name) {
for (MethodNode method : classNode.methods) {
final String methodName = mapMethodName(classNode, method);

if (methodName.equals("onLivingUpdate") || methodName.equals("func_70636_d")) {
final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();

while (iterator.hasNext()) {
final AbstractInsnNode next = iterator.next();

if (next instanceof MethodInsnNode && next.getOpcode() == Opcodes.INVOKEVIRTUAL) {
final String methodInsnName = mapMethodNameFromNode(next);

if ((methodInsnName.equals("isArmored") || methodInsnName.equals("func_82205_o")) && next.getNext().getOpcode() == Opcodes.ISTORE) {
method.instructions.insertBefore(next.getNext().getNext(), checkVisibility());
break;
}
}
}

break;
}
}
}

private InsnList checkVisibility() {
InsnList list = new InsnList();
list.add(new VarInsnNode(Opcodes.ALOAD, 0));
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/boss/EntityWither", "func_82150_aj", "()Z", false));
LabelNode ifeq = new LabelNode();
list.add(new JumpInsnNode(Opcodes.IFEQ, ifeq));
list.add(new InsnNode(Opcodes.RETURN));
list.add(ifeq);
return list;
}
}

0 comments on commit 823523e

Please sign in to comment.