[faction-item-repair] Added item repair inside faction area
This commit is contained in:
parent
fa5bc741ec
commit
449bbe93bd
@ -17,6 +17,7 @@ import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
|||||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AttributeMetalJacket;
|
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AttributeMetalJacket;
|
||||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes.FactionBeacon;
|
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes.FactionBeacon;
|
||||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes.FactionFlight;
|
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes.FactionFlight;
|
||||||
|
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes.FactionItemRepair;
|
||||||
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||||||
|
|
||||||
public class AttributeMgr {
|
public class AttributeMgr {
|
||||||
@ -149,5 +150,6 @@ public class AttributeMgr {
|
|||||||
RegisterAttributeClass(AttributeMetalJacket.class);
|
RegisterAttributeClass(AttributeMetalJacket.class);
|
||||||
RegisterAttributeClass(FactionBeacon.class);
|
RegisterAttributeClass(FactionBeacon.class);
|
||||||
RegisterAttributeClass(FactionFlight.class);
|
RegisterAttributeClass(FactionFlight.class);
|
||||||
|
RegisterAttributeClass(FactionItemRepair.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,105 @@
|
|||||||
|
package jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
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.Commands.FactionCommands;
|
||||||
|
import jesse.keeblarcraft.FactionMgr.FactionManager;
|
||||||
|
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerInBaseCallback;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
|
||||||
|
public class FactionItemRepair extends AbstractNode {
|
||||||
|
private Boolean resetTimer = true;
|
||||||
|
Timer timer = new Timer();
|
||||||
|
Date date = new Date();
|
||||||
|
int repairTier = -1;
|
||||||
|
int tempValue = 0;
|
||||||
|
FactionManager utilFactionManager = new FactionManager();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetNodeTitle() {
|
||||||
|
return "faction_item_repair";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String GetNodeDescription() {
|
||||||
|
; return "Repairs item and too durability while a player is inside the faction";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<String, List<String>> GetDetails() {
|
||||||
|
HashMap<String, List<String>> ret = new HashMap<String, List<String>>();
|
||||||
|
ret.put("Faction Item Repair", List.of("Repairs a players items and tools in their durability while they are at the faction home!",
|
||||||
|
"The repair rate is 1 durability every 5 seconds for each item not at max durability"));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BaseRepair tier 1 speed
|
||||||
|
*/
|
||||||
|
public void RepairInventory(ServerPlayerEntity player) {
|
||||||
|
//probably will end up using this List<DefaultedList<ItemStack>> combinedInventory; from PlayerInventory
|
||||||
|
//PlayerInventory playerInv = player.getInventory();// main is all your inventory you can see exluding your off hand and armor i think
|
||||||
|
switch (utilFactionManager.GetFactionPower(player)) {//should be the faction power
|
||||||
|
case 0:
|
||||||
|
repairTier = -1;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
repairTier = -2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
repairTier = -3;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
repairTier = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (ItemStack item : player.getInventory().main) {
|
||||||
|
if (item.isDamageable() && item.isDamaged()) {
|
||||||
|
item.setDamage(item.getDamage() - repairTier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (ItemStack item : player.getInventory().armor) {
|
||||||
|
if (item.isDamageable() && item.isDamaged()) {
|
||||||
|
item.setDamage(item.getDamage() - repairTier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getInventory().offHand.isEmpty()) { return; }
|
||||||
|
|
||||||
|
if (player.getOffHandStack().isDamaged()) {
|
||||||
|
player.getOffHandStack().setDamage(player.getOffHandStack().getDamage() - repairTier);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void RegisterCallbacks() {
|
||||||
|
PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||||
|
/* DO STUFF - REMEMBER: This function is called EVERY tick a player is inside the base! That's EVERY tick*/
|
||||||
|
|
||||||
|
if (resetTimer) {
|
||||||
|
resetTimer = false;
|
||||||
|
// Make a new timer object here to count down to reset the 'canRepair object'
|
||||||
|
// Reset the 'resetTimer' bool to true IN the timer
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
RepairInventory((ServerPlayerEntity) player);
|
||||||
|
resetTimer = true;
|
||||||
|
}
|
||||||
|
}, 15000);//TESTING PURPOSES WILL CAHNGE HIGHER VALUE
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResult.PASS;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -40,6 +40,7 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
Boolean stopMobSpawn = true;
|
Boolean stopMobSpawn = true;
|
||||||
Boolean hasBuildFlight = true;
|
Boolean hasBuildFlight = true;
|
||||||
Boolean hasSuperBeacon = true;
|
Boolean hasSuperBeacon = true;
|
||||||
|
Boolean hasItemRepair = true;
|
||||||
private ArrayList<String> playersInRadius = new ArrayList<>();
|
private ArrayList<String> playersInRadius = new ArrayList<>();
|
||||||
|
|
||||||
protected final PropertyDelegate propertyDelegate;
|
protected final PropertyDelegate propertyDelegate;
|
||||||
@ -157,6 +158,10 @@ public class FactionBlockEntity extends BlockEntity implements ExtendedScreenHan
|
|||||||
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_beacon");
|
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_beacon");
|
||||||
// ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world);
|
// ActionResult result = PlayerInBaseCallback.EVENT.invoker().interact(player, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasItemRepair) {
|
||||||
|
AttributeMgr.ApplyAttribute(player.getUuidAsString(), "faction_item_repair");
|
||||||
|
}
|
||||||
} else if (!isPlayerInFactionRadius && playersInRadius.contains(player.getUuidAsString())) {
|
} else if (!isPlayerInFactionRadius && playersInRadius.contains(player.getUuidAsString())) {
|
||||||
playersInRadius.remove(player.getUuidAsString());
|
playersInRadius.remove(player.getUuidAsString());
|
||||||
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower);
|
ActionResult result = PlayerExitedBaseCallback.EVENT.invoker().interact(player, world, factionPower);
|
||||||
|
Loading…
Reference in New Issue
Block a user