From 20e0325493dc5091aaca4a6336237d810d1d0d87 Mon Sep 17 00:00:00 2001 From: Jkibbels Date: Sun, 22 Dec 2024 22:28:39 -0500 Subject: [PATCH] [factions-and-banking] More work on the faction base block + mixin example of player drop --- .../keeblarcraft/gui/FactionBlockScreen.java | 3 +- .../keeblarcraft/BankMgr/BankManager.java | 6 +- .../keeblarcraft/Commands/BankCommands.java | 2 +- .../keeblarcraft/Commands/MiscCommands.java | 1 + .../Commands/ShortcutCommands.java | 135 ++++++++---------- .../BlockEntities/FactionBlockEntity.java | 20 +-- .../CustomBlocks/Blocks/FactionBaseBlock.java | 3 +- .../keeblarcraft/CustomItems/ItemManager.java | 1 - .../FactionMgr/FactionConfig.java | 1 - .../FactionMgr/FactionManager.java | 9 +- .../GuiMgr/FactionBlockScreenHandler.java | 51 +++++-- .../keeblarcraft/Utils/PlayerChecks.java | 26 ++++ .../jesse/keeblarcraft/mixin/PlayerMixin.java | 53 +++++++ .../textures/gui/faction_base_block.png | Bin 0 -> 7683 bytes src/main/resources/fabric.mod.json | 3 + src/main/resources/keeblarcraft.mixins.json | 13 ++ 16 files changed, 225 insertions(+), 102 deletions(-) create mode 100644 src/main/java/jesse/keeblarcraft/Utils/PlayerChecks.java create mode 100644 src/main/java/jesse/keeblarcraft/mixin/PlayerMixin.java create mode 100644 src/main/resources/assets/keeblarcraft/textures/gui/faction_base_block.png create mode 100644 src/main/resources/keeblarcraft.mixins.json diff --git a/src/client/java/jesse/keeblarcraft/gui/FactionBlockScreen.java b/src/client/java/jesse/keeblarcraft/gui/FactionBlockScreen.java index 842518e..1fa86db 100644 --- a/src/client/java/jesse/keeblarcraft/gui/FactionBlockScreen.java +++ b/src/client/java/jesse/keeblarcraft/gui/FactionBlockScreen.java @@ -13,7 +13,8 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; public class FactionBlockScreen extends HandledScreen { - private static final Identifier TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/attribute_flight.png"); + // This is a placeholder image until an actual one is drawn + private static final Identifier TEXTURE = new Identifier(Keeblarcraft.MOD_ID, "textures/gui/faction_base_block.png"); public FactionBlockScreen(FactionBlockScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); diff --git a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java index e547af6..3949480 100644 --- a/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java +++ b/src/main/java/jesse/keeblarcraft/BankMgr/BankManager.java @@ -267,7 +267,7 @@ public final class BankManager { boolean defaultServerBank = bankIdentifier == null || bankIdentifier == ""; System.out.println("value of bankIdentifier is " + defaultServerBank); - System.out.println("The player name is " + player.getDisplayName().getString()); + System.out.println("The player name is " + player.getEntityName()); // DEBUG @@ -278,14 +278,14 @@ public final class BankManager { // Create an account via the server-owned bank account if (defaultServerBank) { - success = banks.get(KEEBLARCRAFT_SERVER_BANK_ID).CreateAccount(player.getUuidAsString(), player.getDisplayName().getString(), accountType); + success = banks.get(KEEBLARCRAFT_SERVER_BANK_ID).CreateAccount(player.getUuidAsString(), player.getEntityName(), accountType); } else { System.out.println("Creating bank on non-server owned bank"); // Create an account via a specified bank identifier Integer routingNumber = Integer.parseInt(bankIdentifier); if (banks.containsKey(routingNumber)) { - banks.get(routingNumber).CreateAccount(player.getUuidAsString(), player.getDisplayName().getString(), accountType); + banks.get(routingNumber).CreateAccount(player.getUuidAsString(), player.getEntityName(), accountType); } else { player.sendMessage(Text.of("That bank does not exist")); } diff --git a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java index c6af3e0..a98c61c 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/BankCommands.java @@ -383,7 +383,7 @@ public class BankCommands { ///////////////////////////////////////////////////////////////////////////// public void AdminCommand(ServerPlayerEntity sourcePlayer, List argList) { // The player must be opped & the size must be at LEAST 2 (1 keyword + extra for sublist) - String pName = sourcePlayer.getDisplayName().toString(); + String pName = sourcePlayer.getEntityName(); System.out.println("Is player admin? " + (IsOperator(sourcePlayer) ? "YES" : "NO")); if (IsOperator(sourcePlayer) && argList.size() >= 1) { String arg = argList.get(0); diff --git a/src/main/java/jesse/keeblarcraft/Commands/MiscCommands.java b/src/main/java/jesse/keeblarcraft/Commands/MiscCommands.java index d3c3d45..f0963f4 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/MiscCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/MiscCommands.java @@ -126,6 +126,7 @@ public class MiscCommands { public int SetNickname(ServerPlayerEntity player, String name) { player.setCustomName(Text.of(name)); + player.setCustomNameVisible(true); return 0; } diff --git a/src/main/java/jesse/keeblarcraft/Commands/ShortcutCommands.java b/src/main/java/jesse/keeblarcraft/Commands/ShortcutCommands.java index 971a729..5d28391 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/ShortcutCommands.java +++ b/src/main/java/jesse/keeblarcraft/Commands/ShortcutCommands.java @@ -14,6 +14,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.context.CommandContext; import jesse.keeblarcraft.Utils.ChatUtil; +import jesse.keeblarcraft.Utils.PlayerChecks; import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.command.argument.EntityArgumentType; @@ -40,17 +41,13 @@ public class ShortcutCommands { // Fly command CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("fly") - .executes(context -> { FlightShortcut(context); - return 0; - })); - }); + var flightNode = CommandManager.literal("fly").executes(context -> FlightSpeedShortcut(null, context)).build(); - // Fly command with speed - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("fly") - .then(CommandManager.argument("value", IntegerArgumentType.integer()) - .executes(context -> FlightSpeedShortcut(IntegerArgumentType.getInteger(context, "value"), context)))); + var flightSpeed = CommandManager.argument("value", IntegerArgumentType.integer()) + .executes(context -> FlightSpeedShortcut(IntegerArgumentType.getInteger(context, "value"), context)).build(); + + dispatcher.getRoot().addChild(flightNode); + flightNode.addChild(flightSpeed); }); ///TODO: Read TODO on function @@ -61,16 +58,21 @@ public class ShortcutCommands { // }); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("heal") - .executes(context -> { HealShortcut(context, null); - return 0; - })); + var healNode = CommandManager.literal("heal").executes(context -> HealShortcut(context, null)).build(); + var targetPlayer = CommandManager.argument("targetPlayer", EntityArgumentType.player()) + .executes(context -> HealShortcut(context, EntityArgumentType.getPlayer(context, "targetPlayer"))).build(); + + dispatcher.getRoot().addChild(healNode); + healNode.addChild(targetPlayer); }); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - var healNode = CommandManager.literal("heal").build(); + var feedNode = CommandManager.literal("feed").executes(context -> FeedShortcut(context, null)).build(); var targetPlayer = CommandManager.argument("targetPlayer", EntityArgumentType.player()) - .executes(context -> HealShortcut(context, EntityArgumentType.getPlayer(context, "targetPlayer"))); + .executes(context -> FeedShortcut(context, EntityArgumentType.getPlayer(context, "targetPlayer"))).build(); + + dispatcher.getRoot().addChild(feedNode); + feedNode.addChild(targetPlayer); }); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { @@ -118,7 +120,6 @@ public class ShortcutCommands { retValue = -1; break; } - } else { player.sendMessage(Text.literal("\033[31m You do not have permissions to run this command! \033[0m")); @@ -127,52 +128,34 @@ public class ShortcutCommands { else { System.out.println(ChatUtil.ColoredString("This command cannot be executed by a non-player entity!", CONSOLE_COLOR.RED)); } - return retValue; } - private int FlightShortcut(CommandContext context) { - int retValue = -1; - if (context.getSource().isExecutedByPlayer()) { + private int FlightSpeedShortcut(Integer value, CommandContext context) { + if (PlayerChecks.HasPermission(context)) { ServerPlayerEntity player = context.getSource().getPlayer(); + PlayerAbilities abilities = player.getAbilities(); - if (player.hasPermissionLevel(4)) { - PlayerAbilities abilities = player.getAbilities(); - abilities.flying = !abilities.flying; // Toggle flying - abilities.setFlySpeed(DEFAULT_FLIGHT_SPEED); // It seems flight speed is on a 0-1 scale + if (abilities.flying && value == null) { + // Disable flight + abilities.flying = false; + abilities.setFlySpeed(0); + player.sendMessage(Text.of("Disabled flight")); + } else if (!abilities.flying && value == null) { + value = 1; + } + + if (value != null && value >= 1 && value <= 10) { + abilities.allowFlying = true; + abilities.setFlySpeed((float) (value / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast! player.sendAbilitiesUpdate(); - ChatUtil.SendPlayerMsg(player, "You can now fly! Flight speed is " + abilities.getFlySpeed()); + ChatUtil.SendPlayerMsg(player, "Flight speed set to " + (value)); } else { - player.sendMessage(Text.literal("You do not have permission for this command")); + player.sendMessage(Text.literal("Only values from 1-10 are accepted")); } } - return retValue; - } - - private int FlightSpeedShortcut(int value, CommandContext context) { - int retValue = -1; - - if (context.getSource().isExecutedByPlayer()) { - ServerPlayerEntity player = context.getSource().getPlayer(); - - if (player.hasPermissionLevel(4)) { - PlayerAbilities abilities = player.getAbilities(); - - if (value >= 1 && value <= 10) { - abilities.allowFlying = true; - abilities.setFlySpeed((float) (value / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast! - player.sendAbilitiesUpdate(); - ChatUtil.SendPlayerMsg(player, "Flight speed set to " + (value)); - } else { - player.sendMessage(Text.literal("Only values from 1-10 are accepted")); - } - } else { - player.sendMessage(Text.literal("You do not have permission for this command")); - } - } - - return retValue; + return 0; } ///TODO: There is a bug with walk speed that causes the players speed to behave weirdly despite the value. It's either a crawl or mach 10 @@ -202,35 +185,37 @@ public class ShortcutCommands { // } private int FeedShortcut(CommandContext context, ServerPlayerEntity target) { - - // if target is null, feed ourselves - if (target == null) { - ServerPlayerEntity player = context.getSource().getPlayer(); - player.getHungerManager().setExhaustion(0.0f); - player.getHungerManager().setFoodLevel(20); // 20 is hardcoded inside class - player.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10! - ChatUtil.SendPlayerMsg(player, "You were just super fed!"); - } else { - target.getHungerManager().setExhaustion(0.0f); - target.getHungerManager().setFoodLevel(20); // 20 is hardcoded inside class - target.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10! - ChatUtil.SendPlayerMsg(target, "You were just super fed!"); + if (PlayerChecks.HasPermission(context)) { + // if target is null, feed ourselves + if (target == null) { + ServerPlayerEntity player = context.getSource().getPlayer(); + player.getHungerManager().setExhaustion(0.0f); + player.getHungerManager().setFoodLevel(20); // 20 is hardcoded inside class + player.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10! + ChatUtil.SendPlayerMsg(player, "You were just super fed!"); + } else { + target.getHungerManager().setExhaustion(0.0f); + target.getHungerManager().setFoodLevel(20); // 20 is hardcoded inside class + target.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10! + ChatUtil.SendPlayerMsg(target, "You were just super fed!"); + } } return 0; } private int HealShortcut(CommandContext context, ServerPlayerEntity target) { int retValue = -1; - // If no player specified; then heal ourself full HP - if (target == null) { - context.getSource().getPlayer().setHealth(context.getSource().getPlayer().getMaxHealth()); - ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "Healed!"); - } else { - target.setHealth(target.getMaxHealth()); - ChatUtil.SendPlayerMsg(target, "You were just healed!"); - ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "You healed " + target.getDisplayName()); + if (PlayerChecks.HasPermission(context)) { + // If no player specified; then heal ourself full HP + if (target == null) { + context.getSource().getPlayer().setHealth(context.getSource().getPlayer().getMaxHealth()); + ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "Healed!"); + } else { + target.setHealth(target.getMaxHealth()); + ChatUtil.SendPlayerMsg(target, "You were just healed!"); + ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "You healed " + target.getEntityName()); + } } - return retValue; } diff --git a/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java b/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java index 494e6e9..e4172bb 100644 --- a/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java +++ b/src/main/java/jesse/keeblarcraft/CustomBlocks/BlockEntities/FactionBlockEntity.java @@ -5,7 +5,6 @@ import jesse.keeblarcraft.world.ImplementedInventory; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventories; @@ -21,13 +20,13 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory { - private final DefaultedList inventory = DefaultedList.ofSize(4, ItemStack.EMPTY); + private final DefaultedList inventory = DefaultedList.ofSize(7, ItemStack.EMPTY); private static final int DEFENSE_SLOT_ONE = 0; private static final int DEFENSE_SLOT_TWO = 1; private static final int OFFENSE_SLOT_ONE = 2; private static final int OFFENSE_SLOT_TWO = 3; - private static int power = 0; + private static int factionPower = 0; protected final PropertyDelegate propertyDelegate; @@ -37,20 +36,22 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan @Override public int get(int index) { + // The only value we need to get/delegate is faction power return switch(index) { - default -> power; + default -> factionPower; }; } @Override public void set(int index, int value) { switch(index) { - default -> power = value; + default -> factionPower = value; }; } @Override public int size() { + // We are only sync'ing 1 integer - faction power return 1; } @@ -71,14 +72,15 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan public void readNbt(NbtCompound nbt) { super.readNbt(nbt); Inventories.readNbt(nbt, inventory); - power = nbt.getInt("faction_block_entity.power"); + factionPower = nbt.getInt("faction_block_entity.power"); } @Override public void writeNbt(NbtCompound nbt) { super.writeNbt(nbt); - Inventories.writeNbt(nbt, inventory); // Write our inventory when world is saved; etc - nbt.putInt("faction_block_entity.power", power); + // Write the inventory of the block + Inventories.writeNbt(nbt, inventory); + nbt.putInt("faction_block_entity.power", factionPower); } @Override @@ -100,5 +102,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan } // Do stuff here that we need to do on a per tick basis. Probably check the items inside the slots and do stuff? + // Maybe something with callback handlers might be done here? Like the temp flight within bounds of the faction block if that powerup is + // active, etc? } } diff --git a/src/main/java/jesse/keeblarcraft/CustomBlocks/Blocks/FactionBaseBlock.java b/src/main/java/jesse/keeblarcraft/CustomBlocks/Blocks/FactionBaseBlock.java index b4f423d..f26593a 100644 --- a/src/main/java/jesse/keeblarcraft/CustomBlocks/Blocks/FactionBaseBlock.java +++ b/src/main/java/jesse/keeblarcraft/CustomBlocks/Blocks/FactionBaseBlock.java @@ -1,7 +1,5 @@ package jesse.keeblarcraft.CustomBlocks.Blocks; -import javax.swing.text.html.BlockView; - import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration; import jesse.keeblarcraft.CustomBlocks.BlockEntities.FactionBlockEntity; import net.minecraft.block.*; @@ -59,6 +57,7 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { // Server side handling is different than that of client side handling; we MUST check if we are on a server first because then we must // request information about this block entity from the server + System.out.println("onUse of faction base block called"); if (!world.isClient()) { NamedScreenHandlerFactory screenHandlerFactory = (FactionBlockEntity) world.getBlockEntity(pos); diff --git a/src/main/java/jesse/keeblarcraft/CustomItems/ItemManager.java b/src/main/java/jesse/keeblarcraft/CustomItems/ItemManager.java index 872f14f..656b80e 100644 --- a/src/main/java/jesse/keeblarcraft/CustomItems/ItemManager.java +++ b/src/main/java/jesse/keeblarcraft/CustomItems/ItemManager.java @@ -65,5 +65,4 @@ public class ItemManager { // Item exampleItem = new Item(new FabricItemSettings()); // RegisterItem("metaljacket_helmet", exampleItem); } - } diff --git a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java index b2ff584..290e498 100644 --- a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java +++ b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionConfig.java @@ -502,7 +502,6 @@ public class FactionConfig { System.out.println("ListOfFactions - map size: " + allFactions.size()); for (Entry entry : allFactions.entrySet()) { - System.out.println("Adding fac " + entry.getKey() + " to fac"); facs.add(entry.getKey()); } diff --git a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java index dd1ccac..2b8cc3e 100644 --- a/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java +++ b/src/main/java/jesse/keeblarcraft/FactionMgr/FactionManager.java @@ -91,8 +91,9 @@ public class FactionManager { String playerFac = factionConfig.factions.FindFactionOfPlayer(player.getUuidAsString()); if (playerFac != "") { - success = factionConfig.factions.LeaveFaction(playerFac, player.getUuidAsString(), player.getDisplayName().toString()); + success = factionConfig.factions.LeaveFaction(playerFac, player.getUuidAsString(), player.getEntityName()); player.sendMessage(Text.of("[Factions]: You left your faction!")); + FlashConfig(); } else { player.sendMessage(Text.of("[Factions]: You are not in a faction!")); } @@ -116,7 +117,11 @@ public class FactionManager { String facOfPlayer = factionConfig.factions.FindFactionOfPlayer(creator.getUuidAsString()); if (facOfPlayer == "") { - success = factionConfig.factions.CreateFaction(factionName, creator.getUuidAsString(), creator.getDisplayName().toString()); + creator.sendMessage(Text.of("Your display name: " + creator.getDisplayName().toString())); + creator.sendMessage(Text.of("Your name: " + creator.getName())); + creator.sendMessage(Text.of("Your custom name: " + creator.getCustomName())); + creator.sendMessage(Text.of("Your entity name: " + creator.getEntityName())); + success = factionConfig.factions.CreateFaction(factionName, creator.getUuidAsString(), creator.getEntityName()); if (!success) { creator.sendMessage(Text.of("[Factions]: Could not create faction - faction already exists.")); diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java b/src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java index 29a5186..de01b96 100644 --- a/src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/FactionBlockScreenHandler.java @@ -16,24 +16,32 @@ public class FactionBlockScreenHandler extends ScreenHandler { private final Inventory inventory; private final PropertyDelegate propertyDelegate; public final FactionBlockEntity blockEntity; + public int factionPower = 0; public FactionBlockScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) { - this(syncId, inventory, inventory.player.getWorld().getBlockEntity(buf.readBlockPos()), new ArrayPropertyDelegate(4)); + this(syncId, inventory, inventory.player.getWorld().getBlockEntity(buf.readBlockPos()), new ArrayPropertyDelegate(7)); } public FactionBlockScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity, PropertyDelegate arrayPropertyDelegate) { super(ScreenHandlerRegistration.FACTION_BLOCK_SCREEN_HANDLER, syncId); - checkSize((Inventory) blockEntity, 4); + checkSize((Inventory) blockEntity, 7); this.inventory = (Inventory) blockEntity; inventory.onOpen(playerInventory.player); this.propertyDelegate = arrayPropertyDelegate; this.blockEntity = (FactionBlockEntity) blockEntity; - // TODO: These positions need to be redrawn with an actual GUI - this.addSlot(new Slot(inventory, 0, 60, 11)); - this.addSlot(new Slot(inventory, 1, 70, 11)); - this.addSlot(new Slot(inventory, 2, 80, 11)); - this.addSlot(new Slot(inventory, 3, 90, 11)); + // Need a better way of storing these coordinates... + this.addSlot(new Slot(inventory, 0, 20, 11)); // top row + this.addSlot(new Slot(inventory, 1, 20, 39)); + this.addSlot(new Slot(inventory, 2, 49, 11)); + this.addSlot(new Slot(inventory, 3, 49, 39)); + this.addSlot(new Slot(inventory, 4, 78, 11)); + this.addSlot(new Slot(inventory, 5, 78, 39)); + + this.addSlot(new Slot(inventory, 6, 128, 26)); + + addPlayerInventory(playerInventory); + addPlayerHotbar(playerInventory); // Need to reference Kaupendim tutorial again; but we could theoretically just add the player inventory // right here so that they can drag items in and whatnot (I assume). I am unsure if I am taking that @@ -43,6 +51,11 @@ public class FactionBlockScreenHandler extends ScreenHandler { addProperties(arrayPropertyDelegate); } + public Integer GetFactionPower() { + factionPower = this.propertyDelegate.get(0); + return factionPower; + } + // This is just for SHIFT+CLICK moving @Override public ItemStack quickMove(PlayerEntity player, int invSlot) { @@ -64,10 +77,32 @@ public class FactionBlockScreenHandler extends ScreenHandler { slot.markDirty();; } } - return newStack; } + // From Kaupenjoe video + private void addPlayerInventory(PlayerInventory playerInventory) { + for (int i = 0; i < 3; ++i) { // Rows + for (int l = 0; l < 9; ++l) { // Columns + // The fancy math (expanded from kaupen video for clarity for me for later) seems to just specify a few things + int index = l + i * 9 + 9; // l = col, i*9 = the row to be on (scaling by 9 bc slots are 1-(9*3) in amount), +9 = where on that row to be! + int x = 8 + l * 18; // Texture draw position on image + int y = 84 + i * 18; // Texture draw position on image + this.addSlot(new Slot(playerInventory, index, x, y)); + } + } + } + + // From Kaupenjoe video + private void addPlayerHotbar(PlayerInventory playerInventory) { + for (int i = 0; i < 9; ++i) { + int index = i; // Index of hotbar (only 9 slots long in vanilla) + int x = 8 + i * 18; // Texture draw position + int y = 142; // Texture draw position + this.addSlot(new Slot(playerInventory, index, x, y)); + } + } + @Override public boolean canUse(PlayerEntity player) { return this.inventory.canPlayerUse(player); diff --git a/src/main/java/jesse/keeblarcraft/Utils/PlayerChecks.java b/src/main/java/jesse/keeblarcraft/Utils/PlayerChecks.java new file mode 100644 index 0000000..bf6a735 --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/Utils/PlayerChecks.java @@ -0,0 +1,26 @@ +package jesse.keeblarcraft.Utils; + +import com.mojang.brigadier.context.CommandContext; + +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + +public class PlayerChecks { + public static Boolean HasPermission(CommandContext context) { + if (context.getSource().isExecutedByPlayer() && HasPermission(context.getSource().getPlayer())) { + return true; + } else { + return false; + } + } + + public static Boolean HasPermission(ServerPlayerEntity player) { + if (player.hasPermissionLevel(4)) { + return true; + } else { + player.sendMessage(Text.of("You do not have permission to use this command.")); + return false; + } + } +} diff --git a/src/main/java/jesse/keeblarcraft/mixin/PlayerMixin.java b/src/main/java/jesse/keeblarcraft/mixin/PlayerMixin.java new file mode 100644 index 0000000..7401b30 --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/mixin/PlayerMixin.java @@ -0,0 +1,53 @@ +package jesse.keeblarcraft.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import jesse.keeblarcraft.Keeblarcraft; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; + +// MIXIN CHEAT SHEET: +// https://wiki.fabricmc.net/tutorial:mixin_examples +// Tutorial I referenced for this knowledge (outside fabric wiki): https://www.youtube.com/watch?v=HQUkWjMWTik +// MAKE SURE YOU READ fabric_mod.json and the keeblarcraft.mixin.json!! These injections are not instantiated anywhere else because mixins are special +// because all this code is essentially injected (pasted) into their respective areas during compilation. + +@Mixin(PlayerEntity.class) +// *THIS* CLASS MUST BE ABSTRACT - BUT NOT TRUE FOR EVERY MIXIN +public abstract class PlayerMixin { + // Example 0: Base injection (HEAD) + // EXPLANATION OF THI MAGIC STRING: + // This string MUST be written as so; BUT - it's not so bad! It has logic to it - obviously. Some known, some still a bit not + // 1. 'dropItem' is the method we are overriding, and then we are just specifying exactly (which is required) where that method is at + // 2. 'Lnet/minecraft/item/ItemStack' -> First argument inside method we are injecting in. In this case, the argument is an object 'ItemStack' so we specify + // that this is the net/minecraft/item/ItemStack type. WHY THE 'L' AT START? Don't know - but it's used in EVERY example + // so it can be assumed you always need it. It's consistently there, so not a huge deal. + // 3. The 'ZZ' here are the other parameters inside the method which are java defaults - 'Z' happens to stand for boolean. It seems semicolons aren't needed + // between defaults since it just goes 'ZZ' and the parameter finishes with two booleans. Please CTRL+CLICK into the PlayerEntity class and search for 'dropItem' to + // familiarize yourself with the signature of the function. + // 4. The appending 'Lnet/minecraft/entity/ItemEntity' is the RETURN TYPE of this method + // 5. WHAT IS THE 'at = @At' syntax? Well; it is VERY Helpful to familiarize yourself with some areas on the fabric cheat sheet (https://wiki.fabricmc.net/tutorial:mixin_examples) + // but to give a brief explanation of it - it's just WHERE you are injecting your code at inside this function. 'HEAD' means the very top. 'TAIL' means at the end. There also + // is ways to inject by some offset into the function, and whatever a 'slice' is but I'm not looking at those right now. You get the idea + // 6. WHAT IS THE 'cancellable = true' + @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At("HEAD"), cancellable = true) + // THE METHOD CAN BE CALLED WHATEVER - But make sure it takes in the same parameters as the method you are mixing into ('mixin') + // 1. What's the 'CallbackInfoReturnable cir' here? This can be the item we return with inside our injection. You need to picture the code in this + // function as literally being copied+pasted into what you are injecting into (at the 'HEAD', in this case). + // 2. Why is this function 'void' if dropItem is not? -> The last parameter actually covers this case if we need to return but it's not required - remember this is a copy and + // paste of code into the function itself so it's not really relevant that our MIXIN function here returns anything + public void dropItem0(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable cir) { + // WHY THE CAST LIKE THIS? + // This is the starting work required to get 'this' from the perspective of PlayerEntity + // 1. Remember that 'this' is actually NOT the PlayerEntity class, but we want to use the methods and functions from that class + // 2. Casting (Object) 'this' gets us the 'PlayerMixin' class as a general object that we can cast into anything else + // 3. Casting '(Object) this' into 'PlayerEntity' gets us to the mixin inject - and NOW we can store the result of this cast into the type we want as a reference + // which is the 'PlayerEntity' on the left hand side. Now we can access stuff from that class AS IF WE ARE CODING INSIDE OF THAT CLASS :))) + PlayerEntity player = (PlayerEntity) (Object) this; + Keeblarcraft.LOGGER.info("PLAYER MIXIN: " + player.getEntityName()); + } +} diff --git a/src/main/resources/assets/keeblarcraft/textures/gui/faction_base_block.png b/src/main/resources/assets/keeblarcraft/textures/gui/faction_base_block.png new file mode 100644 index 0000000000000000000000000000000000000000..10d6377b3f07bf6a3069361d3303f7b7ffeb3b45 GIT binary patch literal 7683 zcmeHMc|4Ts+keJdmT;m~8ABmvj4^{5yRl6gWUWwU!(hyq#h^s#B&X7HibShYw5YTp zOQ%z|B3rgZr!>iyM2PV|Go;S@JLmnKKJWYceBM8Ld~VP6-1l{Tuk~J@XOi7rofPGk z$pHYMNN~3I000O`LV$TP;LV?XF$laprEMSt5eRF5dEf)c36T;riT**pp(P-afF#JV z8*D#;^b8OHEQ3gk>3v}T@>%)_NbAn>h-8c)5`ZFj&jcF^q*cLtF4*WvGrCGZT6E15 z|CvevVva9&Cj!wOib5D65yobqJQ9V*8KH0}6x7HRhs5B}W}tq^>8}=vklJ$mtU>#C z(eZe90v-=#v6(^ia2fzaXT}|}bber?{&0)uEts0@r9EcUi>^`YRU&h}b?tuk(7*XE zklnKwO?US2SC?+ynW(YXTXu19zzTn9+xL>cx85hzIjo)B;t`_q>VBm4i;k_&izRo( zrso7Xsk&pTogY%jtBcmiY*zUlDudjMNKT*dN2MnS#tM@Tr>LoUek))jgviud)f_vF==m z^_!O(QIiCA2tb|cYx2o^J#Q2Jt*F~oXxIyp!`S&02Vx^du`xuAg;qv zm<$Ao$|Tbe(F~R-VSt5oG>b$Dqj8~RS};Ar5;j;=3WL(AmM~uo5lLj>X(4pyST@Zw z*42v=8%DuWVb)f17ST8mfI;JupwW!*2o5gV5+=sQfwZXG5C#>qaKkKN8^AikGubpK z8i7V2;SSOCC=|>}4r;-s2H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<`nz#;7(qh z^|@7{8u%&6vKF(`424g>^vCd90+OTslkNSJqaWY6U0U6JxS>0>p{H%w)f$b~CVNC11TH_U(WLwU?=K|3o9C3?VvztqN%v0YG51 znb|S^sv~%;uIp~?1~idy!{A=oFE&R!6}qW;^Uz(>wat981GGwSf_;s%L1hp7mlAa!skST?n-7W=vidLFT}!&J!ITAG4~Ksr zC@9b(`bF`y)ODD0w`v@=1)Fhoo|LMVj}-Zf`z@(NH;Ef-klm_yZ0jWnN}2?8T;_G6 zH&aiilWm550{*`E?{g!O5Fk3Lu2sGy;ptkJmU!YpZdnU|gW55@ndBxMUM|c+`X5$! zfP7q6w>}EtepU;}%F8=Yydy4gVZzUciY19r^GADv7X$wvt^~=h>6T^gDtj7zUW@D@ MIJnwhwF}(&U#2#BTmS$7 literal 0 HcmV?d00001 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e9b1b75..7e18dc9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,6 +28,9 @@ "jesse.keeblarcraft.world.biome.ModTerrablenderAPI" ] }, + "mixins": [ + "keeblarcraft.mixins.json" + ], "depends": { "fabricloader": ">=0.15.11", "minecraft": "~1.20", diff --git a/src/main/resources/keeblarcraft.mixins.json b/src/main/resources/keeblarcraft.mixins.json new file mode 100644 index 0000000..8c36171 --- /dev/null +++ b/src/main/resources/keeblarcraft.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "jesse.keeblarcraft.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "PlayerMixin" + ], + "client": [], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file