minecraft-src/net/minecraft/client/gui/screens/inventory/CartographyTableScreen.java
2025-07-04 02:00:41 +03:00

117 lines
5.5 KiB
Java

package net.minecraft.client.gui.screens.inventory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.MapRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.state.MapRenderState;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.CartographyTableMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.MapItem;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public class CartographyTableScreen extends AbstractContainerScreen<CartographyTableMenu> {
private static final ResourceLocation ERROR_SPRITE = ResourceLocation.withDefaultNamespace("container/cartography_table/error");
private static final ResourceLocation SCALED_MAP_SPRITE = ResourceLocation.withDefaultNamespace("container/cartography_table/scaled_map");
private static final ResourceLocation DUPLICATED_MAP_SPRITE = ResourceLocation.withDefaultNamespace("container/cartography_table/duplicated_map");
private static final ResourceLocation MAP_SPRITE = ResourceLocation.withDefaultNamespace("container/cartography_table/map");
private static final ResourceLocation LOCKED_SPRITE = ResourceLocation.withDefaultNamespace("container/cartography_table/locked");
private static final ResourceLocation BG_LOCATION = ResourceLocation.withDefaultNamespace("textures/gui/container/cartography_table.png");
private final MapRenderState mapRenderState = new MapRenderState();
public CartographyTableScreen(CartographyTableMenu menu, Inventory playerInventory, Component title) {
super(menu, playerInventory, title);
this.titleLabelY -= 2;
}
@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
super.render(guiGraphics, mouseX, mouseY, partialTick);
this.renderTooltip(guiGraphics, mouseX, mouseY);
}
@Override
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
int i = this.leftPos;
int j = this.topPos;
guiGraphics.blit(RenderType::guiTextured, BG_LOCATION, i, j, 0.0F, 0.0F, this.imageWidth, this.imageHeight, 256, 256);
ItemStack itemStack = this.menu.getSlot(1).getItem();
boolean bl = itemStack.is(Items.MAP);
boolean bl2 = itemStack.is(Items.PAPER);
boolean bl3 = itemStack.is(Items.GLASS_PANE);
ItemStack itemStack2 = this.menu.getSlot(0).getItem();
MapId mapId = itemStack2.get(DataComponents.MAP_ID);
boolean bl4 = false;
MapItemSavedData mapItemSavedData;
if (mapId != null) {
mapItemSavedData = MapItem.getSavedData(mapId, this.minecraft.level);
if (mapItemSavedData != null) {
if (mapItemSavedData.locked) {
bl4 = true;
if (bl2 || bl3) {
guiGraphics.blitSprite(RenderType::guiTextured, ERROR_SPRITE, i + 35, j + 31, 28, 21);
}
}
if (bl2 && mapItemSavedData.scale >= 4) {
bl4 = true;
guiGraphics.blitSprite(RenderType::guiTextured, ERROR_SPRITE, i + 35, j + 31, 28, 21);
}
}
} else {
mapItemSavedData = null;
}
this.renderResultingMap(guiGraphics, mapId, mapItemSavedData, bl, bl2, bl3, bl4);
}
private void renderResultingMap(
GuiGraphics guiGraphics, @Nullable MapId mapId, @Nullable MapItemSavedData mapData, boolean hasMap, boolean hasPaper, boolean hasGlassPane, boolean isMaxSize
) {
int i = this.leftPos;
int j = this.topPos;
if (hasPaper && !isMaxSize) {
guiGraphics.blitSprite(RenderType::guiTextured, SCALED_MAP_SPRITE, i + 67, j + 13, 66, 66);
this.renderMap(guiGraphics, mapId, mapData, i + 85, j + 31, 0.226F);
} else if (hasMap) {
guiGraphics.blitSprite(RenderType::guiTextured, DUPLICATED_MAP_SPRITE, i + 67 + 16, j + 13, 50, 66);
this.renderMap(guiGraphics, mapId, mapData, i + 86, j + 16, 0.34F);
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(0.0F, 0.0F, 1.0F);
guiGraphics.blitSprite(RenderType::guiTextured, DUPLICATED_MAP_SPRITE, i + 67, j + 13 + 16, 50, 66);
this.renderMap(guiGraphics, mapId, mapData, i + 70, j + 32, 0.34F);
guiGraphics.pose().popPose();
} else if (hasGlassPane) {
guiGraphics.blitSprite(RenderType::guiTextured, MAP_SPRITE, i + 67, j + 13, 66, 66);
this.renderMap(guiGraphics, mapId, mapData, i + 71, j + 17, 0.45F);
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(0.0F, 0.0F, 1.0F);
guiGraphics.blitSprite(RenderType::guiTextured, LOCKED_SPRITE, i + 118, j + 60, 10, 14);
guiGraphics.pose().popPose();
} else {
guiGraphics.blitSprite(RenderType::guiTextured, MAP_SPRITE, i + 67, j + 13, 66, 66);
this.renderMap(guiGraphics, mapId, mapData, i + 71, j + 17, 0.45F);
}
}
private void renderMap(GuiGraphics guiGraphics, @Nullable MapId mapId, @Nullable MapItemSavedData mapData, int x, int y, float scale) {
if (mapId != null && mapData != null) {
guiGraphics.pose().pushPose();
guiGraphics.pose().translate((float)x, (float)y, 1.0F);
guiGraphics.pose().scale(scale, scale, 1.0F);
MapRenderer mapRenderer = this.minecraft.getMapRenderer();
mapRenderer.extractRenderState(mapId, mapData, this.mapRenderState);
guiGraphics.drawSpecial(multiBufferSource -> mapRenderer.render(this.mapRenderState, guiGraphics.pose(), multiBufferSource, true, 15728880));
guiGraphics.pose().popPose();
}
}
}