Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Robust lang, cleaned up layout #20

Open
wants to merge 3 commits into
base: xplat/1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import net.minecraft.block.FlowerBlock;
import net.minecraft.block.entity.BeaconBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.*;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionUtil;
import net.minecraft.registry.Registries;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
Expand All @@ -40,6 +42,7 @@ public class StatusEffectInfo implements EmiRecipe {
public StatusEffectInfo(StatusEffect effect, StatusEffectEmiStack emiStack) {
this.id = Registries.STATUS_EFFECT.getId(effect) != null ? Registries.STATUS_EFFECT.getId(effect) : new Identifier("emiffect", "missingno");
List<EmiIngredient> inputs0 = new ArrayList<>();

for (Potion potion : Registries.POTION) {
for (StatusEffectInstance instance : potion.getEffects()) {
if (instance.getEffectType().equals(effect)) {
Expand Down Expand Up @@ -79,12 +82,16 @@ public StatusEffectInfo(StatusEffect effect, StatusEffectEmiStack emiStack) {
inputs0.add(EmiStack.of(Blocks.BEACON));
}
}

this.inputs = inputs0;
this.desc = MinecraftClient.getInstance().textRenderer.wrapLines(EmiPort.translatable("effect." + id.getNamespace() + "." + id.getPath() + ".description"), 110);
String key1 = "effect." + id.getNamespace() + "." + id.getPath() + ".description";
String key2 = "effect." + id.getNamespace() + "." + id.getPath() + ".desc";
Text description = I18n.hasTranslation(key1) ? EmiPort.translatable(key1) : (I18n.hasTranslation(key2) ? EmiPort.translatable(key2) : EmiPort.translatable("emiffect.status_effect_info.missing"));
this.desc = MinecraftClient.getInstance().textRenderer.wrapLines(description, 110);
this.inputStackRow = inputs.isEmpty() ? 0 : 1;
int inputColumn = 0;
for (EmiIngredient ignored : inputs) {
if (inputColumn >= 6) {
if (inputColumn >= 8) {
this.inputStackRow += 1;
inputColumn = 0;
}
Expand Down Expand Up @@ -115,6 +122,11 @@ public List<EmiStack> getOutputs() {
return List.of(emiStack);
}

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

@Override
public int getDisplayWidth() {
return 144;
Expand Down Expand Up @@ -151,15 +163,15 @@ public void addWidgets(WidgetHolder widgets) {
int inputRow = 0;
int inputColumn = 0;
for (EmiIngredient ingredient : inputs) {
widgets.addSlot(ingredient, 18 + (inputColumn * 18), descHeight + 4 + (inputRow * 18));
widgets.addSlot(ingredient, (inputColumn * 18), descHeight + 4 + (inputRow * 18));
inputColumn += 1;
if (inputColumn >= 6) {
if (inputColumn >= 8) {
inputRow += 1;
inputColumn = 0;
}
}

SlotWidget effectSlot = new SlotWidget(emiStack, 3, (descHeight - 26) / 2).large(true);
SlotWidget effectSlot = new SlotWidget(emiStack, 2, 14).large(true);
widgets.add(effectSlot);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.StatusEffectSpriteManager;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.DamageModifierStatusEffect;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.ItemStack;
Expand All @@ -25,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class StatusEffectEmiStack extends EmiStack {
@Nullable
Expand Down Expand Up @@ -57,10 +62,10 @@ public void render(DrawContext draw, int x, int y, float delta, int flags) {
StatusEffectSpriteManager sprites = MinecraftClient.getInstance().getStatusEffectSpriteManager();
if (effect != null) {
Sprite sprite = sprites.getSprite(effect);
RenderSystem.clearColor(1.0F, 1.0F,1.0F,1.0F);
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderTexture(0, sprite.getAtlasId());
draw.drawSprite(x, y, 0, 18, 18, sprite);
draw.drawSprite(x - 1, y - 1, 0, 18, 18, sprite);
RenderSystem.applyModelViewMatrix();
}
}
Expand Down Expand Up @@ -98,8 +103,48 @@ public List<TooltipComponent> getTooltip() {
EmiPort.translatable("tooltip.emiffect.harmful").formatted(Formatting.RED))));
}
tooltips.add(TooltipComponent.of(EmiPort.ordered(
EmiPort.translatable("tooltip.emiffect.color", "#" + String.format("%02x", effect.getColor())).formatted(Formatting.GRAY))));
EmiPort.translatable("tooltip.emiffect.color", "#" + String.format("%02x", effect.getColor())).styled(style -> style.withColor(effect.getColor())))));
Identifier id = Registries.STATUS_EFFECT.getId(effect);
if (!effect.getAttributeModifiers().isEmpty()) {
tooltips.add(TooltipComponent.of(EmiPort.ordered(EmiPort.literal(""))));
tooltips.add(TooltipComponent.of(EmiPort.ordered(EmiPort.translatable("tooltip.emiffect.applied").formatted(Formatting.GRAY))));
for (Map.Entry<EntityAttribute, EntityAttributeModifier> entry: effect.getAttributeModifiers().entrySet()) {
System.out.println(entry);
EntityAttributeModifier entityAttributeModifier = entry.getValue();
double d = entityAttributeModifier.getValue();
boolean damage = false;
if (effect instanceof DamageModifierStatusEffect damageModifierStatusEffect) {
damage = true;
d = damageModifierStatusEffect.adjustModifierAmount(0, entityAttributeModifier);
}
double e;
if (entityAttributeModifier.getOperation() != EntityAttributeModifier.Operation.MULTIPLY_BASE && entityAttributeModifier.getOperation() != EntityAttributeModifier.Operation.MULTIPLY_TOTAL) {
if ((entry.getKey()).equals(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE)) {
e = d * 10.0;
} else {
e = d;
}
} else {
e = d * 100.0;
}

if (damage) {
if (d > 0.0) {
tooltips.add(TooltipComponent.of(EmiPort.ordered((EmiPort.translatable("attribute.modifier.plus." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(e), Text.translatable((entry.getKey()).getTranslationKey())).formatted(Formatting.BLUE).append(EmiPort.translatable("tooltip.emiffect.per_level").formatted(Formatting.BLUE))))));
} else if (d < 0.0) {
e *= -1.0;
tooltips.add(TooltipComponent.of(EmiPort.ordered((EmiPort.translatable("attribute.modifier.take." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(e), Text.translatable((entry.getKey()).getTranslationKey())).formatted(Formatting.RED).append(EmiPort.translatable("tooltip.emiffect.per_level").formatted(Formatting.RED))))));
}
} else {
if (d > 0.0) {
tooltips.add(TooltipComponent.of(EmiPort.ordered((EmiPort.translatable("attribute.modifier.plus." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(e), Text.translatable((entry.getKey()).getTranslationKey())).formatted(Formatting.BLUE)))));
} else if (d < 0.0) {
e *= -1.0;
tooltips.add(TooltipComponent.of(EmiPort.ordered((EmiPort.translatable("attribute.modifier.take." + entityAttributeModifier.getOperation().getId(), ItemStack.MODIFIER_FORMAT.format(e), Text.translatable((entry.getKey()).getTranslationKey())).formatted(Formatting.RED)))));
}
}
}
}
if (id != null)
tooltips.add(TooltipComponent.of(EmiPort.ordered(EmiPort.literal(EmiUtil.getModName(id.getNamespace()), Formatting.BLUE, Formatting.ITALIC))));
return tooltips;
Expand All @@ -119,4 +164,4 @@ public ItemStack getItemStack() {
}
return stack;
}
}
}
4 changes: 4 additions & 0 deletions common/src/main/resources/assets/emiffect/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"emi.category.emiffect.status_effect_info": "Status Effect Info",

"emiffect.status_effect_info.missing": "No description provided",

"tooltip.emiffect.beneficial": "Beneficial",
"tooltip.emiffect.neutral": "Neutral",
"tooltip.emiffect.harmful": "Harmful",
"tooltip.emiffect.color": "Color: %s",
"tooltip.emiffect.applied": "While Active:",
"tooltip.emiffect.per_level": " per level",

"effect.minecraft.absorption.description": "Adds damage some damaging absorbing hearths (which can't be regenerated); higher levels give more absorption.",
"effect.minecraft.bad_omen.description": "Causes an illager raid to start upon entering a village; higher levels increase the raid difficulty.",
Expand Down