Skip to content

Commit

Permalink
fix Horse Armor, Saddles/Carpets, Wolf Armor, and Mount Inventory Pre…
Browse files Browse the repository at this point in the history
…views
  • Loading branch information
sakura-ryoko committed Jul 31, 2024
1 parent c43f0cc commit f3b6797
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = tweakeroo-fabric

# Current mod version
mod_version = 0.20.999-sakura.22
mod_version = 0.20.999-sakura.23

# Required malilib version
malilib_version = 0.20.0
Expand Down
43 changes: 38 additions & 5 deletions src/main/java/fi/dy/masa/tweakeroo/renderer/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.CrafterBlock;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
Expand All @@ -21,8 +20,10 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.AbstractHorseEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.passive.WolfEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -32,6 +33,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import fi.dy.masa.malilib.render.InventoryOverlay;
import fi.dy.masa.malilib.util.EntityUtils;
import fi.dy.masa.malilib.util.GuiUtils;
import fi.dy.masa.tweakeroo.config.Configs;
Expand Down Expand Up @@ -146,7 +148,7 @@ public static void renderInventoryOverlay(MinecraftClient mc, DrawContext drawCo

Inventory inv = null;
ShulkerBoxBlock shulkerBoxBlock = null;
CrafterBlock crafterBlock = null;
//CrafterBlock crafterBlock = null;
LivingEntity entityLivingBase = null;

if (trace.getType() == HitResult.Type.BLOCK)
Expand Down Expand Up @@ -200,6 +202,7 @@ else if (entity instanceof AbstractHorseEntity)
}
}

final boolean isWolf = (entityLivingBase instanceof WolfEntity);
final int xCenter = GuiUtils.getScaledWindowWidth() / 2;
final int yCenter = GuiUtils.getScaledWindowHeight() / 2;
int x = xCenter - 52 / 2;
Expand All @@ -208,8 +211,8 @@ else if (entity instanceof AbstractHorseEntity)
if (inv != null && inv.size() > 0)
{
final boolean isHorse = (entityLivingBase instanceof AbstractHorseEntity);
final int totalSlots = isHorse ? inv.size() - 2 : inv.size();
final int firstSlot = isHorse ? 2 : 0;
final int totalSlots = isHorse ? inv.size() - 1 : inv.size();
final int firstSlot = isHorse ? 1 : 0;

final fi.dy.masa.malilib.render.InventoryOverlay.InventoryRenderType type = (entityLivingBase instanceof VillagerEntity) ? fi.dy.masa.malilib.render.InventoryOverlay.InventoryRenderType.VILLAGER : fi.dy.masa.malilib.render.InventoryOverlay.getInventoryType(inv);
final fi.dy.masa.malilib.render.InventoryOverlay.InventoryProperties props = fi.dy.masa.malilib.render.InventoryOverlay.getInventoryPropsTemp(type, totalSlots);
Expand All @@ -234,8 +237,13 @@ else if (entity instanceof AbstractHorseEntity)

if (isHorse)
{
Inventory horseInv = new SimpleInventory(2);
ItemStack horseArmor = (((AbstractHorseEntity) entityLivingBase).getBodyArmor());
horseInv.setStack(0, horseArmor != null && !horseArmor.isEmpty() ? horseArmor : ItemStack.EMPTY);
horseInv.setStack(1, inv.getStack(0));

fi.dy.masa.malilib.render.InventoryOverlay.renderInventoryBackground(type, xInv, yInv, 1, 2, mc);
fi.dy.masa.malilib.render.InventoryOverlay.renderInventoryStacks(type, inv, xInv + props.slotOffsetX, yInv + props.slotOffsetY, 1, 0, 2, mc, drawContext);
fi.dy.masa.malilib.render.InventoryOverlay.renderInventoryStacks(type, horseInv, xInv + props.slotOffsetX, yInv + props.slotOffsetY, 1, 0, 2, mc, drawContext);
xInv += 32 + 4;
}

Expand All @@ -246,6 +254,31 @@ else if (entity instanceof AbstractHorseEntity)
}
}

if (isWolf)
{
InventoryOverlay.InventoryRenderType type = InventoryOverlay.InventoryRenderType.HORSE;
final fi.dy.masa.malilib.render.InventoryOverlay.InventoryProperties props = fi.dy.masa.malilib.render.InventoryOverlay.getInventoryPropsTemp(type, 2);
final int rows = (int) Math.ceil((double) 2 / props.slotsPerRow);
int xInv;
int yInv = yCenter - props.height - 6;

if (rows > 6)
{
yInv -= (rows - 6) * 18;
y -= (rows - 6) * 18;
}

x = xCenter - 55;
xInv = xCenter + 2;
yInv = Math.min(yInv, yCenter - 92);

Inventory wolfInv = new SimpleInventory(2);
ItemStack wolfArmor = ((WolfEntity) entityLivingBase).getBodyArmor();
wolfInv.setStack(0, wolfArmor != null && !wolfArmor.isEmpty() ? wolfArmor : ItemStack.EMPTY);
fi.dy.masa.malilib.render.InventoryOverlay.renderInventoryBackground(type, xInv, yInv, 1, 2, mc);
fi.dy.masa.malilib.render.InventoryOverlay.renderInventoryStacks(type, wolfInv, xInv + props.slotOffsetX, yInv + props.slotOffsetY, 1, 0, 2, mc, drawContext);
}

if (entityLivingBase != null)
{
fi.dy.masa.malilib.render.InventoryOverlay.renderEquipmentOverlayBackground(x, y, entityLivingBase, drawContext);
Expand Down

0 comments on commit f3b6797

Please sign in to comment.