generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
320 additions
and
6 deletions.
There are no files selected for viewing
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
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
8 changes: 6 additions & 2 deletions
8
src/main/java/dev/frydae/emcutils/EmpireMinecraftUtilities.java
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
5 changes: 5 additions & 0 deletions
5
src/main/java/dev/frydae/emcutils/accessors/GenericContainerScreenHandlerAccessor.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.frydae.emcutils.accessors; | ||
|
||
public interface GenericContainerScreenHandlerAccessor { | ||
void setRows(int rows); | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/frydae/emcutils/features/VaultButtons.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.frydae.emcutils.features; | ||
|
||
import dev.frydae.emcutils.features.vaultButtons.VaultScreenHandler; | ||
import dev.frydae.emcutils.utils.Util; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreens; | ||
import net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
public class VaultButtons { | ||
public static final ScreenHandlerType<VaultScreenHandler> GENERIC_9X7 = ScreenHandlerType.register("generic_9x7", VaultScreenHandler::createGeneric9x7); | ||
|
||
public static void handleScreenOpen(OpenScreenS2CPacket packet, CallbackInfo ci) { | ||
if (Util.IS_ON_EMC) { | ||
if (!packet.getName().getString().startsWith("Page: ")) { | ||
return; | ||
} | ||
|
||
if (packet.getScreenHandlerType() != ScreenHandlerType.GENERIC_9X6) { | ||
return; | ||
} | ||
|
||
HandledScreens.open(GENERIC_9X7, MinecraftClient.getInstance(), packet.getSyncId(), packet.getName()); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
161 changes: 161 additions & 0 deletions
161
src/main/java/dev/frydae/emcutils/features/vaultButtons/VaultScreen.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package dev.frydae.emcutils.features.vaultButtons; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import com.mojang.authlib.properties.Property; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.NbtHelper; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.text.LiteralText; | ||
import net.minecraft.text.Style; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.text.TextColor; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Identifier; | ||
import org.apache.commons.lang3.math.NumberUtils; | ||
|
||
import java.util.UUID; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class VaultScreen extends HandledScreen<VaultScreenHandler> implements ScreenHandlerProvider<VaultScreenHandler> { | ||
private static final Identifier TEXTURE = new Identifier("emcutils", "textures/gui/container/generic_63.png"); | ||
private final int rows; | ||
private final int vaultPage; | ||
private boolean shouldCallClose = true; | ||
|
||
private final int[] slotOffsets = {8, 26, 44, 62, 80, 98, 116, 134, 152}; | ||
|
||
public VaultScreen(VaultScreenHandler handler, PlayerInventory inventory, Text title) { | ||
super(handler, inventory, title); | ||
this.passEvents = false; | ||
this.rows = 6; | ||
this.backgroundHeight = 114 + 7 * 18; | ||
this.playerInventoryTitleY = this.backgroundHeight - 94; | ||
|
||
String page = title.getString().split(" ")[1]; | ||
this.vaultPage = NumberUtils.isParsable(page) ? Integer.parseInt(page) : 1; | ||
} | ||
|
||
/** | ||
* @param amount the amount of pages to go back | ||
* @return an {@link ItemStack player head} with a left arrow | ||
*/ | ||
private ItemStack getPreviousHead(int amount) { | ||
ItemStack stack = Items.PLAYER_HEAD.getDefaultStack(); | ||
|
||
stack.setCustomName(new LiteralText("Go back " + amount + " page" + (amount > 1 ? "s" : "")).setStyle(Style.EMPTY.withColor(TextColor.fromFormatting(Formatting.GREEN)).withItalic(false))); | ||
|
||
GameProfile profile = new GameProfile(UUID.fromString("1f961930-4e97-47b7-a5a1-2cc5150f3764"), ""); | ||
profile.getProperties().put("textures", new Property("Value", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWYxMzNlOTE5MTlkYjBhY2VmZGMyNzJkNjdmZDg3YjRiZTg4ZGM0NGE5NTg5NTg4MjQ0NzRlMjFlMDZkNTNlNiJ9fX0=")); | ||
|
||
stack.getTag().put("SkullOwner", NbtHelper.fromGameProfile(new CompoundTag(), profile)); | ||
|
||
return stack; | ||
} | ||
|
||
private ItemStack getNextHead(int amount) { | ||
ItemStack stack = Items.PLAYER_HEAD.getDefaultStack(); | ||
|
||
stack.setCustomName(new LiteralText("Go forward " + amount + " page" + (amount > 1 ? "s" : "")).setStyle(Style.EMPTY.withColor(TextColor.fromFormatting(Formatting.GREEN)).withItalic(false))); | ||
|
||
GameProfile profile = new GameProfile(UUID.fromString("1f961930-4e97-47b7-a5a1-2cc5150f3764"), ""); | ||
profile.getProperties().put("textures", new Property("Value", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTNmYzUyMjY0ZDhhZDllNjU0ZjQxNWJlZjAxYTIzOTQ3ZWRiY2NjY2Y2NDkzNzMyODliZWE0ZDE0OTU0MWY3MCJ9fX0=")); | ||
|
||
stack.getTag().put("SkullOwner", NbtHelper.fromGameProfile(new CompoundTag(), profile)); | ||
|
||
return stack; | ||
} | ||
|
||
@Override | ||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { | ||
this.renderBackground(matrices); | ||
super.render(matrices, mouseX, mouseY, delta); | ||
|
||
for (int i = 4; i > 0; i--) { | ||
if (vaultPage > i) { | ||
drawButton(matrices, getPreviousHead(i), mouseX, mouseY, slotOffsets[4 - i], i + ""); | ||
} | ||
} | ||
|
||
ItemStack chest = Items.CHEST.getDefaultStack(); | ||
chest.setCustomName(new LiteralText("View your vaults").setStyle(Style.EMPTY.withColor(TextColor.fromFormatting(Formatting.GREEN)).withItalic(false))); | ||
drawButton(matrices, chest, mouseX, mouseY, slotOffsets[4], ""); | ||
|
||
for (int i = 1; i <= 4; i++) { | ||
drawButton(matrices, getNextHead(i), mouseX, mouseY, slotOffsets[4 + i], i + ""); | ||
} | ||
|
||
this.drawMouseoverTooltip(matrices, mouseX, mouseY); | ||
} | ||
|
||
private void drawButton(MatrixStack matrices, ItemStack button, int mouseX, int mouseY, int buttonX, String amountText) { | ||
int midWidth = (this.width - this.backgroundWidth) / 2; | ||
int midHeight = (this.height - this.backgroundHeight) / 2; | ||
|
||
this.drawItem(button, midWidth + buttonX, midHeight + 125, amountText); | ||
|
||
if (mouseX >= midWidth + buttonX && mouseX <= midWidth + buttonX + 15) { | ||
if (mouseY >= midHeight + 126 && mouseY <= midHeight + 141) { | ||
matrices.translate(0, 0, 225); | ||
this.fillGradient(matrices, midWidth + buttonX, midHeight + 125, midWidth + buttonX + 16, midHeight + 125 + 16, 0x80ffffff, 0x80ffffff); | ||
this.renderTooltip(matrices, button, mouseX, mouseY); | ||
matrices.translate(0, 0, -225); | ||
} | ||
} | ||
} | ||
|
||
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { | ||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
this.client.getTextureManager().bindTexture(TEXTURE); | ||
int i = (this.width - this.backgroundWidth) / 2; | ||
int j = (this.height - this.backgroundHeight) / 2; | ||
this.drawTexture(matrices, i, j, 0, 0, this.backgroundWidth, (rows + 1) * 18 + 17); | ||
this.drawTexture(matrices, i, j + this.rows * 18 + 17, 0, 126, this.backgroundWidth, 128); | ||
} | ||
|
||
@Override | ||
public boolean mouseClicked(double mouseX, double mouseY, int button) { | ||
for (int i = 4; i > 0; i--) { | ||
handleClick(slotOffsets[4 - i], mouseX, mouseY, "/vault " + (vaultPage - i)); | ||
} | ||
|
||
handleClick(slotOffsets[4], mouseX, mouseY, "/vaults"); | ||
|
||
for (int i = 1; i <= 4; i++) { | ||
handleClick(slotOffsets[4 + i], mouseX, mouseY, "/vault " + (vaultPage + i)); | ||
} | ||
|
||
return super.mouseClicked(mouseX, mouseY, button); | ||
} | ||
|
||
private void handleClick(int buttonX, double mouseX, double mouseY, String command) { | ||
int midWidth = (this.width - this.backgroundWidth) / 2; | ||
int midHeight = (this.height - this.backgroundHeight) / 2; | ||
|
||
if (mouseX >= midWidth + buttonX && mouseX < midWidth + buttonX + 16) { | ||
if (mouseY >= midHeight + 126 && mouseY <= midHeight + 141) { | ||
this.shouldCallClose = false; | ||
MinecraftClient.getInstance().player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_SNARE, 4F, 1F); | ||
MinecraftClient.getInstance().player.sendChatMessage(command); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onClose() { | ||
if (shouldCallClose) { | ||
super.onClose(); | ||
} else { | ||
shouldCallClose = true; | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/dev/frydae/emcutils/features/vaultButtons/VaultScreenHandler.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package dev.frydae.emcutils.features.vaultButtons; | ||
|
||
import dev.frydae.emcutils.features.VaultButtons; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.inventory.SimpleInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.screen.slot.Slot; | ||
|
||
public class VaultScreenHandler extends ScreenHandler { | ||
private final Inventory inventory; | ||
private final int rows; | ||
|
||
public static VaultScreenHandler createGeneric9x7(int syncId, PlayerInventory playerInventory) { | ||
return new VaultScreenHandler(VaultButtons.GENERIC_9X7, syncId, playerInventory, 7); | ||
} | ||
|
||
private VaultScreenHandler(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, int rows) { | ||
this(type, syncId, playerInventory, new SimpleInventory(9 * rows), rows); | ||
} | ||
|
||
public VaultScreenHandler(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows) { | ||
super(type, syncId); | ||
checkSize(inventory, rows * 9); | ||
this.inventory = inventory; | ||
this.rows = rows; | ||
inventory.onOpen(playerInventory.player); | ||
int i = (6 - 3) * 18; | ||
|
||
for(int row = 0; row < 6; ++row) { | ||
for(int column = 0; column < 9; ++column) { | ||
this.addSlot(new Slot(inventory, column + row * 9, 8 + column * 18, 18 + row * 18)); | ||
} | ||
} | ||
|
||
for(int row = 0; row < 3; ++row) { | ||
for(int column = 0; column < 9; ++column) { | ||
this.addSlot(new Slot(playerInventory, column + row * 9 + 9, 8 + column * 18, 103 + row * 18 + i)); | ||
} | ||
} | ||
|
||
for(int row = 0; row < 9; ++row) { | ||
this.addSlot(new Slot(playerInventory, row, 8 + row * 18, 161 + i)); | ||
} | ||
|
||
} | ||
|
||
public boolean canUse(PlayerEntity player) { | ||
return this.inventory.canPlayerUse(player); | ||
} | ||
|
||
public ItemStack transferSlot(PlayerEntity player, int index) { | ||
ItemStack itemStack = ItemStack.EMPTY; | ||
Slot slot = (Slot)this.slots.get(index); | ||
if (slot != null && slot.hasStack()) { | ||
ItemStack itemStack2 = slot.getStack(); | ||
itemStack = itemStack2.copy(); | ||
if (index < this.rows * 9) { | ||
if (!this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true)) { | ||
return ItemStack.EMPTY; | ||
} | ||
} else if (!this.insertItem(itemStack2, 0, this.rows * 9, false)) { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
if (itemStack2.isEmpty()) { | ||
slot.setStack(ItemStack.EMPTY); | ||
} else { | ||
slot.markDirty(); | ||
} | ||
} | ||
|
||
return itemStack; | ||
} | ||
|
||
public void close(PlayerEntity player) { | ||
super.close(player); | ||
this.inventory.onClose(player); | ||
} | ||
} |
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
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
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
File renamed without changes
File renamed without changes.
Binary file added
BIN
+1.17 KB
src/main/resources/assets/emcutils/textures/gui/container/generic_63.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.