[factions-and-banking] More work on the faction base block + mixin example of player drop
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
a7f8504c2c
commit
20e0325493
@ -13,7 +13,8 @@ import net.minecraft.text.Text;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class FactionBlockScreen extends HandledScreen<FactionBlockScreenHandler> {
|
public class FactionBlockScreen extends HandledScreen<FactionBlockScreenHandler> {
|
||||||
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) {
|
public FactionBlockScreen(FactionBlockScreenHandler handler, PlayerInventory inventory, Text title) {
|
||||||
super(handler, inventory, title);
|
super(handler, inventory, title);
|
||||||
|
@ -267,7 +267,7 @@ public final class BankManager {
|
|||||||
boolean defaultServerBank = bankIdentifier == null || bankIdentifier == "";
|
boolean defaultServerBank = bankIdentifier == null || bankIdentifier == "";
|
||||||
System.out.println("value of bankIdentifier is " + defaultServerBank);
|
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
|
// DEBUG
|
||||||
|
|
||||||
@ -278,14 +278,14 @@ public final class BankManager {
|
|||||||
|
|
||||||
// Create an account via the server-owned bank account
|
// Create an account via the server-owned bank account
|
||||||
if (defaultServerBank) {
|
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 {
|
} else {
|
||||||
System.out.println("Creating bank on non-server owned bank");
|
System.out.println("Creating bank on non-server owned bank");
|
||||||
// Create an account via a specified bank identifier
|
// Create an account via a specified bank identifier
|
||||||
Integer routingNumber = Integer.parseInt(bankIdentifier);
|
Integer routingNumber = Integer.parseInt(bankIdentifier);
|
||||||
|
|
||||||
if (banks.containsKey(routingNumber)) {
|
if (banks.containsKey(routingNumber)) {
|
||||||
banks.get(routingNumber).CreateAccount(player.getUuidAsString(), player.getDisplayName().getString(), accountType);
|
banks.get(routingNumber).CreateAccount(player.getUuidAsString(), player.getEntityName(), accountType);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(Text.of("That bank does not exist"));
|
player.sendMessage(Text.of("That bank does not exist"));
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ public class BankCommands {
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
public void AdminCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
public void AdminCommand(ServerPlayerEntity sourcePlayer, List<String> argList) {
|
||||||
// The player must be opped & the size must be at LEAST 2 (1 keyword + extra for sublist)
|
// 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"));
|
System.out.println("Is player admin? " + (IsOperator(sourcePlayer) ? "YES" : "NO"));
|
||||||
if (IsOperator(sourcePlayer) && argList.size() >= 1) {
|
if (IsOperator(sourcePlayer) && argList.size() >= 1) {
|
||||||
String arg = argList.get(0);
|
String arg = argList.get(0);
|
||||||
|
@ -126,6 +126,7 @@ public class MiscCommands {
|
|||||||
|
|
||||||
public int SetNickname(ServerPlayerEntity player, String name) {
|
public int SetNickname(ServerPlayerEntity player, String name) {
|
||||||
player.setCustomName(Text.of(name));
|
player.setCustomName(Text.of(name));
|
||||||
|
player.setCustomNameVisible(true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
||||||
import jesse.keeblarcraft.Utils.ChatUtil;
|
import jesse.keeblarcraft.Utils.ChatUtil;
|
||||||
|
import jesse.keeblarcraft.Utils.PlayerChecks;
|
||||||
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
import jesse.keeblarcraft.Utils.ChatUtil.CONSOLE_COLOR;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.command.argument.EntityArgumentType;
|
import net.minecraft.command.argument.EntityArgumentType;
|
||||||
@ -40,17 +41,13 @@ public class ShortcutCommands {
|
|||||||
|
|
||||||
// Fly command
|
// Fly command
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
dispatcher.register(CommandManager.literal("fly")
|
var flightNode = CommandManager.literal("fly").executes(context -> FlightSpeedShortcut(null, context)).build();
|
||||||
.executes(context -> { FlightShortcut(context);
|
|
||||||
return 0;
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fly command with speed
|
var flightSpeed = CommandManager.argument("value", IntegerArgumentType.integer())
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
.executes(context -> FlightSpeedShortcut(IntegerArgumentType.getInteger(context, "value"), context)).build();
|
||||||
dispatcher.register(CommandManager.literal("fly")
|
|
||||||
.then(CommandManager.argument("value", IntegerArgumentType.integer())
|
dispatcher.getRoot().addChild(flightNode);
|
||||||
.executes(context -> FlightSpeedShortcut(IntegerArgumentType.getInteger(context, "value"), context))));
|
flightNode.addChild(flightSpeed);
|
||||||
});
|
});
|
||||||
|
|
||||||
///TODO: Read TODO on function
|
///TODO: Read TODO on function
|
||||||
@ -61,16 +58,21 @@ public class ShortcutCommands {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
dispatcher.register(CommandManager.literal("heal")
|
var healNode = CommandManager.literal("heal").executes(context -> HealShortcut(context, null)).build();
|
||||||
.executes(context -> { HealShortcut(context, null);
|
var targetPlayer = CommandManager.argument("targetPlayer", EntityArgumentType.player())
|
||||||
return 0;
|
.executes(context -> HealShortcut(context, EntityArgumentType.getPlayer(context, "targetPlayer"))).build();
|
||||||
}));
|
|
||||||
|
dispatcher.getRoot().addChild(healNode);
|
||||||
|
healNode.addChild(targetPlayer);
|
||||||
});
|
});
|
||||||
|
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
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())
|
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) -> {
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||||||
@ -118,7 +120,6 @@ public class ShortcutCommands {
|
|||||||
retValue = -1;
|
retValue = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
player.sendMessage(Text.literal("\033[31m You do not have permissions to run this command! \033[0m"));
|
player.sendMessage(Text.literal("\033[31m You do not have permissions to run this command! \033[0m"));
|
||||||
@ -127,39 +128,24 @@ public class ShortcutCommands {
|
|||||||
else {
|
else {
|
||||||
System.out.println(ChatUtil.ColoredString("This command cannot be executed by a non-player entity!", CONSOLE_COLOR.RED));
|
System.out.println(ChatUtil.ColoredString("This command cannot be executed by a non-player entity!", CONSOLE_COLOR.RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int FlightShortcut(CommandContext<ServerCommandSource> context) {
|
private int FlightSpeedShortcut(Integer value, CommandContext<ServerCommandSource> context) {
|
||||||
int retValue = -1;
|
if (PlayerChecks.HasPermission(context)) {
|
||||||
if (context.getSource().isExecutedByPlayer()) {
|
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
|
|
||||||
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
|
|
||||||
player.sendAbilitiesUpdate();
|
|
||||||
ChatUtil.SendPlayerMsg(player, "You can now fly! Flight speed is " + abilities.getFlySpeed());
|
|
||||||
} else {
|
|
||||||
player.sendMessage(Text.literal("You do not have permission for this command"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int FlightSpeedShortcut(int value, CommandContext<ServerCommandSource> context) {
|
|
||||||
int retValue = -1;
|
|
||||||
|
|
||||||
if (context.getSource().isExecutedByPlayer()) {
|
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
||||||
|
|
||||||
if (player.hasPermissionLevel(4)) {
|
|
||||||
PlayerAbilities abilities = player.getAbilities();
|
PlayerAbilities abilities = player.getAbilities();
|
||||||
|
|
||||||
if (value >= 1 && value <= 10) {
|
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.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!
|
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();
|
player.sendAbilitiesUpdate();
|
||||||
@ -167,12 +153,9 @@ public class ShortcutCommands {
|
|||||||
} else {
|
} else {
|
||||||
player.sendMessage(Text.literal("Only values from 1-10 are accepted"));
|
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
|
///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,7 +185,7 @@ public class ShortcutCommands {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
private int FeedShortcut(CommandContext<ServerCommandSource> context, ServerPlayerEntity target) {
|
private int FeedShortcut(CommandContext<ServerCommandSource> context, ServerPlayerEntity target) {
|
||||||
|
if (PlayerChecks.HasPermission(context)) {
|
||||||
// if target is null, feed ourselves
|
// if target is null, feed ourselves
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||||
@ -216,11 +199,13 @@ public class ShortcutCommands {
|
|||||||
target.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10!
|
target.getHungerManager().setSaturationLevel(10.0f); // 5 is set in constructor, but let's try 10!
|
||||||
ChatUtil.SendPlayerMsg(target, "You were just super fed!");
|
ChatUtil.SendPlayerMsg(target, "You were just super fed!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int HealShortcut(CommandContext<ServerCommandSource> context, ServerPlayerEntity target) {
|
private int HealShortcut(CommandContext<ServerCommandSource> context, ServerPlayerEntity target) {
|
||||||
int retValue = -1;
|
int retValue = -1;
|
||||||
|
if (PlayerChecks.HasPermission(context)) {
|
||||||
// If no player specified; then heal ourself full HP
|
// If no player specified; then heal ourself full HP
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
context.getSource().getPlayer().setHealth(context.getSource().getPlayer().getMaxHealth());
|
context.getSource().getPlayer().setHealth(context.getSource().getPlayer().getMaxHealth());
|
||||||
@ -228,9 +213,9 @@ public class ShortcutCommands {
|
|||||||
} else {
|
} else {
|
||||||
target.setHealth(target.getMaxHealth());
|
target.setHealth(target.getMaxHealth());
|
||||||
ChatUtil.SendPlayerMsg(target, "You were just healed!");
|
ChatUtil.SendPlayerMsg(target, "You were just healed!");
|
||||||
ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "You healed " + target.getDisplayName());
|
ChatUtil.SendPlayerMsg(context.getSource().getPlayer(), "You healed " + target.getEntityName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import jesse.keeblarcraft.world.ImplementedInventory;
|
|||||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
|
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.inventory.Inventories;
|
import net.minecraft.inventory.Inventories;
|
||||||
@ -21,13 +20,13 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory {
|
public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory {
|
||||||
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(4, ItemStack.EMPTY);
|
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize(7, ItemStack.EMPTY);
|
||||||
|
|
||||||
private static final int DEFENSE_SLOT_ONE = 0;
|
private static final int DEFENSE_SLOT_ONE = 0;
|
||||||
private static final int DEFENSE_SLOT_TWO = 1;
|
private static final int DEFENSE_SLOT_TWO = 1;
|
||||||
private static final int OFFENSE_SLOT_ONE = 2;
|
private static final int OFFENSE_SLOT_ONE = 2;
|
||||||
private static final int OFFENSE_SLOT_TWO = 3;
|
private static final int OFFENSE_SLOT_TWO = 3;
|
||||||
private static int power = 0;
|
private static int factionPower = 0;
|
||||||
|
|
||||||
protected final PropertyDelegate propertyDelegate;
|
protected final PropertyDelegate propertyDelegate;
|
||||||
|
|
||||||
@ -37,20 +36,22 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int get(int index) {
|
public int get(int index) {
|
||||||
|
// The only value we need to get/delegate is faction power
|
||||||
return switch(index) {
|
return switch(index) {
|
||||||
default -> power;
|
default -> factionPower;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(int index, int value) {
|
public void set(int index, int value) {
|
||||||
switch(index) {
|
switch(index) {
|
||||||
default -> power = value;
|
default -> factionPower = value;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
|
// We are only sync'ing 1 integer - faction power
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,14 +72,15 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
public void readNbt(NbtCompound nbt) {
|
public void readNbt(NbtCompound nbt) {
|
||||||
super.readNbt(nbt);
|
super.readNbt(nbt);
|
||||||
Inventories.readNbt(nbt, inventory);
|
Inventories.readNbt(nbt, inventory);
|
||||||
power = nbt.getInt("faction_block_entity.power");
|
factionPower = nbt.getInt("faction_block_entity.power");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeNbt(NbtCompound nbt) {
|
public void writeNbt(NbtCompound nbt) {
|
||||||
super.writeNbt(nbt);
|
super.writeNbt(nbt);
|
||||||
Inventories.writeNbt(nbt, inventory); // Write our inventory when world is saved; etc
|
// Write the inventory of the block
|
||||||
nbt.putInt("faction_block_entity.power", power);
|
Inventories.writeNbt(nbt, inventory);
|
||||||
|
nbt.putInt("faction_block_entity.power", factionPower);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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?
|
// 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?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package jesse.keeblarcraft.CustomBlocks.Blocks;
|
package jesse.keeblarcraft.CustomBlocks.Blocks;
|
||||||
|
|
||||||
import javax.swing.text.html.BlockView;
|
|
||||||
|
|
||||||
import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration;
|
import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration;
|
||||||
import jesse.keeblarcraft.CustomBlocks.BlockEntities.FactionBlockEntity;
|
import jesse.keeblarcraft.CustomBlocks.BlockEntities.FactionBlockEntity;
|
||||||
import net.minecraft.block.*;
|
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) {
|
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
|
// 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
|
// request information about this block entity from the server
|
||||||
|
System.out.println("onUse of faction base block called");
|
||||||
if (!world.isClient()) {
|
if (!world.isClient()) {
|
||||||
NamedScreenHandlerFactory screenHandlerFactory = (FactionBlockEntity) world.getBlockEntity(pos);
|
NamedScreenHandlerFactory screenHandlerFactory = (FactionBlockEntity) world.getBlockEntity(pos);
|
||||||
|
|
||||||
|
@ -65,5 +65,4 @@ public class ItemManager {
|
|||||||
// Item exampleItem = new Item(new FabricItemSettings());
|
// Item exampleItem = new Item(new FabricItemSettings());
|
||||||
// RegisterItem("metaljacket_helmet", exampleItem);
|
// RegisterItem("metaljacket_helmet", exampleItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -502,7 +502,6 @@ public class FactionConfig {
|
|||||||
|
|
||||||
System.out.println("ListOfFactions - map size: " + allFactions.size());
|
System.out.println("ListOfFactions - map size: " + allFactions.size());
|
||||||
for (Entry<String, WriteableFaction> entry : allFactions.entrySet()) {
|
for (Entry<String, WriteableFaction> entry : allFactions.entrySet()) {
|
||||||
System.out.println("Adding fac " + entry.getKey() + " to fac");
|
|
||||||
facs.add(entry.getKey());
|
facs.add(entry.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +91,9 @@ public class FactionManager {
|
|||||||
String playerFac = factionConfig.factions.FindFactionOfPlayer(player.getUuidAsString());
|
String playerFac = factionConfig.factions.FindFactionOfPlayer(player.getUuidAsString());
|
||||||
|
|
||||||
if (playerFac != "") {
|
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!"));
|
player.sendMessage(Text.of("[Factions]: You left your faction!"));
|
||||||
|
FlashConfig();
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(Text.of("[Factions]: You are not in a faction!"));
|
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());
|
String facOfPlayer = factionConfig.factions.FindFactionOfPlayer(creator.getUuidAsString());
|
||||||
|
|
||||||
if (facOfPlayer == "") {
|
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) {
|
if (!success) {
|
||||||
creator.sendMessage(Text.of("[Factions]: Could not create faction - faction already exists."));
|
creator.sendMessage(Text.of("[Factions]: Could not create faction - faction already exists."));
|
||||||
|
@ -16,24 +16,32 @@ public class FactionBlockScreenHandler extends ScreenHandler {
|
|||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
private final PropertyDelegate propertyDelegate;
|
private final PropertyDelegate propertyDelegate;
|
||||||
public final FactionBlockEntity blockEntity;
|
public final FactionBlockEntity blockEntity;
|
||||||
|
public int factionPower = 0;
|
||||||
|
|
||||||
public FactionBlockScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) {
|
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) {
|
public FactionBlockScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity, PropertyDelegate arrayPropertyDelegate) {
|
||||||
super(ScreenHandlerRegistration.FACTION_BLOCK_SCREEN_HANDLER, syncId);
|
super(ScreenHandlerRegistration.FACTION_BLOCK_SCREEN_HANDLER, syncId);
|
||||||
checkSize((Inventory) blockEntity, 4);
|
checkSize((Inventory) blockEntity, 7);
|
||||||
this.inventory = (Inventory) blockEntity;
|
this.inventory = (Inventory) blockEntity;
|
||||||
inventory.onOpen(playerInventory.player);
|
inventory.onOpen(playerInventory.player);
|
||||||
this.propertyDelegate = arrayPropertyDelegate;
|
this.propertyDelegate = arrayPropertyDelegate;
|
||||||
this.blockEntity = (FactionBlockEntity) blockEntity;
|
this.blockEntity = (FactionBlockEntity) blockEntity;
|
||||||
|
|
||||||
// TODO: These positions need to be redrawn with an actual GUI
|
// Need a better way of storing these coordinates...
|
||||||
this.addSlot(new Slot(inventory, 0, 60, 11));
|
this.addSlot(new Slot(inventory, 0, 20, 11)); // top row
|
||||||
this.addSlot(new Slot(inventory, 1, 70, 11));
|
this.addSlot(new Slot(inventory, 1, 20, 39));
|
||||||
this.addSlot(new Slot(inventory, 2, 80, 11));
|
this.addSlot(new Slot(inventory, 2, 49, 11));
|
||||||
this.addSlot(new Slot(inventory, 3, 90, 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
|
// 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
|
// 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);
|
addProperties(arrayPropertyDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer GetFactionPower() {
|
||||||
|
factionPower = this.propertyDelegate.get(0);
|
||||||
|
return factionPower;
|
||||||
|
}
|
||||||
|
|
||||||
// This is just for SHIFT+CLICK moving
|
// This is just for SHIFT+CLICK moving
|
||||||
@Override
|
@Override
|
||||||
public ItemStack quickMove(PlayerEntity player, int invSlot) {
|
public ItemStack quickMove(PlayerEntity player, int invSlot) {
|
||||||
@ -64,10 +77,32 @@ public class FactionBlockScreenHandler extends ScreenHandler {
|
|||||||
slot.markDirty();;
|
slot.markDirty();;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newStack;
|
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
|
@Override
|
||||||
public boolean canUse(PlayerEntity player) {
|
public boolean canUse(PlayerEntity player) {
|
||||||
return this.inventory.canPlayerUse(player);
|
return this.inventory.canPlayerUse(player);
|
||||||
|
26
src/main/java/jesse/keeblarcraft/Utils/PlayerChecks.java
Normal file
26
src/main/java/jesse/keeblarcraft/Utils/PlayerChecks.java
Normal file
@ -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<ServerCommandSource> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
src/main/java/jesse/keeblarcraft/mixin/PlayerMixin.java
Normal file
53
src/main/java/jesse/keeblarcraft/mixin/PlayerMixin.java
Normal file
@ -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<ItemEntity> 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<ItemEntity> 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());
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
@ -28,6 +28,9 @@
|
|||||||
"jesse.keeblarcraft.world.biome.ModTerrablenderAPI"
|
"jesse.keeblarcraft.world.biome.ModTerrablenderAPI"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"mixins": [
|
||||||
|
"keeblarcraft.mixins.json"
|
||||||
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.15.11",
|
"fabricloader": ">=0.15.11",
|
||||||
"minecraft": "~1.20",
|
"minecraft": "~1.20",
|
||||||
|
13
src/main/resources/keeblarcraft.mixins.json
Normal file
13
src/main/resources/keeblarcraft.mixins.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "jesse.keeblarcraft.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"mixins": [
|
||||||
|
"PlayerMixin"
|
||||||
|
],
|
||||||
|
"client": [],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user