mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-01-25 22:11:32 +01:00
added support for negative items in <= 1.10
This commit is contained in:
parent
2241052a90
commit
3b6ae50436
@ -17,7 +17,11 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.settings.groups.VisualSettings;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.ItemModels;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
@ -25,11 +29,13 @@ import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.world.World;
|
||||
import org.joml.Matrix4f;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ItemRenderer.class)
|
||||
@ -43,4 +49,11 @@ public class MixinItemRenderer {
|
||||
cir.setReturnValue(this.models.getModelManager().getMissingModel());
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "renderGuiItemOverlay(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Ljava/lang/String;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I"))
|
||||
public int recolor(TextRenderer instance, String text, float x, float y, int color, boolean shadow, Matrix4f matrix, VertexConsumerProvider vertexConsumers, TextRenderer.TextLayerType layerType, int backgroundColor, int light) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_10) && text.startsWith("-")) color = -43213;
|
||||
return instance.draw(text, x, y, color, shadow, matrix, vertexConsumers, layerType, backgroundColor, light);
|
||||
}
|
||||
}
|
||||
|
@ -28,20 +28,43 @@ import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.*;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
@SuppressWarnings("ConstantValue")
|
||||
@Mixin(value = ItemStack.class, priority = 1)
|
||||
public abstract class MixinItemStack {
|
||||
|
||||
@Shadow
|
||||
public abstract Item getItem();
|
||||
|
||||
@Shadow @Final public static ItemStack EMPTY;
|
||||
|
||||
@Shadow private int count;
|
||||
|
||||
@Shadow private boolean empty;
|
||||
|
||||
@Inject(method = "updateEmptyState", at = @At("HEAD"), cancellable = true)
|
||||
public void allowNegativeItems(CallbackInfo ci) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_10)) {
|
||||
this.empty = false;
|
||||
final ItemStack self = (ItemStack) (Object) this;
|
||||
this.empty = self == EMPTY || this.getItem() == null || self.isOf(Items.AIR) && count != 0;
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "isEmpty", at = @At("HEAD"), cancellable = true)
|
||||
public void dontRecalculateState(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_10)) {
|
||||
cir.setReturnValue(this.empty);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getMiningSpeedMultiplier", at = @At("RETURN"), cancellable = true)
|
||||
private void modifyMiningSpeedMultiplier(BlockState state, CallbackInfoReturnable<Float> ci) {
|
||||
final Item toolItem = ((ItemStack) (Object) this).getItem();
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion.protocol1_11to1_10;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(value = EntityIdRewriter.class, remap = false)
|
||||
public class MixinEntityIdRewriter {
|
||||
|
||||
@Redirect(method = "toClientItem(Lcom/viaversion/viaversion/api/minecraft/item/Item;Z)V", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/minecraft/item/Item;setAmount(I)V"))
|
||||
private static void allowNegativeItems(Item instance, int i) {
|
||||
}
|
||||
}
|
@ -131,6 +131,7 @@
|
||||
"fixes.viaversion.MixinCommonBoss",
|
||||
"fixes.viaversion.MixinNBTType",
|
||||
"fixes.viaversion.MixinProtocolVersion",
|
||||
"fixes.viaversion.protocol1_11to1_10.MixinEntityIdRewriter",
|
||||
"fixes.viaversion.protocol1_11to1_10.MixinProtocol1_11To1_10",
|
||||
"fixes.viaversion.protocol1_12to1_11_1.MixinChatItemRewriter",
|
||||
"fixes.viaversion.protocol1_13to1_12_2.MixinAbstractFenceConnectionHandler",
|
||||
|
Loading…
Reference in New Issue
Block a user