[factions-banking] Added some of the commissioned art to the game to get ready to add the faction upgrades. Corrected faction block behavior to have to be unique & make it so only one can be placed. Probably some other things too
Some checks are pending
build / build (21) (push) Waiting to run

This commit is contained in:
Jkibbels 2025-01-26 00:25:07 -05:00
parent 4becbd8f45
commit 2d926310cf
18 changed files with 275 additions and 66 deletions

View File

@ -24,20 +24,14 @@ public class ChatFormatting {
/////////////////////////////////////////////////////////////////////////////
public static String GetColor(COLOR_CODE code) {
String colorStr = COLOR_START;
switch(code) {
case BLUE:
return colorStr + "9";
case GRAY:
return colorStr + "7";
case GOLD:
return colorStr + "6";
case RED:
return colorStr + "4";
case GREEN:
return colorStr + "2";
}
return switch (code) {
case BLUE -> colorStr + "9";
case GRAY -> colorStr + "7";
case GOLD -> colorStr + "6";
case RED -> colorStr + "4";
case GREEN -> colorStr + "2";
};
// If this code is reachable, then someone has not properly handled the above switch-case
return colorStr;
}
}

View File

@ -178,7 +178,7 @@ public class ChatMsg {
///
/// @return Formatted string of colored text
/////////////////////////////////////////////////////////////////////////////
public String ColorMsg(String msg, COLOR_CODE color) {
public static String ColorMsg(String msg, COLOR_CODE color) {
return ChatFormatting.GetColor(color) + msg + ChatFormatting.COLOR_END;
}

View File

@ -70,8 +70,6 @@ public class GeneralConfig {
/// set yet.
/////////////////////////////////////////////////////////////////////////////
public DirectionalVec GetSpawnCoords() {
System.out.println("Among us");
System.out.println("GetSpawnCoords called. is global_spawn null? " + (config.global_spawn == null ? "YES": "NO"));
return config.global_spawn;
}

View File

@ -36,17 +36,14 @@ import net.minecraft.world.World;
public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory {
private final DefaultedList<ItemStack> 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 String faction; // Faction this block belongs to
private String faction = null; // Faction this block belongs to
private static int factionPower = 0;
private FactionTierEnum factionTier = FactionTierEnum.TIER_INVALID;
Boolean stopMobSpawn = true;
Boolean hasBuildFlight = true;
Boolean hasSuperBeacon = true;
Position3d storedBlockPos;
private Boolean hasStopMobSpawn = true;
private Boolean registeredMobSpawnCallback = false;
private Boolean hasBuildFlight = true;
private Boolean hasSuperBeacon = true;
private Position3d storedBlockPos;
private final double factionDefaultRadiusBlocks = 50; // 50 blocks
private ArrayList<String> playersInRadius = new ArrayList<>();
private HashMap<String, FactionConfig.VALID_FACTION_ROLES> factionPlayers;
@ -56,17 +53,17 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
public FactionBlockEntity(BlockPos pos, BlockState state, String faction) {
this(pos, state);
this.faction = faction;
MobSpawnCallback.EVENT.register((world, mob) -> {
HandleMobSpawn(world, mob);
return ActionResult.PASS;
});
RegisterMobSpawn();
}
public void SetFaction(String faction) {
this.faction = faction;
}
public String GetFaction() {
return this.faction;
}
public FactionBlockEntity(BlockPos pos, BlockState state) {
super(BlockEntityRegistration.FACTION_BLOCK_ENTITY, pos, state);
storedBlockPos = new Position3d(pos.getX(), pos.getY(), pos.getZ());
@ -91,13 +88,22 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
};
}
private void RegisterMobSpawn() {
if (hasStopMobSpawn && !registeredMobSpawnCallback) {
MobSpawnCallback.EVENT.register((world, mob) -> {
HandleMobSpawn(world, mob);
return ActionResult.PASS;
});
}
}
// TODO: Make sure mobs are within range before targeting!
private void HandleMobSpawn(World world, MobEntity mob) {
if (world.isClient()) {
return;
}
mob.kill();
mob.setDespawnCounter(0);
}
@Override
@ -146,11 +152,9 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
Math.abs(Math.pow(Math.floor(z) - storedBlockPos.z, 2))));
// Arbitrarily for now; each point of faction power increases the distance by 10. Testing will confirm if this
// is too much or too little. Making this configurable would probably be good too
// is too much or too little. Making this configurable would probably be good to
// Default radius; increased by power
double factionBlockRadius = factionDefaultRadiusBlocks + (10 * factionPower);
System.out.println("Dist: " + dist);
return Math.ceil(dist) <= factionBlockRadius;
}
@ -163,7 +167,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
// Call when the block attached to this entity is broken so we can send out our last messages to reset players correctly before perishing
public void ResetBlock() {
System.out.println("Reset block called. Is world null? " + (world==null?"YES":"NO"));
System.out.println("Reset block called. Is world null? " + (world == null ? "YES" : "NO"));
if (world != null) {
for (PlayerEntity player : world.getPlayers()) {
Boolean isPlayerInFactionRadius = IsPlayerInBounds(player, pos);
@ -172,7 +176,17 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
}
}
} else {
System.out.println("Error, world is null and factionblockentity cannot reset players!");
System.out.println("Error, world is null and FactionBlockEntity cannot reset players!");
}
}
// TODO: There has GOT to be a better way of validating the inventory than this... but it's okay for now! *cries*
public void ValidateInventory() {
// Slots 1, 3, 5 are ATTACK/PASSIVE slots
// Slots 2, 4, 6 are DEFENSE/PASSIVE slots
// Slot 7 is the special slot reserved EXCLUSIVELY for LEGENDARY Tier only! Legendary CANNOT go in other slots!
for (ItemStack item : inventory) {
}
}

