Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Add support for Crowdin-Translate, and for Colytra (see issue 45)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbl committed Nov 1, 2020
1 parent 3707794 commit a879a93
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Versionfiles
24 changes: 21 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
buildscript {
dependencies {
classpath 'de.guntram.mcmod:crowdin-translate:1.2'
}
repositories {
maven {
name = 'CrowdinTranslate source'
url = "https://minecraft.guntram.de/maven/"
}
}
}
plugins {
id 'fabric-loom' version '0.4-SNAPSHOT'
}
apply plugin: 'de.guntram.mcmod.crowdin-translate'
crowdintranslate.crowdinProjectName = 'durabilityviewer'
crowdintranslate.verbose = false

repositories {
maven {
Expand Down Expand Up @@ -28,7 +42,7 @@ ext.Versions = new Properties()
Versions.load(file("Versionfiles/mcversion-1.16.2.properties").newReader())

archivesBaseName = "durabilityviewer"
ext.projectVersion = "1.8.7"
ext.projectVersion = "1.9"

version = "${Versions['minecraft_version']}-fabric${Versions['fabric_versiononly']}-${project.projectVersion}"

Expand All @@ -55,8 +69,8 @@ dependencies {
modCompile "net.fabricmc.fabric-api:fabric-api:${Versions['fabric_version']}"
modCompile "TechReborn:TechReborn-1.16:3.4.5+build.95"
modCompile "io.github.prospector:modmenu:${Versions['modmenu_version']}"
// modImplementation "de.guntram.mcmod:crowdin-translate:1.0"
// include "de.guntram.mcmod:crowdin-translate:1.0"
modImplementation "de.guntram.mcmod:crowdin-translate:1.2"
include "de.guntram.mcmod:crowdin-translate:1.2"

modCompile "de.guntram.mcmod:GBfabrictools:${Versions['gbfabrictools_version']}"
include "de.guntram.mcmod:GBfabrictools:${Versions['gbfabrictools_version']}"
Expand All @@ -75,3 +89,7 @@ task sourcesJar(type: Jar, dependsOn: classes) {
jar {
from "LICENSE"
}

build {
dependsOn downloadTranslations
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.guntram.mcmod.durabilityviewer;

// import de.guntram.mcmod.crowdintranslate.CrowdinTranslate;
import de.guntram.mcmod.crowdintranslate.CrowdinTranslate;
import de.guntram.mcmod.durabilityviewer.client.gui.GuiItemDurability;
import de.guntram.mcmod.durabilityviewer.handler.ConfigurationHandler;
import de.guntram.mcmod.fabrictools.ConfigurationProvider;
Expand All @@ -16,7 +16,6 @@ public class DurabilityViewer implements ClientModInitializer
{
public static final String MODID = "durabilityviewer";
public static final String MODNAME = "Durability Viewer";
public static final String VERSION = "1.16-20w10a-fabric0.5.1-1.7";

public static DurabilityViewer instance;
private static ConfigurationHandler confHandler;
Expand All @@ -25,7 +24,7 @@ public class DurabilityViewer implements ClientModInitializer

@Override
public void onInitializeClient() {
// CrowdinTranslate.downloadTranslations(MODID, MODID, true);
CrowdinTranslate.downloadTranslations(MODID, MODID, true);
setKeyBindings();
confHandler=ConfigurationHandler.getInstance();
ConfigurationProvider.register(MODNAME, confHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.google.common.collect.Ordering;
import com.mojang.blaze3d.platform.GlStateManager;
import de.guntram.mcmod.durabilityviewer.handler.ConfigurationHandler;
import de.guntram.mcmod.durabilityviewer.itemindicator.ColytraDamageIndicator;
import de.guntram.mcmod.durabilityviewer.itemindicator.InventorySlotsIndicator;
import de.guntram.mcmod.durabilityviewer.itemindicator.ItemCountIndicator;
import de.guntram.mcmod.durabilityviewer.itemindicator.ItemDamageIndicator;
import de.guntram.mcmod.durabilityviewer.itemindicator.ItemIndicator;
import de.guntram.mcmod.durabilityviewer.itemindicator.TREnergyIndicator;
import de.guntram.mcmod.durabilityviewer.sound.ColytraBreakingWarner;
import de.guntram.mcmod.durabilityviewer.sound.ItemBreakingWarner;
import dev.emi.trinkets.api.TrinketsApi;
import java.util.Collection;
Expand Down Expand Up @@ -47,6 +49,7 @@ public class GuiItemDurability
private static boolean haveTRCore = false;

private ItemBreakingWarner mainHandWarner, offHandWarner, helmetWarner, chestWarner, pantsWarner, bootsWarner;
private ItemBreakingWarner colytraWarner;
private ItemBreakingWarner trinketWarners[];

public static void toggleVisibility() {
Expand All @@ -65,6 +68,7 @@ public GuiItemDurability() {
chestWarner=new ItemBreakingWarner();
pantsWarner=new ItemBreakingWarner();
bootsWarner=new ItemBreakingWarner();
colytraWarner=new ColytraBreakingWarner();

try {
Class.forName("dev.emi.trinkets.api.TrinketsApi");
Expand Down Expand Up @@ -141,13 +145,20 @@ public void onRenderGameOverlayPost(MatrixStack stack, float partialTicks) {
PlayerEntity player = (PlayerEntity) minecraft.player;
boolean needToWarn=false;

// @TODO: remove duplicate code

ItemIndicator mainHand, offHand;
mainHand = damageOrEnergy(player, EquipmentSlot.MAINHAND);
offHand = damageOrEnergy(player, EquipmentSlot.OFFHAND);

ItemStack chestItem = player.getEquippedStack(EquipmentSlot.CHEST);
ItemIndicator colytra = null;
if (chestItem != null && chestItem.getTag()!= null && chestItem.getTag().contains("colytra:ElytraUpgrade")) {
colytra = new ColytraDamageIndicator(chestItem);
}

ItemIndicator boots = new ItemDamageIndicator(player.getEquippedStack(EquipmentSlot.FEET));
ItemIndicator leggings = new ItemDamageIndicator(player.getEquippedStack(EquipmentSlot.LEGS));
ItemIndicator chestplate = new ItemDamageIndicator(player.getEquippedStack(EquipmentSlot.CHEST));
ItemIndicator chestplate = new ItemDamageIndicator(chestItem);
ItemIndicator helmet = new ItemDamageIndicator(player.getEquippedStack(EquipmentSlot.HEAD));
ItemIndicator arrows = null;
ItemIndicator invSlots = (ConfigurationHandler.getShowChestIcon() ? new InventorySlotsIndicator(minecraft.player.inventory) : null);
Expand All @@ -169,8 +180,9 @@ public void onRenderGameOverlayPost(MatrixStack stack, float partialTicks) {
needToWarn|=offHandWarner.checkBreaks(player.getEquippedStack(EquipmentSlot.OFFHAND));
needToWarn|=bootsWarner.checkBreaks(player.getEquippedStack(EquipmentSlot.FEET));
needToWarn|=pantsWarner.checkBreaks(player.getEquippedStack(EquipmentSlot.LEGS));
needToWarn|=chestWarner.checkBreaks(player.getEquippedStack(EquipmentSlot.CHEST));
needToWarn|=chestWarner.checkBreaks(chestItem);
needToWarn|=helmetWarner.checkBreaks(player.getEquippedStack(EquipmentSlot.HEAD));
needToWarn|=colytraWarner.checkBreaks(chestItem);
if (haveTrinketsApi) {
Inventory inventory = TrinketsApi.getTrinketsInventory(player);
LOGGER.debug("know about "+trinkets.length+" trinkets, invSize is "+inventory.size()+", have "+trinketWarners.length+" warners");
Expand All @@ -191,7 +203,7 @@ public void onRenderGameOverlayPost(MatrixStack stack, float partialTicks) {
if (ConfigurationHandler.getArmorAroundHotbar()) {
armorSize = new RenderSize(0, 0);
} else {
armorSize=this.renderItems(stack, 0, 0, false, RenderPos.left, 0, boots, leggings, chestplate, helmet);
armorSize=this.renderItems(stack, 0, 0, false, RenderPos.left, 0, boots, leggings, colytra, chestplate, helmet);
}
toolsSize=this.renderItems(stack, 0, 0, false, RenderPos.right, 0, invSlots, mainHand, offHand, arrows);
trinketsSize = this.renderItems(stack, 0, 0, false, RenderPos.left, 0, trinkets);
Expand Down Expand Up @@ -248,6 +260,10 @@ public void onRenderGameOverlayPost(MatrixStack stack, float partialTicks) {
int chestTextWidth = fontRenderer.getWidth(chestplate.getDisplayValue());
this.renderItems(stack, mainWindow.getScaledWidth()/2+leftOffset - helmetTextWidth, mainWindow.getScaledHeight()-iconHeight*2-2, true, RenderPos.left, helmetTextWidth+iconWidth+spacing, helmet);
this.renderItems(stack, mainWindow.getScaledWidth()/2+leftOffset - chestTextWidth, mainWindow.getScaledHeight()-iconHeight-2, true, RenderPos.left, chestTextWidth+iconWidth+spacing, chestplate);
if (colytra != null) {
int colytraTextWidth = fontRenderer.getWidth(colytra.getDisplayValue());
this.renderItems(stack, mainWindow.getScaledWidth()/2+leftOffset - chestTextWidth - colytraTextWidth - iconWidth, mainWindow.getScaledHeight()-iconHeight-2, true, RenderPos.left, colytraTextWidth+iconWidth+spacing, colytra);
}
this.renderItems(stack, mainWindow.getScaledWidth()/2+rightOffset, mainWindow.getScaledHeight()-iconHeight*2-2, true, RenderPos.right, armorSize.width, leggings);
this.renderItems(stack, mainWindow.getScaledWidth()/2+rightOffset, mainWindow.getScaledHeight()-iconHeight-2, true, RenderPos.right, armorSize.width, boots);
if (ConfigurationHandler.getCorner().isRight()) {
Expand All @@ -256,7 +272,7 @@ public void onRenderGameOverlayPost(MatrixStack stack, float partialTicks) {
xposTools -= armorSize.width;
}
} else {
this.renderItems(stack, xposArmor, ypos, true, ConfigurationHandler.getCorner().isLeft() ? RenderPos.left : RenderPos.right, armorSize.width, helmet, chestplate, leggings, boots);
this.renderItems(stack, xposArmor, ypos, true, ConfigurationHandler.getCorner().isLeft() ? RenderPos.left : RenderPos.right, armorSize.width, helmet, chestplate, colytra, leggings, boots);
}
this.renderItems(stack, xposTools, ypos, true, ConfigurationHandler.getCorner().isRight() ? RenderPos.right : RenderPos.left, toolsSize.width, invSlots, mainHand, offHand, arrows);
this.renderItems(stack, xposTrinkets, ypos, true, ConfigurationHandler.getCorner().isRight() ? RenderPos.right : RenderPos.left, trinketsSize.width, trinkets);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package de.guntram.mcmod.durabilityviewer.itemindicator;

import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

/**
*
* @author gbl
*/
public class ColytraDamageIndicator extends ItemDamageIndicator {

private static int elytraMaxDamage;
private static ItemStack newElytra;

public ColytraDamageIndicator(ItemStack chestItem) {
super(chestItem);
if (elytraMaxDamage == 0) {
newElytra = new ItemStack(Items.ELYTRA);
elytraMaxDamage = newElytra.getMaxDamage();
}
}

private int getDamage() {
int damage;
try {
damage = stack.getTag().getCompound("colytra:ElytraUpgrade").getCompound("tag").getInt("Damage");
return damage;
} catch (Exception ex) {
return 0;
}
}

@Override
public String getDisplayValue() {
return calculateDisplayValue(elytraMaxDamage, getDamage());
}

@Override
public int getDisplayColor() {
return calculateDisplayColor(elytraMaxDamage, getDamage());
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean isItemStackDamageable() {
return true;
}

@Override
public ItemStack getItemStack() {
return newElytra;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ public String getDisplayValue() {
if (!(stack.isDamageable())) {
return "";
}
int max=stack.getMaxDamage();
int cur=stack.getMaxDamage()-stack.getDamage();
return calculateDisplayValue(stack.getMaxDamage(), stack.getDamage());
}

public static String calculateDisplayValue(int max, int dam) {
int cur=max-dam;

int shown;
if (cur > max*ConfigurationHandler.showDamageOverPercent()/100) {
shown=-stack.getDamage();
shown=-dam;
} else {
shown=cur;
}
if (ConfigurationHandler.getShowPercentValues()) {
return String.format("%.1f%%", shown * 100.0 / stack.getMaxDamage());
return String.format("%.1f%%", shown * 100.0 / max);
}
return String.valueOf(shown);
}
Expand All @@ -40,6 +44,10 @@ public String getDisplayValue() {
public int getDisplayColor() {
int max=stack.getMaxDamage();
int cur=stack.getDamage();
return calculateDisplayColor(max, cur);
}

public static int calculateDisplayColor(int max, int cur) {
if (cur < max/5)
return color_green;
if (cur > max*9/10 && cur>max-100)
Expand All @@ -63,5 +71,4 @@ public boolean isItemStackDamageable() {
public ItemStack getItemStack() {
return stack;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.guntram.mcmod.durabilityviewer.sound;

import de.guntram.mcmod.durabilityviewer.handler.ConfigurationHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author gbl
*/
public class ColytraBreakingWarner extends ItemBreakingWarner {

private static int elytraMaxDamage;

int lastDurability;

@Override
public boolean checkBreaks(ItemStack stack) {
if (stack.getTag() == null || !stack.getTag().contains("colytra:ElytraUpgrade")) {
return false;
}

int damage;
try {
damage = stack.getTag().getCompound("colytra:ElytraUpgrade").getCompound("tag").getInt("Damage");
} catch (Exception ex) {
return false;
}

if (elytraMaxDamage == 0) {
elytraMaxDamage = new ItemStack(Items.ELYTRA).getMaxDamage();
}

int newDurability=elytraMaxDamage - damage;
if (newDurability < lastDurability
&& newDurability < ConfigurationHandler.getMinDurability()
&& newDurability * 100 / ConfigurationHandler.getMinPercent() < elytraMaxDamage) {
lastDurability=newDurability;
return true;
}
lastDurability=newDurability;
return false;
}
}

0 comments on commit a879a93

Please sign in to comment.