[factions-banking] Added faction attachment to block. Still a bit buggy
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
7d5fbca603
commit
fa5bc741ec
@ -32,10 +32,11 @@ public class FactionBeacon extends AbstractNode {
|
||||
|
||||
private void ApplyEffects(ServerPlayerEntity player) {
|
||||
// player.setAbsorptionAmount(absorptionAmnt);
|
||||
StatusEffectInstance conduit = new StatusEffectInstance(StatusEffects.CONDUIT_POWER, 1, 0, true,true, true);
|
||||
StatusEffectInstance regen = new StatusEffectInstance(StatusEffects.REGENERATION, 1, 0, true, true, true);
|
||||
StatusEffectInstance hero = new StatusEffectInstance(StatusEffects.HERO_OF_THE_VILLAGE, 1, 0, true, true, true);
|
||||
StatusEffectInstance fire = new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 1, 0, true, true, true);
|
||||
// Duration is in ticks
|
||||
StatusEffectInstance conduit = new StatusEffectInstance(StatusEffects.CONDUIT_POWER, 40, 0, true,true, true);
|
||||
StatusEffectInstance regen = new StatusEffectInstance(StatusEffects.REGENERATION, 40, 0, true, true, true);
|
||||
StatusEffectInstance hero = new StatusEffectInstance(StatusEffects.HERO_OF_THE_VILLAGE, 40, 0, true, true, true);
|
||||
StatusEffectInstance fire = new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 40, 0, true, true, true);
|
||||
|
||||
player.addStatusEffect(conduit);
|
||||
player.addStatusEffect(regen);
|
||||
@ -46,7 +47,7 @@ public class FactionBeacon extends AbstractNode {
|
||||
@Override
|
||||
public void RegisterCallbacks() {
|
||||
System.out.println("REGISTER CALLBACKS FOR FACTION BEACON CALLED");
|
||||
PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||
PlayerInBaseCallback.EVENT.register((player, world, power) -> {
|
||||
// Make sure player can fly while inside the border. We don't ever want to run this more than once!
|
||||
// player.sendMessage(Text.of("Applying effects"));
|
||||
ApplyEffects((ServerPlayerEntity) player);
|
||||
|
@ -78,7 +78,7 @@ public class FactionFlight extends AbstractNode {
|
||||
|
||||
@Override
|
||||
public void RegisterCallbacks() {
|
||||
PlayerEnteredBaseCallback.EVENT.register((player, world) -> {
|
||||
PlayerEnteredBaseCallback.EVENT.register((player, world, power) -> {
|
||||
player.sendMessage(Text.of("Faction flight enabled"));
|
||||
canFly = true;
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
@ -88,7 +88,7 @@ public class FactionFlight extends AbstractNode {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||
PlayerInBaseCallback.EVENT.register((player, world, power) -> {
|
||||
// Make sure player can fly while inside the border. We don't ever want to run this more than once!
|
||||
if (!canFly && !loginInBaseToggle) {
|
||||
player.sendMessage(Text.of("Faction flight enabled"));
|
||||
@ -100,7 +100,7 @@ public class FactionFlight extends AbstractNode {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
PlayerCommandFlightCallback.EVENT.register((player, world) -> {
|
||||
PlayerCommandFlightCallback.EVENT.register((player, world, power) -> {
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
Boolean isFlying = TurnOnFlight(serverPlayer);
|
||||
// This is a toggle command; so first we get if the player is flying
|
||||
@ -124,7 +124,7 @@ public class FactionFlight extends AbstractNode {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
PlayerExitedBaseCallback.EVENT.register((player, world) -> {
|
||||
PlayerExitedBaseCallback.EVENT.register((player, world, power) -> {
|
||||
Timer timer = new Timer();
|
||||
canFly = false;
|
||||
player.sendMessage(Text.of("You left the faction's perimeter! Flight will disable in 5 seconds..."));
|
||||
|
@ -125,7 +125,7 @@ public class FactionCommands {
|
||||
|
||||
private int ForwardFlightCallback(CommandContext<ServerCommandSource> context) {
|
||||
if (context.getSource().isExecutedByPlayer()) {
|
||||
ActionResult result = PlayerCommandFlightCallback.EVENT.invoker().interact(context.getSource().getPlayer(), context.getSource().getWorld());
|
||||
ActionResult result = PlayerCommandFlightCallback.EVENT.invoker().interact(context.getSource().getPlayer(), context.getSource().getWorld(), FactionManager.GetInstance().GetFactionPower(context.getSource().getPlayer()));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeMgr;
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeTree;
|
||||
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerEnteredBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerExitedBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
|
||||
@ -34,6 +35,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
||||
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 static int factionPower = 0;
|
||||
Boolean stopMobSpawn = true;
|
||||
Boolean hasBuildFlight = true;
|
||||
@ -42,10 +44,14 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
||||
|
||||
protected final PropertyDelegate propertyDelegate;
|
||||
|
||||
public FactionBlockEntity(BlockPos pos, BlockState state, String faction) {
|
||||
this(pos, state);
|
||||
this.faction = faction;
|
||||
}
|
||||
|
||||
public FactionBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(BlockEntityRegistration.FACTION_BLOCK_ENTITY, pos, state);
|
||||
this.propertyDelegate = new PropertyDelegate() {
|
||||
|
||||
@Override
|
||||
public int get(int index) {
|
||||
// The only value we need to get/delegate is faction power
|
||||
@ -123,25 +129,28 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
||||
// Tick method is called 20 times a second
|
||||
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()) {
|
||||
if (world.isClient() || faction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
factionPower = FactionManager.GetInstance().GetFactionPower(faction);
|
||||
|
||||
// TODO: Optimize this block so that when it is placed the placers UUID is related to a faction and only pull from a list of those players not the entire server
|
||||
for (PlayerEntity player : world.getPlayers()) {
|
||||
Boolean isPlayerInFactionRadius = IsPlayerInBounds(player, pos);
|
||||
if (isPlayerInFactionRadius) {
|
||||
// Run individual faction modules for players here
|
||||
// First time entry callback check
|
||||
System.out.println("FACTION IS " + faction);
|
||||
if (!playersInRadius.contains(player.getUuidAsString())) {
|
||||
playersInRadius.add(player.getUuidAsString());
|
||||
ActionResult result = PlayerEnteredBaseCallback.EVENT.invoker().interact(player, world);
|
||||
ActionResult result = PlayerEnteredBaseCallback.EVENT.invoker().interact(player, world, factionPower);
|
||||
}
|
||||
|
||||
// Invoke the flight attribute on this player
|
||||
if (hasBuildFlight) {
|
||||
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_flight");
|
||||
ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world);
|
||||
ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world, factionPower);
|
||||
}
|
||||
|
||||
if (hasSuperBeacon) {
|
||||
@ -150,7 +159,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
||||
}
|
||||
} else if (!isPlayerInFactionRadius && playersInRadius.contains(player.getUuidAsString())) {
|
||||
playersInRadius.remove(player.getUuidAsString());
|
||||
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world);
|
||||
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,30 @@
|
||||
package jesse.keeblarcraft.CustomBlocks.Blocks;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jesse.keeblarcraft.CustomBlocks.BlockEntities.BlockEntityRegistration;
|
||||
import jesse.keeblarcraft.CustomBlocks.BlockEntities.FactionBlockEntity;
|
||||
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemScatterer;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProvider {
|
||||
// public static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 12, 16);
|
||||
private String faction; // Faction attached to this block
|
||||
|
||||
public FactionBaseBlock(Settings settings) {
|
||||
super(settings);
|
||||
@ -33,9 +40,31 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
|
||||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (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());
|
||||
|
||||
// An empty string implies NO faction; only do things if it is NOT empty
|
||||
if (!fac.equals("")) {
|
||||
faction = fac;
|
||||
player.sendMessage(Text.of("This block now belongs to the " + faction + " faction."));
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new FactionBlockEntity(pos, state);
|
||||
return new FactionBlockEntity(pos, state, faction);
|
||||
}
|
||||
|
||||
// If block is destroyed; drop inventory
|
||||
|
@ -8,9 +8,9 @@ import net.minecraft.world.World;
|
||||
|
||||
public interface PlayerCommandFlightCallback {
|
||||
Event<PlayerCommandFlightCallback> EVENT = EventFactory.createArrayBacked(PlayerCommandFlightCallback.class,
|
||||
(listeners) -> (player, world) -> {
|
||||
(listeners) -> (player, world, power) -> {
|
||||
for (PlayerCommandFlightCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, world);
|
||||
ActionResult result = listener.interact(player, world, power);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
@ -20,5 +20,5 @@ public interface PlayerCommandFlightCallback {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, World world);
|
||||
ActionResult interact(PlayerEntity player, World world, Integer factionPower);
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import net.minecraft.world.World;
|
||||
|
||||
public interface PlayerEnteredBaseCallback {
|
||||
Event<PlayerEnteredBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerEnteredBaseCallback.class,
|
||||
(listeners) -> (player, world) -> {
|
||||
(listeners) -> (player, world, power) -> {
|
||||
for (PlayerEnteredBaseCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, world);
|
||||
ActionResult result = listener.interact(player, world, power);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
@ -20,5 +20,5 @@ public interface PlayerEnteredBaseCallback {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, World world);
|
||||
ActionResult interact(PlayerEntity player, World world, Integer factionPower);
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import net.minecraft.world.World;
|
||||
|
||||
public interface PlayerExitedBaseCallback {
|
||||
Event<PlayerExitedBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerExitedBaseCallback.class,
|
||||
(listeners) -> (player, world) -> {
|
||||
(listeners) -> (player, world, power) -> {
|
||||
for (PlayerExitedBaseCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, world);
|
||||
ActionResult result = listener.interact(player, world, power);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
@ -20,5 +20,5 @@ public interface PlayerExitedBaseCallback {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, World world);
|
||||
ActionResult interact(PlayerEntity player, World world, Integer factionPower);
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import net.minecraft.world.World;
|
||||
|
||||
public interface PlayerInBaseCallback {
|
||||
Event<PlayerInBaseCallback> EVENT = EventFactory.createArrayBacked(PlayerInBaseCallback.class,
|
||||
(listeners) -> (player, world) -> {
|
||||
(listeners) -> (player, world, power) -> {
|
||||
for (PlayerInBaseCallback listener : listeners) {
|
||||
ActionResult result = listener.interact(player, world);
|
||||
ActionResult result = listener.interact(player, world, power);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
@ -20,5 +20,5 @@ public interface PlayerInBaseCallback {
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult interact(PlayerEntity player, World world);
|
||||
ActionResult interact(PlayerEntity player, World world, Integer factionPower);
|
||||
}
|
||||
|
@ -214,6 +214,14 @@ public class FactionManager {
|
||||
return success;
|
||||
}
|
||||
|
||||
public Integer GetFactionPower(String factionName) {
|
||||
int fPower = 0;
|
||||
if (factionConfig.factions.IsValid(factionName)) {
|
||||
fPower = factionConfig.factions.GetPower(factionName);
|
||||
}
|
||||
return fPower;
|
||||
}
|
||||
|
||||
public Integer GetFactionPower(ServerPlayerEntity caller) {
|
||||
Integer amount = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user