View File

@ -1,5 +1,9 @@
package jesse.keeblarcraft.CustomBlocks.Blocks;
import jesse.keeblarcraft.ChatStuff.ChatFormatting;
import jesse.keeblarcraft.ChatStuff.ChatMsg;
import jesse.keeblarcraft.FactionMgr.FactionConfig;
import jesse.keeblarcraft.Utils.CommonStructures.Position3d;
import org.jetbrains.annotations.Nullable;
import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration;
@ -46,29 +50,40 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
return;
}
if (placer.isPlayer()) {
if (placer != null && placer.isPlayer()) {
// We need to run faction checks here and make sure this player owns a faction otherwise they are NOT allowed to place it!
ServerPlayerEntity player = (ServerPlayerEntity) placer;
String fac = FactionManager.GetInstance().GetFactionOfPlayer(player.getUuidAsString());
FactionBlockEntity bEntity = (FactionBlockEntity) world.getBlockEntity(pos);
// We need to verify the faction does not already have a block placed in the world; and make sure the placer
// is the owner of the faction.
Boolean canPlaceFactionBlock = FactionManager.GetInstance().CanPlaceFactionBlock(fac);
System.out.println("hasFacBlock: " + canPlaceFactionBlock);
FactionConfig.VALID_FACTION_ROLES role = FactionManager.GetInstance().GetPlayerRole(fac, placer.getUuidAsString());
System.out.println("Can place block?: " + canPlaceFactionBlock);
System.out.println("Role: " + role.name());
// Update block entity
if (canPlaceFactionBlock && role == FactionConfig.VALID_FACTION_ROLES.OWNER) {
FactionBlockEntity bEntity = (FactionBlockEntity) world.getBlockEntity(pos);
// Update block entity - this is the "ultimate success" portion
if (bEntity != null) {
bEntity.SetFaction(fac);
// Enable chunk loading
world.getChunkManager().setChunkForced(world.getChunk(pos).getPos(), true);
}
// An empty string implies NO faction; only do things if it is NOT empty
if (!fac.isEmpty()) {
faction = fac;
player.sendMessage(Text.of("This block now belongs to the " + faction + " faction."));
FactionManager.GetInstance().SetFactionBlock(faction, new Position3d(pos.getX(), pos.getY(), pos.getZ()));
player.sendMessage(Text.of(ChatMsg.ColorMsg("This block now begins to the " + fac + " faction!", ChatFormatting.COLOR_CODE.GOLD)));
}
} else if (canPlaceFactionBlock) {
player.sendMessage(Text.of(ChatMsg.ColorMsg("You cannot place more than one faction block per faction!", ChatFormatting.COLOR_CODE.RED)));
world.breakBlock(pos, true);
} else {
player.sendMessage(Text.of("You do not appear to be in a faction, and thus this block cannot be placed!"));
// world.removeBlock(pos, false);
player.sendMessage(Text.of(ChatMsg.ColorMsg("You do not appear to be in a faction or are not the leader of this faction. You cannot place this block!", ChatFormatting.COLOR_CODE.RED)));
world.breakBlock(pos, true);
}
} else {
// Only a player should be able to place the block in order to set faction appropriately. Destroy!
world.breakBlock(pos, true);
}
}
@ -94,10 +109,11 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
if (bEntity != null) {
bEntity.ResetBlock();
}
}t
}
// Disable chunk loading
world.getChunkManager().setChunkForced(world.getChunk(pos).getPos(), false);
FactionManager.GetInstance().RemoveFactionBlock(faction, new Position3d(pos.getX(), pos.getY(), pos.getZ()));
super.onStateReplaced(state, world, pos, newState, moved);
}
}

