-
-
Save fantalatone/8d309e1c6bcc86a2f5ba92c707a78f4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fantalatone.npcmod.common.screen; | |
import com.fantalatone.npcmod.Reference; | |
import com.fantalatone.npcmod.common.entity.NPCEntity; | |
import com.fantalatone.npcmod.core.network.Networking; | |
import com.fantalatone.npcmod.core.network.packet.IncreaseDialogueIndex; | |
import com.fantalatone.npcmod.core.utils.ShopData; | |
import com.mojang.blaze3d.platform.Lighting; | |
import com.mojang.blaze3d.systems.RenderSystem; | |
import com.mojang.blaze3d.vertex.PoseStack; | |
import com.mojang.math.Quaternion; | |
import com.mojang.math.Vector3f; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.gui.components.Button; | |
import net.minecraft.client.gui.screens.Screen; | |
import net.minecraft.client.renderer.MultiBufferSource; | |
import net.minecraft.client.renderer.entity.EntityRenderDispatcher; | |
import net.minecraft.client.renderer.entity.ItemRenderer; | |
import net.minecraft.network.chat.Component; | |
import net.minecraft.resources.ResourceLocation; | |
import net.minecraft.world.MenuProvider; | |
import net.minecraft.world.entity.LivingEntity; | |
import net.minecraft.world.entity.player.Inventory; | |
import net.minecraft.world.entity.player.Player; | |
import net.minecraft.world.inventory.AbstractContainerMenu; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraftforge.api.distmarker.Dist; | |
import net.minecraftforge.api.distmarker.OnlyIn; | |
import org.jetbrains.annotations.Nullable; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.concurrent.atomic.AtomicInteger; | |
@OnlyIn(Dist.CLIENT) | |
public class NPCScreen extends Screen { | |
private static final int WIDTH = 249; | |
private static final int HEIGHT = 168; | |
private static final int ROT_X = -5; | |
private static final int ROT_Y = 5; | |
public Component allDialogues = Component.empty(); | |
private final NPCEntity NPC; | |
private static final ResourceLocation GUI = new ResourceLocation(Reference.MODID, "textures/gui/npc_gui_background.png"); | |
private final ItemRenderer renderer; | |
public HashMap<ItemStack, ItemStack> shop = new HashMap<ItemStack, ItemStack>(); | |
private final List<Button> shopGUIButtons = new ArrayList<>(); | |
public NPCScreen(NPCEntity npc, HashMap<ItemStack, ItemStack> shopMapping) { | |
super(Component.literal("Race Selection")); | |
this.NPC = npc; | |
this.renderer = Minecraft.getInstance().getItemRenderer(); | |
this.shop.putAll(shopMapping); | |
} | |
@Override | |
public boolean isPauseScreen() { | |
return false; | |
} | |
@Override | |
protected void init() { | |
this.allDialogues = this.NPC.getDialogue(); | |
int relY = (this.height - HEIGHT) / 2; | |
int shopBtnY = (relY + HEIGHT) - 32; | |
int relX = (this.width - WIDTH) / 2; | |
int shopBtnX = relX + ((WIDTH - 220) / 2); | |
for (int i = 0; i < shop.size(); i++) { | |
this.addRenderableWidget(new Button(shopBtnX + (i * 100), shopBtnY, 100, 20, Component.empty(), (ctx) -> { | |
buyItem(); | |
})); | |
} | |
updateShopButtons(); | |
} | |
private void updateShopButtons() { | |
} | |
private void buyItem() { | |
} | |
@Override | |
public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { | |
this.renderBackground(matrixStack); | |
RenderSystem.setShaderTexture(0, GUI); | |
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); | |
int relX = (this.width - WIDTH) / 2; | |
int relY = (this.height - HEIGHT) / 2; | |
// GUI BACKGROUND | |
this.blit(matrixStack, relX, relY, 0, 0, WIDTH, HEIGHT); | |
// GUI BACKGROUND END | |
// ENTITY | |
float f = (float)Math.atan(ROT_Y); | |
float f1 = (float)Math.atan(ROT_X); | |
// ToDo -> Fix positioning | |
int entityX = (this.width - (relX - 50)); | |
int entityY = (this.height - (relY + 50)); | |
// ToDo -> make this responsive to the screen | |
int entityScale = 50; | |
renderEntity(entityX, entityY, entityScale, f, f1, this.NPC); | |
// ENTITY END | |
// DIALOGUE | |
int textX = relX + ((WIDTH - 220) / 2); | |
int textY = relY + ((HEIGHT - 139) / 2); | |
this.font.drawWordWrap(this.NPC.getDialogueHistory(), textX, textY, 220, 139); | |
// DIALOGUE END | |
if (!this.NPC.hasNextDialogue()) { | |
AtomicInteger i = new AtomicInteger(0); | |
this.shop.forEach((key, val) -> { | |
this.renderer.renderGuiItem(key, 100, 50 + (i.get() * 10)); | |
this.renderer.renderGuiItem(val, 100, 50 + (i.get() * 10)); | |
i.getAndIncrement(); | |
}); | |
} | |
super.render(matrixStack, mouseX, mouseY, partialTicks); | |
} | |
private void renderEntity(int p_98851_, int p_98852_, int p_98853_, float angleXComponent, float angleYComponent, LivingEntity p_98856_) { | |
// | |
} | |
@Override | |
public boolean keyPressed(int p_96552_, int p_96553_, int p_96554_) { | |
if (p_96552_ == 32) { | |
Networking.sendToServer(new IncreaseDialogueIndex(this.NPC.getUUID())); | |
// this.updateShopButtons(); | |
return true; | |
} | |
return super.keyPressed(p_96552_, p_96553_, p_96554_); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment