[factions-banking] More adjustments. Chunk load block, bug fixing, faction stuff extension
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
5911c7c775
commit
4becbd8f45
@ -17,9 +17,9 @@ import net.minecraft.util.ActionResult;
|
|||||||
public class FactionBeacon extends AbstractNode {
|
public class FactionBeacon extends AbstractNode {
|
||||||
private int beaconStrength = 1; // Increases with faction power; 1 is default
|
private int beaconStrength = 1; // Increases with faction power; 1 is default
|
||||||
private int potionEffectLastingTimeTicks = 200; // 20 ticks per second makes this 10 seconds
|
private int potionEffectLastingTimeTicks = 200; // 20 ticks per second makes this 10 seconds
|
||||||
private Integer timerLengthMillis = 5000; // The default potion length is 10 seconds; so reset every 5 to be sure!
|
private final Integer timerLengthMillis = 5000; // The default potion length is 10 seconds; so reset every 5 to be sure!
|
||||||
private Boolean resetTimer = true;
|
private Boolean resetTimer = true;
|
||||||
private Timer timer = new Timer();
|
private final Timer timer = new Timer();
|
||||||
@Override
|
@Override
|
||||||
public String GetNodeTitle() {
|
public String GetNodeTitle() {
|
||||||
return "faction_beacon";
|
return "faction_beacon";
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package jesse.keeblarcraft.CustomBlocks.BlockEntities;
|
package jesse.keeblarcraft.CustomBlocks.BlockEntities;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import jesse.keeblarcraft.AttributeMgr.AttributeMgr;
|
import jesse.keeblarcraft.AttributeMgr.AttributeMgr;
|
||||||
import jesse.keeblarcraft.Callbacks.MobSpawnCallback;
|
import jesse.keeblarcraft.Callbacks.MobSpawnCallback;
|
||||||
|
import jesse.keeblarcraft.FactionMgr.FactionConfig;
|
||||||
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
||||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
||||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
||||||
@ -45,7 +47,9 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
Boolean hasBuildFlight = true;
|
Boolean hasBuildFlight = true;
|
||||||
Boolean hasSuperBeacon = true;
|
Boolean hasSuperBeacon = true;
|
||||||
Position3d storedBlockPos;
|
Position3d storedBlockPos;
|
||||||
|
private final double factionDefaultRadiusBlocks = 50; // 50 blocks
|
||||||
private ArrayList<String> playersInRadius = new ArrayList<>();
|
private ArrayList<String> playersInRadius = new ArrayList<>();
|
||||||
|
private HashMap<String, FactionConfig.VALID_FACTION_ROLES> factionPlayers;
|
||||||
|
|
||||||
protected final PropertyDelegate propertyDelegate;
|
protected final PropertyDelegate propertyDelegate;
|
||||||
|
|
||||||
@ -53,7 +57,6 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
this(pos, state);
|
this(pos, state);
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
|
|
||||||
System.out.println("Subscribing to mob spawning");
|
|
||||||
MobSpawnCallback.EVENT.register((world, mob) -> {
|
MobSpawnCallback.EVENT.register((world, mob) -> {
|
||||||
HandleMobSpawn(world, mob);
|
HandleMobSpawn(world, mob);
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
@ -71,21 +74,17 @@ 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
|
// The only value we need to get/delegate is faction power
|
||||||
return switch(index) {
|
return factionPower;
|
||||||
default -> factionPower;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(int index, int value) {
|
public void set(int index, int value) {
|
||||||
switch(index) {
|
factionPower = value;
|
||||||
default -> factionPower = value;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
// We are only sync'ing 1 integer - faction power
|
// We are only syncing 1 integer - faction power
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,22 +136,29 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
buf.writeBlockPos(this.pos);
|
buf.writeBlockPos(this.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is uniquely only calculating the second coordinate on 'storedBlockPos' which is the center coordinate of the
|
||||||
|
// hypothetical sphere
|
||||||
|
private Boolean DistanceToCenterSphere(double x, double y, double z) {
|
||||||
|
// Distance between two points
|
||||||
|
double dist = Math.ceil(Math.sqrt(
|
||||||
|
Math.abs(Math.pow(Math.floor(x) - storedBlockPos.x, 2)) +
|
||||||
|
Math.abs(Math.pow(Math.floor(y) - storedBlockPos.y, 2)) +
|
||||||
|
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
|
||||||
|
// Default radius; increased by power
|
||||||
|
double factionBlockRadius = factionDefaultRadiusBlocks + (10 * factionPower);
|
||||||
|
System.out.println("Dist: " + dist);
|
||||||
|
|
||||||
|
return Math.ceil(dist) <= factionBlockRadius;
|
||||||
|
}
|
||||||
|
|
||||||
private Boolean IsPlayerInBounds(PlayerEntity player, BlockPos pos) {
|
private Boolean IsPlayerInBounds(PlayerEntity player, BlockPos pos) {
|
||||||
Boolean isNearBlock = false;
|
Boolean isNearBlock = false;
|
||||||
String playerFaction = FactionManager.GetInstance().GetFactionOfPlayer(player.getUuidAsString());
|
String playerFaction = FactionManager.GetInstance().GetFactionOfPlayer(player.getUuidAsString());
|
||||||
|
|
||||||
// Verify the player is in the faction to be considered "in bounds"!
|
return playerFaction.equals(faction) && DistanceToCenterSphere(player.getX(), player.getY(), player.getZ());
|
||||||
if (playerFaction.equals(faction)) {
|
|
||||||
// Will check in range - assumes same world! 50 is a temporary value at the moment
|
|
||||||
Boolean xBounds = player.getX() <= pos.getX() + 50 && player.getX() >= pos.getX() - 50;
|
|
||||||
Boolean yBounds = player.getY() <= pos.getY() + 50 && player.getY() >= pos.getY() - 50;
|
|
||||||
Boolean zBounds = player.getZ() <= pos.getZ() + 50 && player.getZ() >= pos.getZ() - 50;
|
|
||||||
if (xBounds && yBounds && zBounds) {
|
|
||||||
isNearBlock = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return isNearBlock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call when the block attached to this entity is broken so we can send out our last messages to reset players correctly before perishing
|
// Call when the block attached to this entity is broken so we can send out our last messages to reset players correctly before perishing
|
||||||
@ -172,13 +178,14 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
|
|
||||||
// Tick method is called 20 times a second
|
// Tick method is called 20 times a second
|
||||||
public void tick(World world, BlockPos pos, BlockState state) {
|
public void tick(World world, BlockPos pos, BlockState state) {
|
||||||
// For reasons unknown to me and only to Kaupenjoe (youtube video) - we never want to call this on a client.
|
|
||||||
if (world.isClient() || faction == null) {
|
if (world.isClient() || faction == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
//TODO: The below values can ABSOLUTELY be moved to a one-time call-out when the block is created & when a player
|
||||||
|
// leaves or joins a faction with a simple callback subscriber. Leaving because not doing now, BUT REFACTOR
|
||||||
|
factionPlayers = FactionManager.GetInstance().GetFactionPlayers(faction);
|
||||||
factionPower = FactionManager.GetInstance().GetFactionPower(faction);
|
factionPower = FactionManager.GetInstance().GetFactionPower(faction);
|
||||||
factionTier = FactionManager.GetInstance().GetFactionTier(faction);
|
factionTier = FactionManager.GetInstance().GetFactionTier(faction);
|
||||||
|
|
||||||
@ -207,25 +214,5 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower, factionTier);
|
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower, factionTier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (stopMobSpawn) {
|
|
||||||
// // Temporary for now
|
|
||||||
// // Sphere center point is going to be X,Y,Z
|
|
||||||
// Integer X = pos.getX();
|
|
||||||
// Integer y = pos.getY();
|
|
||||||
// Integer z = pos.getZ();
|
|
||||||
// Integer radius = 10;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (hasBuildFlight) {
|
|
||||||
// for (PlayerEntity player : world.getPlayers()) {
|
|
||||||
// if (IsPlayerInBounds(player, pos)) {
|
|
||||||
// // Notify the attribute tree to enable this attribute!
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// world.getBlockEntity(pos.east());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import net.minecraft.util.ItemScatterer;
|
|||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldAccess;
|
|
||||||
|
|
||||||
public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProvider {
|
public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProvider {
|
||||||
// public static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 12, 16);
|
// public static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 12, 16);
|
||||||
@ -57,10 +56,12 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
|
|||||||
// Update block entity
|
// Update block entity
|
||||||
if (bEntity != null) {
|
if (bEntity != null) {
|
||||||
bEntity.SetFaction(fac);
|
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
|
// An empty string implies NO faction; only do things if it is NOT empty
|
||||||
if (!fac.equals("")) {
|
if (!fac.isEmpty()) {
|
||||||
faction = fac;
|
faction = fac;
|
||||||
player.sendMessage(Text.of("This block now belongs to the " + faction + " faction."));
|
player.sendMessage(Text.of("This block now belongs to the " + faction + " faction."));
|
||||||
} else {
|
} else {
|
||||||
@ -81,7 +82,7 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
|
|||||||
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
|
||||||
if (state.getBlock() != newState.getBlock()) {
|
if (state.getBlock() != newState.getBlock()) {
|
||||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||||
if (blockEntity != null && blockEntity instanceof FactionBlockEntity) {
|
if (blockEntity instanceof FactionBlockEntity) {
|
||||||
ItemScatterer.spawn(world, pos, (FactionBlockEntity) blockEntity);
|
ItemScatterer.spawn(world, pos, (FactionBlockEntity) blockEntity);
|
||||||
world.updateComparators(pos, this);
|
world.updateComparators(pos, this);
|
||||||
}
|
}
|
||||||
@ -93,8 +94,10 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
|
|||||||
if (bEntity != null) {
|
if (bEntity != null) {
|
||||||
bEntity.ResetBlock();
|
bEntity.ResetBlock();
|
||||||
}
|
}
|
||||||
}
|
}t
|
||||||
|
|
||||||
|
// Disable chunk loading
|
||||||
|
world.getChunkManager().setChunkForced(world.getChunk(pos).getPos(), false);
|
||||||
super.onStateReplaced(state, world, pos, newState, moved);
|
super.onStateReplaced(state, world, pos, newState, moved);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +106,7 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
|
|||||||
// Calls ScreenHandler inside createMenu of entity class
|
// Calls ScreenHandler inside createMenu of entity class
|
||||||
@Override
|
@Override
|
||||||
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 from 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");
|
System.out.println("onUse of faction base block called");
|
||||||
if (!world.isClient()) {
|
if (!world.isClient()) {
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
package jesse.keeblarcraft.FactionMgr;
|
package jesse.keeblarcraft.FactionMgr;
|
||||||
|
|
||||||
|
import jesse.keeblarcraft.Utils.CommonStructures.Pair;
|
||||||
|
|
||||||
import static java.util.Map.entry;
|
import static java.util.Map.entry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -48,7 +50,7 @@ public class FactionConfig {
|
|||||||
entry (3, VALID_FACTION_ROLES.OWNER)
|
entry (3, VALID_FACTION_ROLES.OWNER)
|
||||||
);
|
);
|
||||||
|
|
||||||
public class WriteableFaction {
|
public static class WriteableFaction {
|
||||||
// Key = Player UUID
|
// Key = Player UUID
|
||||||
// Val = Faction role of player
|
// Val = Faction role of player
|
||||||
HashMap<String, VALID_FACTION_ROLES> factionPlayerList = new HashMap<String, VALID_FACTION_ROLES>();
|
HashMap<String, VALID_FACTION_ROLES> factionPlayerList = new HashMap<String, VALID_FACTION_ROLES>();
|
||||||
@ -133,6 +135,18 @@ public class FactionConfig {
|
|||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets faction members in a pair return; KEY = UUID values. PAIR = Ranks of each UUID
|
||||||
|
// Alternatively you could just call @see GetMemberNames(String) to get member names
|
||||||
|
// and their ranks.
|
||||||
|
public HashMap<String, VALID_FACTION_ROLES> GetFactionPlayers(String factionName) {
|
||||||
|
HashMap<String, VALID_FACTION_ROLES> players = null;
|
||||||
|
|
||||||
|
if (IsValid(factionName)) {
|
||||||
|
players = allFactions.get(factionName).factionPlayerList;
|
||||||
|
}
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
/// @fn DeleteFaction
|
/// @fn DeleteFaction
|
||||||
///
|
///
|
||||||
|
@ -85,6 +85,7 @@ public class FactionManager {
|
|||||||
FactionTier.InitializeFactionTiers();
|
FactionTier.InitializeFactionTiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is purely a chat-based call. Here to help with `/faction info` basically.
|
||||||
public void GetFactionInformation(ServerPlayerEntity player) {
|
public void GetFactionInformation(ServerPlayerEntity player) {
|
||||||
String factionName = GetFactionOfPlayer(player.getUuidAsString());
|
String factionName = GetFactionOfPlayer(player.getUuidAsString());
|
||||||
|
|
||||||
@ -274,6 +275,10 @@ public class FactionManager {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, VALID_FACTION_ROLES> GetFactionPlayers(String factionName) {
|
||||||
|
return factionConfig.factions.GetFactionPlayers(factionName);
|
||||||
|
}
|
||||||
|
|
||||||
public Integer GetFactionPower(String factionName) {
|
public Integer GetFactionPower(String factionName) {
|
||||||
int fPower = 0;
|
int fPower = 0;
|
||||||
if (factionConfig.factions.IsValid(factionName)) {
|
if (factionConfig.factions.IsValid(factionName)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user