View File

@ -13,7 +13,10 @@ package jesse.keeblarcraft.CustomItems;
import java.util.ArrayList;
import java.util.List;
import jesse.keeblarcraft.CustomItems.Items.FactionBeaconItem;
import jesse.keeblarcraft.CustomItems.Items.FactionFlightItem;
import jesse.keeblarcraft.Keeblarcraft;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
@ -34,7 +37,8 @@ public class ItemManager {
/// 1. The name provided here must match these names:
/// * This items models/item name
/// * This items textures/item name
/// 2 Name must be lowercase & no special characters besides '_'
/// 2. Name must be lowercase & no special characters besides '_'
/// 3. Do NOT provide the Mod ID inside the name part
///
/// @arg[in] item is the item to be added to the item list
///
@ -62,7 +66,7 @@ public class ItemManager {
CustomItemGroups.RegisterGroups();
// The example item provides a demo of how you could make an item in your class
// Item exampleItem = new Item(new FabricItemSettings());
// RegisterItem("metaljacket_helmet", exampleItem);
RegisterItem("faction_upgrade_flight", new FactionFlightItem(new FabricItemSettings().maxCount(1)));
RegisterItem("faction_upgrade_beacon", new FactionBeaconItem(new FabricItemSettings().maxCount(1)));
}
}

View File

@ -0,0 +1,28 @@
package jesse.keeblarcraft.CustomItems.Items;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class FactionBeaconItem extends Item {
public FactionBeaconItem(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (world.isClient()) {
user.sendMessage(Text.of("This item can only be placed inside the faction home block!"));
}
return super.use(world, user, hand);
}
@Override
public boolean isDamageable() {
return false;
}
}

View File

@ -0,0 +1,28 @@
package jesse.keeblarcraft.CustomItems.Items;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class FactionFlightItem extends Item {
public FactionFlightItem(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
if (world.isClient()) {
user.sendMessage(Text.of("This item can only be placed inside the faction home block!"));
}
return super.use(world, user, hand);
}
@Override
public boolean isDamageable() {
return false;
}
}

View File

@ -0,0 +1,24 @@
package jesse.keeblarcraft.FactionMgr;
import java.util.Map;
import static java.util.Map.entry;
// This class is going to keep track of everything related to items that the faction block is allowed to accept and
// information regarding those items.
public class FactionBlockItems {
public static enum ITEM_TIER {
COMMON,
UNCOMMON,
RARE,
VERY_RARE,
LEGENDARY
}
// TODO: Need to add the Item information for these down below; but I haven't made them yet! The string should
// make it obvious what needs to go here though.
public static Map<String, ITEM_TIER> FACTION_UPGRADES = Map.ofEntries(
entry("keeblarcraft:faction_flight", ITEM_TIER.UNCOMMON),
entry("keeblarcraft:faction_beacon", ITEM_TIER.RARE)
);
}

