Replace MixinItemRenderer by the new 1.17 vanilla API. Fixes #2602

This commit is contained in:
modmuss50 2021-11-26 21:06:45 +00:00
parent f500b5ddff
commit 8b24b8439a
16 changed files with 72 additions and 204 deletions

View file

@ -1,43 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.util;
import net.minecraft.item.ItemStack;
public interface ItemDurabilityExtensions {
default double getDurability(ItemStack stack) {
return 0;
}
default boolean showDurability(ItemStack stack) {
return false;
}
default int getDurabilityColor(ItemStack stack) {
return 0;
}
}

View file

@ -108,12 +108,16 @@ public class ItemUtils {
return ItemStack.fromNbt(data);
}
public static double getPowerForDurabilityBar(ItemStack stack) {
public static int getPowerForDurabilityBar(ItemStack stack) {
if (!(stack.getItem() instanceof RcEnergyItem energyItem)) {
return 0.0;
throw new UnsupportedOperationException();
}
return (double) energyItem.getStoredEnergy(stack) / energyItem.getEnergyCapacity();
return Math.round((energyItem.getStoredEnergy(stack) * 100f / energyItem.getEnergyCapacity()) * 13) / 100;
}
public static int getColorForDurabilityBar(ItemStack stack) {
return 0xff8006;
}
/**

View file

@ -1,75 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.mixin.client;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;
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.callback.CallbackInfo;
import reborncore.common.util.ItemDurabilityExtensions;
//Not too happy with this, need to find and get a better solution into fabric soon
@Mixin(ItemRenderer.class)
public abstract class MixinItemRenderer {
@Shadow
protected abstract void renderGuiQuad(BufferBuilder bufferBuilder_1, int int_1, int int_2, int int_3, int int_4, int int_5, int int_6, int int_7, int int_8);
@Inject(method = "renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At("HEAD"))
private void renderGuiItemOverlay(TextRenderer textRenderer, ItemStack stack, int x, int y, @Nullable String string, CallbackInfo info) {
if (stack.getItem() instanceof ItemDurabilityExtensions durabilityExtensions) {
if (!durabilityExtensions.showDurability(stack)) {
return;
}
RenderSystem.disableDepthTest();
RenderSystem.disableTexture();
//RenderSystem.disableAlphaTest(); FIXME 1.17
RenderSystem.disableBlend();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
int durability = (int) (13 * (1 - Math.max(0.0F, durabilityExtensions.getDurability(stack))));
int color = durabilityExtensions.getDurabilityColor(stack);
this.renderGuiQuad(bufferBuilder, x + 2, y + 13, 13, 2, 0, 0, 0, 255);
this.renderGuiQuad(bufferBuilder, x + 2, y + 13, durability, 1, color >> 16 & 255, color >> 8 & 255, color & 255, 255);
RenderSystem.enableBlend();
//RenderSystem.enableAlphaTest();
RenderSystem.enableTexture();
RenderSystem.enableDepthTest();
}
}
}

View file

@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_16",
"client": [
"MixinGameRenderer",
"MixinItemRenderer",
"MixinDebugRenderer",
"AccessorModelPredicateProviderRegistry",
"AccessorChatHud",

View file

@ -42,7 +42,6 @@ import org.jetbrains.annotations.Nullable;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
@ -50,7 +49,7 @@ import techreborn.utils.MessageIDs;
import java.util.List;
public class BatteryItem extends Item implements RcEnergyItem, ItemDurabilityExtensions {
public class BatteryItem extends Item implements RcEnergyItem {
private final int maxEnergy;
private final RcEnergyTier tier;
@ -113,17 +112,17 @@ public class BatteryItem extends Item implements RcEnergyItem, ItemDurabilityExt
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
}

View file

@ -38,12 +38,11 @@ import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
public class BatpackItem extends ArmorItem implements RcEnergyItem, ItemDurabilityExtensions {
public class BatpackItem extends ArmorItem implements RcEnergyItem {
public final int maxCharge;
public final RcEnergyTier tier;
@ -95,19 +94,18 @@ public class BatpackItem extends ArmorItem implements RcEnergyItem, ItemDurabili
return tier;
}
// ItemDurabilityExtensions
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
}

View file

@ -61,12 +61,12 @@ public class CloakingDeviceItem extends TRArmourItem implements RcEnergyItem, Ar
// ItemTRArmour
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@ -76,8 +76,8 @@ public class CloakingDeviceItem extends TRArmourItem implements RcEnergyItem, Ar
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// Item

View file

@ -143,12 +143,12 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
}
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@ -158,8 +158,8 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
@Override

View file

@ -28,7 +28,6 @@ import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Item;
import reborncore.common.util.ItemDurabilityExtensions;
import techreborn.TechReborn;
import java.util.UUID;
@ -36,7 +35,7 @@ import java.util.UUID;
/**
* Created by modmuss50 on 26/02/2016.
*/
public class TRArmourItem extends ArmorItem implements ItemDurabilityExtensions {
public class TRArmourItem extends ArmorItem {
//Thanks for being private
public static final UUID[] MODIFIERS = new UUID[]{

View file

@ -36,14 +36,13 @@ import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
import java.util.Random;
public class ChainsawItem extends AxeItem implements RcEnergyItem, ItemDurabilityExtensions {
public class ChainsawItem extends AxeItem implements RcEnergyItem {
public final int maxCharge;
public final int cost;
@ -118,20 +117,19 @@ public class ChainsawItem extends AxeItem implements RcEnergyItem, ItemDurabilit
return referenceTool.isSuitableFor(state);
}
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// EnergyHolder

View file

@ -38,12 +38,11 @@ import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
public class DrillItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions, DynamicAttributeTool {
public class DrillItem extends PickaxeItem implements RcEnergyItem, DynamicAttributeTool {
public final int maxCharge;
public final int cost;
@ -133,20 +132,19 @@ public class DrillItem extends PickaxeItem implements RcEnergyItem, ItemDurabili
InitUtils.initPoweredItems(this, stacks);
}
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// EnergyHolder

View file

@ -39,7 +39,6 @@ import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.utils.InitUtils;
@ -47,7 +46,7 @@ import techreborn.utils.ToolsUtil;
import java.util.Random;
public class JackhammerItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions, DynamicAttributeTool {
public class JackhammerItem extends PickaxeItem implements RcEnergyItem, DynamicAttributeTool {
public final int maxCharge;
public final RcEnergyTier tier;
@ -144,20 +143,19 @@ public class JackhammerItem extends PickaxeItem implements RcEnergyItem, ItemDur
return 0;
}
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// DynamicAttributeTool

View file

@ -33,7 +33,6 @@ import net.minecraft.util.collection.DefaultedList;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import techreborn.TechReborn;
import techreborn.config.TechRebornConfig;
@ -42,7 +41,7 @@ import techreborn.utils.InitUtils;
/**
* Created by modmuss50 on 05/11/2016.
*/
public class ElectricTreetapItem extends Item implements RcEnergyItem, ItemDurabilityExtensions {
public class ElectricTreetapItem extends Item implements RcEnergyItem {
public final int maxCharge = TechRebornConfig.electricTreetapCharge;
public int cost = TechRebornConfig.electricTreetapCost;
@ -67,20 +66,19 @@ public class ElectricTreetapItem extends Item implements RcEnergyItem, ItemDurab
InitUtils.initPoweredItems(this, stacks);
}
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// EnergyHolder

View file

@ -37,7 +37,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
@ -46,7 +45,7 @@ import techreborn.init.TRContent;
import java.util.Random;
public class RockCutterItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions {
public class RockCutterItem extends PickaxeItem implements RcEnergyItem {
public static final int maxCharge = TechRebornConfig.rockCutterCharge;
public int cost = TechRebornConfig.rockCutterCost;
@ -129,18 +128,18 @@ public class RockCutterItem extends PickaxeItem implements RcEnergyItem, ItemDur
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// EnergyHolder

View file

@ -47,7 +47,6 @@ import org.jetbrains.annotations.Nullable;
import reborncore.api.items.ItemStackModifiers;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import reborncore.common.powerSystem.RcEnergyTier;
import techreborn.TechReborn;
@ -57,7 +56,7 @@ import techreborn.utils.MessageIDs;
import java.util.List;
public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemDurabilityExtensions, ItemStackModifiers {
public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemStackModifiers {
public static final int maxCharge = TechRebornConfig.nanosaberCharge;
public int cost = TechRebornConfig.nanosaberCost;
@ -152,20 +151,19 @@ public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemDurabi
return 0;
}
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// ItemStackModifiers

View file

@ -46,7 +46,6 @@ import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.RcEnergyItem;
import reborncore.common.util.ItemDurabilityExtensions;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.TorchHelper;
import reborncore.common.powerSystem.RcEnergyTier;
@ -58,7 +57,7 @@ import techreborn.utils.InitUtils;
import java.util.List;
public class OmniToolItem extends PickaxeItem implements RcEnergyItem, ItemDurabilityExtensions, DynamicAttributeTool {
public class OmniToolItem extends PickaxeItem implements RcEnergyItem, DynamicAttributeTool {
public final int maxCharge = TechRebornConfig.omniToolCharge;
public int cost = TechRebornConfig.omniToolCost;
@ -139,20 +138,19 @@ public class OmniToolItem extends PickaxeItem implements RcEnergyItem, ItemDurab
tooltip.add(new LiteralText(Formatting.YELLOW + I18n.translate("techreborn.tooltip.omnitool_motto")));
}
// ItemDurabilityExtensions
@Override
public double getDurability(ItemStack stack) {
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
public int getItemBarStep(ItemStack stack) {
return ItemUtils.getPowerForDurabilityBar(stack);
}
@Override
public boolean showDurability(ItemStack stack) {
public boolean isItemBarVisible(ItemStack stack) {
return true;
}
@Override
public int getDurabilityColor(ItemStack stack) {
return PowerSystem.getDisplayPower().colour;
public int getItemBarColor(ItemStack stack) {
return ItemUtils.getColorForDurabilityBar(stack);
}
// EnergyHolder