issue/finish-factions-and-banking #2
@ -2,9 +2,13 @@ package jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||
import jesse.keeblarcraft.FactionMgr.FactionTier;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
|
||||
import jesse.keeblarcraft.FactionMgr.FactionTier.FactionTierEnum;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@ -12,7 +16,10 @@ import net.minecraft.util.ActionResult;
|
||||
|
||||
public class FactionBeacon extends AbstractNode {
|
||||
private int beaconStrength = 1; // Increases with faction power; 1 is default
|
||||
private float absorptionAmnt = 0.2f * beaconStrength;
|
||||
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 Boolean resetTimer = true;
|
||||
private Timer timer = new Timer();
|
||||
@Override
|
||||
public String GetNodeTitle() {
|
||||
return "faction_beacon";
|
||||
@ -30,27 +37,101 @@ public class FactionBeacon extends AbstractNode {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void ApplyEffects(ServerPlayerEntity player) {
|
||||
private Integer GetBeaconAmplifier(FactionTierEnum tier) {
|
||||
switch (tier) {
|
||||
case TIER_I:
|
||||
|
||||
case TIER_II:
|
||||
beaconStrength = 0;
|
||||
break;
|
||||
case TIER_III:
|
||||
beaconStrength = 1;
|
||||
break;
|
||||
case TIER_IV:
|
||||
beaconStrength = 2;
|
||||
break;
|
||||
case TIER_V:
|
||||
beaconStrength = 3;
|
||||
break;
|
||||
case TIER_VI:
|
||||
beaconStrength = 8;
|
||||
break;
|
||||
default:
|
||||
// Invalid case; in which case the beacon probably should do nothing
|
||||
beaconStrength = 0;
|
||||
break;
|
||||
}
|
||||
return beaconStrength;
|
||||
}
|
||||
|
||||
private void ApplyEffects(ServerPlayerEntity player, FactionTierEnum tier) {
|
||||
// player.setAbsorptionAmount(absorptionAmnt);
|
||||
// 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);
|
||||
beaconStrength = GetBeaconAmplifier(tier);
|
||||
System.out.println("Beacon strength is " + beaconStrength);
|
||||
|
||||
player.addStatusEffect(conduit);
|
||||
player.addStatusEffect(regen);
|
||||
player.addStatusEffect(hero);
|
||||
player.addStatusEffect(fire);
|
||||
// Tier 2 effects
|
||||
if (FactionTier.IsGreaterOrEqualTo(tier, FactionTierEnum.TIER_II)) {
|
||||
StatusEffectInstance regen = new StatusEffectInstance(StatusEffects.REGENERATION, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
StatusEffectInstance fire = new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
player.addStatusEffect(regen);
|
||||
player.addStatusEffect(fire);
|
||||
}
|
||||
|
||||
// Tier 3 effects
|
||||
if (FactionTier.IsGreaterOrEqualTo(tier, FactionTierEnum.TIER_III)) {
|
||||
StatusEffectInstance hero = new StatusEffectInstance(StatusEffects.HERO_OF_THE_VILLAGE, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
StatusEffectInstance haste = new StatusEffectInstance(StatusEffects.HASTE, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
|
||||
player.addStatusEffect(hero);
|
||||
player.addStatusEffect(haste);
|
||||
}
|
||||
|
||||
// Tier 4 effects
|
||||
if (FactionTier.IsGreaterOrEqualTo(tier, FactionTierEnum.TIER_IV)) {
|
||||
StatusEffectInstance conduit = new StatusEffectInstance(StatusEffects.CONDUIT_POWER, potionEffectLastingTimeTicks, 0, true,true, true);
|
||||
StatusEffectInstance luck = new StatusEffectInstance(StatusEffects.LUCK, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
StatusEffectInstance absorption = new StatusEffectInstance(StatusEffects.ABSORPTION, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
StatusEffectInstance waterBreathing = new StatusEffectInstance(StatusEffects.WATER_BREATHING, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
player.addStatusEffect(conduit);
|
||||
player.addStatusEffect(luck);
|
||||
player.addStatusEffect(absorption);
|
||||
player.addStatusEffect(waterBreathing);
|
||||
}
|
||||
|
||||
// Tier 5 effects
|
||||
if (FactionTier.IsGreaterOrEqualTo(tier, FactionTierEnum.TIER_V)) {
|
||||
StatusEffectInstance resistance = new StatusEffectInstance(StatusEffects.RESISTANCE, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
StatusEffectInstance strength = new StatusEffectInstance(StatusEffects.STRENGTH, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
StatusEffectInstance dolphins = new StatusEffectInstance(StatusEffects.DOLPHINS_GRACE, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
|
||||
player.addStatusEffect(resistance);
|
||||
player.addStatusEffect(strength);
|
||||
player.addStatusEffect(dolphins);
|
||||
}
|
||||
|
||||
// Tier 6 effects
|
||||
if (FactionTier.IsGreaterOrEqualTo(tier, FactionTierEnum.TIER_VI)) {
|
||||
StatusEffectInstance freeHealth = new StatusEffectInstance(StatusEffects.HEALTH_BOOST, potionEffectLastingTimeTicks, beaconStrength, true, true, true);
|
||||
|
||||
player.addStatusEffect(freeHealth);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RegisterCallbacks() {
|
||||
System.out.println("REGISTER CALLBACKS FOR FACTION BEACON CALLED");
|
||||
PlayerInBaseCallback.EVENT.register((player, world, power, factionTier) -> {
|
||||
// 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);
|
||||
if (resetTimer) {
|
||||
// The timer is super necessary because some effects (like regen) will not actually regen the player unless they can run for a few seconds
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplyEffects((ServerPlayerEntity) player, factionTier);
|
||||
resetTimer = true;
|
||||
}
|
||||
|
||||
}, timerLengthMillis);
|
||||
resetTimer = false;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class BlockList {
|
||||
public static void RegisterBlocks() {
|
||||
BlockManager.RegisterBlock("example_block_ore", new Block(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).sounds(BlockSoundGroup.AMETHYST_BLOCK).requiresTool().breakInstantly()));
|
||||
BlockManager.RegisterBlock("example_block", new ExperienceDroppingBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).sounds(BlockSoundGroup.ANCIENT_DEBRIS).requiresTool(), UniformIntProvider.create(4, 20)));
|
||||
BlockManager.RegisterBlock("example_statue", new Block(FabricBlockSettings.copyOf(Blocks.BELL)));
|
||||
BlockManager.RegisterBlock("faction_base_block", new FactionBaseBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque()));
|
||||
BlockManager.RegisterBlock("example_statue", new Block(FabricBlockSettings.copyOf(Blocks.BELL).nonOpaque()));
|
||||
BlockManager.RegisterBlock("faction_base_block", new FactionBaseBlock(FabricBlockSettings.copyOf(Blocks.COBBLESTONE).requiresTool().nonOpaque()));
|
||||
jkibbels marked this conversation as resolved
walrus
commented
did nonOpaque fix the faces not rendering issue of blocks ajacent did nonOpaque fix the faces not rendering issue of blocks ajacent
jkibbels
commented
yes yes
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ public class FactionBaseBlock extends BlockWithEntity implements BlockEntityProv
|
||||
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, true);
|
||||
// world.removeBlock(pos, false);
|
||||
world.breakBlock(pos, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,32 @@ public class FactionTier {
|
||||
factionTiers.put(Range.closed(1000, Integer.MAX_VALUE), FactionTierEnum.TIER_VI);
|
||||
}
|
||||
|
||||
// Tier 1 can never be greater than anything (and not itself, obviously)
|
||||
public static Boolean IsGreaterThan(FactionTierEnum tierInQuestion, FactionTierEnum tierToCompareAgainst) {
|
||||
Boolean isGreater = false;
|
||||
|
||||
if (tierInQuestion == FactionTierEnum.TIER_II && tierToCompareAgainst == FactionTierEnum.TIER_I) {
|
||||
isGreater = true;
|
||||
} else if (tierInQuestion == FactionTierEnum.TIER_III && (tierToCompareAgainst == FactionTierEnum.TIER_II || tierToCompareAgainst == FactionTierEnum.TIER_I)) {
|
||||
isGreater = true;
|
||||
} else if (tierInQuestion == FactionTierEnum.TIER_IV && (tierToCompareAgainst == FactionTierEnum.TIER_III || tierToCompareAgainst == FactionTierEnum.TIER_II || tierToCompareAgainst == FactionTierEnum.TIER_I)) {
|
||||
isGreater = true;
|
||||
} else if (tierInQuestion == FactionTierEnum.TIER_V && (tierToCompareAgainst == FactionTierEnum.TIER_IV || tierToCompareAgainst == FactionTierEnum.TIER_III || tierToCompareAgainst == FactionTierEnum.TIER_II || tierToCompareAgainst == FactionTierEnum.TIER_I)) {
|
||||
isGreater = true;
|
||||
} else if (tierInQuestion == FactionTierEnum.TIER_VI && (tierToCompareAgainst == FactionTierEnum.TIER_V || tierToCompareAgainst == FactionTierEnum.TIER_IV || tierToCompareAgainst == FactionTierEnum.TIER_III || tierToCompareAgainst == FactionTierEnum.TIER_II || tierToCompareAgainst == FactionTierEnum.TIER_I)) {
|
||||
isGreater = true;
|
||||
}
|
||||
return isGreater;
|
||||
}
|
||||
|
||||
public static Boolean IsEqualTo(FactionTierEnum tierInQuestion, FactionTierEnum tierToCompareAgainst) {
|
||||
return tierInQuestion == tierToCompareAgainst;
|
||||
}
|
||||
|
||||
public static Boolean IsGreaterOrEqualTo(FactionTierEnum tierInQuestion, FactionTierEnum tierToCompareAgainst) {
|
||||
return IsEqualTo(tierInQuestion, tierToCompareAgainst) || IsGreaterThan(tierInQuestion, tierToCompareAgainst);
|
||||
}
|
||||
|
||||
// Make sure you initialize tiers by calling the above function first!
|
||||
public static FactionTierEnum GetFactionTier(Integer value) {
|
||||
FactionTierEnum tier = factionTiers.get(value);
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"keeblarcraft:example_block_ore"
|
||||
"keeblarcraft:example_block_ore",
|
||||
"keeblarcraft:faction_base_block"
|
||||
]
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"bonus_rolls": 0.0,
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
],
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "keeblarcraft:faction_base_block"
|
||||
}
|
||||
],
|
||||
"rolls": 1.0
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "misc",
|
||||
"pattern": [
|
||||
"#E#",
|
||||
"#T#",
|
||||
"#G#"
|
||||
],
|
||||
"key": {
|
||||
"#": {
|
||||
"item": "minecraft:netherite_block"
|
||||
},
|
||||
"T": {
|
||||
"item": "minecraft:totem_of_undying"
|
||||
},
|
||||
"E": {
|
||||
"item": "minecraft:elytra"
|
||||
},
|
||||
"G": {
|
||||
"item": "minecraft:golden_apple"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "keeblarcraft:faction_base_block",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
"replace": false,
|
||||
"values": [
|
||||
"keeblarcraft:example_block",
|
||||
"keeblarcraft:example_block_ore"
|
||||
"keeblarcraft:example_block_ore",
|
||||
"keeblarcraft:faction_base_block"
|
||||
]
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"keeblarcraft:example_block"
|
||||
"keeblarcraft:example_block",
|
||||
"keeblarcraft:faction_base_block"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user
you should leave a commet saying TIER_I has no effects this could be confusing