View File

@ -9,6 +9,7 @@
package jesse.keeblarcraft.FactionMgr;
import jesse.keeblarcraft.Utils.CommonStructures.Pair;
import jesse.keeblarcraft.Utils.CommonStructures.Position3d;
import static java.util.Map.entry;
@ -30,7 +31,8 @@ public class FactionConfig {
OWNER,
COOWNER,
MANAGEMENT,
EMPLOYEE
EMPLOYEE,
INVALID
}
private static Map<VALID_FACTION_ROLES, Integer> ROLE_LEVELS = Map.ofEntries
@ -50,6 +52,7 @@ public class FactionConfig {
entry (3, VALID_FACTION_ROLES.OWNER)
);
// This is the actual faction configuration object that is written to a json file
public static class WriteableFaction {
// Key = Player UUID
// Val = Faction role of player
@ -62,6 +65,9 @@ public class FactionConfig {
// TODO: Refactor to map so players can un-invite by name not UUID...
List<String> openInvites = new ArrayList<String>();
Position3d factionBlockLocation; // May be null until faction places it; but only one can be placed!
int numFactionBlocks = 0;
Integer factionBankBalance;
Integer factionPower;
String factionName;
@ -94,6 +100,38 @@ public class FactionConfig {
return success;
}
public void SetFactionBlock(String factionName, Position3d blockPos) {
if (IsValid(factionName) && blockPos != null) {
allFactions.get(factionName).numFactionBlocks++;
allFactions.get(factionName).factionBlockLocation = blockPos;
}
}
public void RemoveFactionBlock(String factionName) {
if (IsValid(factionName)) {
allFactions.get(factionName).factionBlockLocation = null;
allFactions.get(factionName).numFactionBlocks--;
}
}
public Position3d GetFactionBlock(String factionName) {
Position3d blockLoc = null;
if (IsValid(factionName)){
blockLoc = allFactions.get(factionName).factionBlockLocation;
}
return blockLoc;
}
// Will return amount of faction blocks in a faction, where any number less than 0 should be treated
// as an invalid case where the faction may have not existed when this function was called.
public Integer GetNumberOfFactionBlocks(String factionName) {
int amount = -1;
if (IsValid(factionName)) {
amount = allFactions.get(factionName).numFactionBlocks;
}
return amount;
}
// It is assumed that the person calling this function has verified that the person
// can in fact set faction power. This is generally just an admin command
public Boolean SetPower(String factionName, Integer amount) {
@ -147,6 +185,15 @@ public class FactionConfig {
return players;
}
public VALID_FACTION_ROLES GetPlayerRole(String factionName, String playerUuid) {
VALID_FACTION_ROLES role = VALID_FACTION_ROLES.INVALID;
// Check to make sure faction exists & player is in faction
if (IsValid(factionName) && allFactions.get(factionName).factionPlayerList.containsKey(playerUuid)) {
role = allFactions.get(factionName).factionPlayerList.get(playerUuid);
}
return role;
}
/////////////////////////////////////////////////////////////////////////////
/// @fn DeleteFaction
///
@ -353,11 +400,7 @@ public class FactionConfig {
/// @return True if a faction exists with the specified name, false if not
/////////////////////////////////////////////////////////////////////////////
public Boolean IsValid(String factionName) {
if (allFactions.containsKey(factionName)) {
return true;
} else {
return false;
}
return allFactions.containsKey(factionName);
}
/////////////////////////////////////////////////////////////////////////////

View File

@ -22,6 +22,7 @@ import jesse.keeblarcraft.Keeblarcraft;
import jesse.keeblarcraft.ChatStuff.ChatMenu;
import jesse.keeblarcraft.ChatStuff.ChatMsg;
import jesse.keeblarcraft.ChatStuff.ChatFormatting.COLOR_CODE;
import jesse.keeblarcraft.Utils.CommonStructures.Position3d;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
@ -85,6 +86,40 @@ public class FactionManager {
FactionTier.InitializeFactionTiers();
}
// Returns true if the faction is allowed to place a faction block. False if not
public Boolean CanPlaceFactionBlock(String factionName) {
return factionConfig.factions.GetNumberOfFactionBlocks(factionName) == 0;
}
public void SetFactionBlock(String factionName, Position3d newPos) {
// Only consider the faction block now "placed" if we (the manager) agree there are no others
if (factionConfig.factions.GetNumberOfFactionBlocks(factionName) == 0) {
factionConfig.factions.SetFactionBlock(factionName, newPos);
}
FlashConfig();
}
public void RemoveFactionBlock(String factionName, Position3d blockPos) {
// In order to "remove" a block (NOT from the world, just the manager) - it must be the LAST remaining faction
// block. In general, it should NOT be possible (for now) to set more than one faction block in the world from
// the manager's perspective.
Position3d origBlock = factionConfig.factions.GetFactionBlock(factionName);
if (origBlock != null && origBlock.equals(blockPos)) {
factionConfig.factions.RemoveFactionBlock(factionName);
}
FlashConfig();
}
public int GetNumberOfFactionBlocks(String factionName) {
return factionConfig.factions.GetNumberOfFactionBlocks(factionName);
}
public VALID_FACTION_ROLES GetPlayerRole(String factionName, String uuid) {
return factionConfig.factions.GetPlayerRole(factionName, uuid);
}
// This is purely a chat-based call. Here to help with `/faction info` basically.
public void GetFactionInformation(ServerPlayerEntity player) {
String factionName = GetFactionOfPlayer(player.getUuidAsString());

View File

@ -11,6 +11,7 @@ import net.minecraft.screen.ArrayPropertyDelegate;
import net.minecraft.screen.PropertyDelegate;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import org.jetbrains.annotations.Nullable;
public class FactionBlockScreenHandler extends ScreenHandler {
private final Inventory inventory;
@ -44,10 +45,6 @@ public class FactionBlockScreenHandler extends ScreenHandler {
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
// direction with this block RIGHT NOW - so for now I am NOT doing that
// Remainder stuff
addProperties(arrayPropertyDelegate);
}
@ -60,9 +57,10 @@ public class FactionBlockScreenHandler extends ScreenHandler {
// This is just for SHIFT+CLICK moving
@Override
public ItemStack quickMove(PlayerEntity player, int invSlot) {
System.out.println("Is client: " + player.getWorld().isClient());
ItemStack newStack = ItemStack.EMPTY;
Slot slot = this.slots.get(invSlot);
if (slot != null && slot.hasStack()) {
if (slot.hasStack()) {
ItemStack originalStack = slot.getStack();
newStack = originalStack.copy();

View File

@ -7,6 +7,19 @@ public class Position3d {
this.z = z;
}
@Override
public boolean equals(Object obj) {
boolean isEqual = false;
if (this == obj) {
isEqual = true;
} else if (obj instanceof Position3d castedObj) {
if (castedObj.x == this.x && castedObj.y == this.y && castedObj.z == this.z) {
isEqual = true;
}
}
return isEqual;
}
public int x;
public int y;
public int z;

View File

@ -3,6 +3,8 @@
"item.keeblarcraft.metaljacket_chestplate": "MetalJacket Chestplate",
"item.keeblarcraft.metaljacket_leggings": "MetalJacket Leggings",
"item.keeblarcraft.metaljacket_boots": "MetalJacket Booties",
"item.keeblarcraft.faction_upgrade_flight": "Faction Flight Upgrade",
"item.keeblarcraft.faction_upgrade_beacon": "Faction Beacon Upgrade",
"itemgroup.keeblarcraft": "Keeblarcraft Modded Items",

View File

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "keeblarcraft:item/faction_upgrade_beacon"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "keeblarcraft:item/faction_upgrade_flight"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 KiB