recipe-nope/src/main/java/dev/pfaff/recipe_nope/mixin/UnlockRecipesS2CPacketMixin...

66 lines
3.1 KiB
Java

package dev.pfaff.recipe_nope.mixin;
import com.google.common.collect.ImmutableList;
import dev.pfaff.recipe_nope.RecipeNope;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.s2c.play.UnlockRecipesS2CPacket;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.book.RecipeBookOptions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
@Mixin(UnlockRecipesS2CPacket.class)
public abstract class UnlockRecipesS2CPacketMixin {
@Inject(method = "<init>(Lnet/minecraft/network/packet/s2c/play/UnlockRecipesS2CPacket$Action;Ljava/util/Collection;Ljava/util/Collection;Lnet/minecraft/recipe/book/RecipeBookOptions;)V", at = @At(value = "INVOKE", target = "Ljava/lang/Object;<init>()V", shift = At.Shift.AFTER))
private void init$noWrite(UnlockRecipesS2CPacket.Action action,
Collection recipeIdsToChange,
Collection recipeIdsToInit,
RecipeBookOptions options,
CallbackInfo ci) {
throw RecipeNope.unsupported();
}
//@Redirect(method = "<init>(Lnet/minecraft/network/packet/s2c/play/UnlockRecipesS2CPacket$Action;Ljava/util/Collection;Ljava/util/Collection;Lnet/minecraft/recipe/book/RecipeBookOptions;)V", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;"))
//private <E> ImmutableList<E> init$skip(Collection<? extends E> list) {
// return null;
//}
@Redirect(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readEnumConstant(Ljava/lang/Class;)Ljava/lang/Enum;"))
private <T extends Enum<T>> T init$skipReadAction(PacketByteBuf instance, Class<T> enumClass) {
return null;
}
@Redirect(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/book/RecipeBookOptions;fromPacket(Lnet/minecraft/network/PacketByteBuf;)Lnet/minecraft/recipe/book/RecipeBookOptions;"))
private RecipeBookOptions init$skipReadOptions(PacketByteBuf buf) {
return null;
}
@Redirect(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readList(Ljava/util/function/Function;)Ljava/util/List;"))
private <T> List<T> init$skipReadList(PacketByteBuf instance, Function<PacketByteBuf, T> entryParser) {
return null;
}
@Inject(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At(value = "TAIL"))
private void init$noRead(PacketByteBuf buf, CallbackInfo ci) {
buf.readerIndex(buf.writerIndex());
}
@Overwrite
public void write(PacketByteBuf buf) {
throw RecipeNope.unsupported();
}
@Overwrite
public void apply(ClientPlayPacketListener clientPlayPacketListener) {
}
}