mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 20:52:36 +00:00
Merge branch 'dev' into pr-290
# Conflicts: # src/api
This commit is contained in:
commit
74511b7449
109 files changed
+4169
-1324
No files matched your search
@@ -786,7 +786,15 @@ public abstract class AbstractDataAbilities {
|
||||
fireTickEvent(currentAbility, target);
|
||||
|
||||
// Script may have completed/cancelled the ability during the tick event
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) return;
|
||||
if (currentAbility == null) return;
|
||||
if (!currentAbility.isExecuting()) {
|
||||
// tick() itself can end the ability (DAZED -> IDLE). Run its completion here,
|
||||
// otherwise it stays the current ability forever and nothing else can start.
|
||||
if (phaseChanged && currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,
|
||||
|
||||
@@ -321,6 +321,9 @@ public class CustomNpcs {
|
||||
new AddonManager();
|
||||
new AttributeController();
|
||||
new MagicController();
|
||||
|
||||
SyncController.register();
|
||||
|
||||
|
||||
APIRegistry.Instance.register("CNPC+ API", "https://kamkeel.github.io/CustomNPC-Plus/");
|
||||
}
|
||||
|
||||
@@ -188,22 +188,35 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
if (maxCooldown > minCooldown) {
|
||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||
}
|
||||
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + ability.getCooldownTicks();
|
||||
long now = npc.worldObj.getTotalWorldTime();
|
||||
|
||||
// Additionally set per-ability cooldown if enabled
|
||||
if (ability.isPerAbilityCooldown() && ability.getCooldownTicks() > 0) {
|
||||
long endTime = npc.worldObj.getTotalWorldTime() + ability.getCooldownTicks();
|
||||
setPerAbilityCooldown(ability.getName(), endTime, ability.getCooldownTicks());
|
||||
// The ability's own cooldown is tracked against the ability, so the global timer
|
||||
// only paces how often the NPC acts. Folding the ability's cooldown into it as
|
||||
// well would always outlast the per-ability entry and make it unreachable.
|
||||
cooldownEndTime = now + baseCooldown;
|
||||
setPerAbilityCooldown(ability.getName(), now + ability.getCooldownTicks(), ability.getCooldownTicks());
|
||||
} else {
|
||||
cooldownEndTime = now + baseCooldown + ability.getCooldownTicks();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollChainCooldown(ChainedAbility chain) {
|
||||
int baseCooldown = minCooldown;
|
||||
if (maxCooldown > minCooldown) {
|
||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||
long now = npc.worldObj.getTotalWorldTime();
|
||||
boolean perAbility = chain.isPerAbilityCooldown() && chain.getCooldownTicks() > 0;
|
||||
|
||||
if (!chain.isIgnoreCooldown()) {
|
||||
int baseCooldown = minCooldown;
|
||||
if (maxCooldown > minCooldown) {
|
||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||
}
|
||||
cooldownEndTime = perAbility ? now + baseCooldown : now + baseCooldown + chain.getCooldownTicks();
|
||||
}
|
||||
|
||||
if (perAbility) {
|
||||
setPerAbilityCooldown(chain.getName(), now + chain.getCooldownTicks(), chain.getCooldownTicks());
|
||||
}
|
||||
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + chain.getCooldownTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,12 +484,17 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Per-ability cooldown filter: ability may have its own independent cooldown
|
||||
// Per-ability cooldown filter: ability/chain may have its own independent cooldown
|
||||
if (!action.isChain()) {
|
||||
Ability ab = (Ability) action;
|
||||
if (ab.isPerAbilityCooldown() && isOnPerAbilityCooldown(ab.getName())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ChainedAbility ch = (ChainedAbility) action;
|
||||
if (ch.isPerAbilityCooldown() && isOnPerAbilityCooldown(ch.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -975,6 +975,11 @@ public class EventHooks {
|
||||
return postAbilityEvent(ability, event);
|
||||
}
|
||||
|
||||
public static boolean onAbilityDefend(Ability ability, AbilityEvent.DefendEvent event) {
|
||||
if (ability == null || event == null) return false;
|
||||
return postAbilityEvent(ability, event);
|
||||
}
|
||||
|
||||
public static boolean onAbilityToggle(Ability ability, EntityLivingBase entity, int oldState, int newState) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.ToggleEvent(entity, ability, oldState, newState));
|
||||
|
||||
@@ -640,7 +640,7 @@ public class NoppesUtilServer {
|
||||
playerdata.save();
|
||||
}
|
||||
if (pl != null) {
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
||||
}
|
||||
sendPlayerData(type, player, name);
|
||||
}
|
||||
@@ -1229,7 +1229,7 @@ public class NoppesUtilServer {
|
||||
playerdata.save();
|
||||
|
||||
if (pl != null) {
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1261,7 +1261,7 @@ public class NoppesUtilServer {
|
||||
|
||||
playerdata.save();
|
||||
if (pl != null) {
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
SyncController.dispatchSyncForAllTypes((EntityPlayerMP) pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,9 @@ import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerDataSyncHandler;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerEffectSyncHelper;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
@@ -141,7 +143,7 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
|
||||
if (playerData.updateClient) {
|
||||
SyncController.syncPlayerData((EntityPlayerMP) player, true);
|
||||
PlayerDataSyncHandler.syncPlayerData((EntityPlayerMP) player, true);
|
||||
playerData.updateClient = false;
|
||||
}
|
||||
|
||||
@@ -151,8 +153,8 @@ public class ScriptPlayerEventHandler {
|
||||
|
||||
if (player.ticksExisted % 10 == 0) {
|
||||
EntityPlayerMP mp = (EntityPlayerMP) player;
|
||||
SyncController.syncEffects(mp);
|
||||
SyncController.syncAbilityCooldowns(mp);
|
||||
PlayerEffectSyncHelper.syncEffects(mp);
|
||||
PlayerAbilitySyncHelper.syncAbilityCooldowns(mp);
|
||||
PlayerAbilitySyncPacket.sendToPlayer(mp);
|
||||
playerData.abilityData.ensureLockStateClear();
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.handlers.CarpentryRecipeSyncHandler;
|
||||
import kamkeel.npcs.controllers.sync.handlers.WorkbenchRecipeSyncHandler;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import kamkeel.npcs.network.packets.data.ClonerPacket;
|
||||
import kamkeel.npcs.network.packets.data.MarkDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
||||
@@ -255,20 +257,22 @@ public class ServerEventsHandler {
|
||||
|
||||
if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.WORKBENCH_RECIPES,
|
||||
SyncType.WORKBENCH_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
SyncController.getCurrentRevision(EnumSyncType.WORKBENCH_RECIPES),
|
||||
SyncController.workbenchNBT()
|
||||
null,
|
||||
SyncController.getCurrentServerRevision(SyncType.WORKBENCH_RECIPES),
|
||||
WorkbenchRecipeSyncHandler.getInstance().serializeAll()
|
||||
), (EntityPlayerMP) player);
|
||||
}
|
||||
if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.CARPENTRY_RECIPES,
|
||||
SyncType.CARPENTRY_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
SyncController.getCurrentRevision(EnumSyncType.CARPENTRY_RECIPES),
|
||||
SyncController.carpentryNBT()
|
||||
null,
|
||||
SyncController.getCurrentServerRevision(SyncType.CARPENTRY_RECIPES),
|
||||
CarpentryRecipeSyncHandler.getInstance().serializeAll()
|
||||
), (EntityPlayerMP) player);
|
||||
}
|
||||
if ((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerEffectSyncHelper;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
@@ -45,13 +47,12 @@ public class ServerTickHandler {
|
||||
playerData.onLogin();
|
||||
}
|
||||
|
||||
ProfileController.Instance.login(player);
|
||||
SyncController.beginLogin(player);
|
||||
SyncController.syncEffects(player);
|
||||
PlayerEffectSyncHelper.syncEffects(player);
|
||||
ScriptController.Instance.syncClientScripts(player);
|
||||
|
||||
// Sync clean ability state to the new client (after beginLogin initializes sync state)
|
||||
SyncController.syncAbilities(player);
|
||||
PlayerAbilitySyncHelper.syncAbilities(player);
|
||||
|
||||
// Send auction notifications on login
|
||||
if (AuctionController.Instance != null) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.constants.EnumPotionType;
|
||||
import noppes.npcs.controllers.data.Line;
|
||||
import noppes.npcs.controllers.data.Lines;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -13,11 +14,21 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class VersionCompatibility {
|
||||
public static int ModRev = 23;
|
||||
public static int ModRev = 24;
|
||||
|
||||
public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound compound) {
|
||||
if (npc.npcVersion == ModRev)
|
||||
return;
|
||||
if (npc.npcVersion < 24) {
|
||||
// Fire projectiles used to ignite unconditionally. The ignite check now also requires
|
||||
// pBurnItem, which reads false when the key is absent, so restore it for anything
|
||||
// saved before the flag existed.
|
||||
if (compound.hasKey("pEffect") && !compound.hasKey("pBurnItem")) {
|
||||
if (EnumPotionType.fromOrdinal(compound.getInteger("pEffect")) == EnumPotionType.Fire) {
|
||||
compound.setBoolean("pBurnItem", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (npc.npcVersion < 23) {
|
||||
if (compound.hasKey("AimWhileShooting")) {
|
||||
boolean aimShot = compound.getBoolean("AimWhileShooting");
|
||||
|
||||
@@ -10,7 +10,10 @@ public class EntityAITransform extends EntityAIBase {
|
||||
|
||||
public EntityAITransform(EntityNPCInterface npc) {
|
||||
this.npc = npc;
|
||||
setMutexBits(AiMutex.PASSIVE);
|
||||
// No mutex: this only polls the world time and flips the transform, it drives nothing.
|
||||
// Claiming PASSIVE let any running movement or look task starve it, so the day/night
|
||||
// swap only fired in the gaps where those yielded - such as while saying a line.
|
||||
setMutexBits(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,10 +67,6 @@ public class BlockBorder extends BlockContainer {
|
||||
}
|
||||
|
||||
tile.rotation = l;
|
||||
|
||||
if (par5EntityLivingBase instanceof EntityPlayer && par1World.isRemote) {
|
||||
CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.Border, (EntityPlayer) par5EntityLivingBase);
|
||||
}
|
||||
}
|
||||
|
||||
private TileBorder getTile(World world, int x, int y, int z) {
|
||||
|
||||
@@ -49,13 +49,6 @@ public class BlockNpcRedstone extends BlockContainer {
|
||||
par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + 1, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack item) {
|
||||
if (entityliving instanceof EntityPlayer && world.isRemote) {
|
||||
CustomNpcs.proxy.openGui(i, j, k, EnumGuiType.RedstoneBlock, (EntityPlayer) entityliving);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {
|
||||
onBlockAdded(par1World, par2, par3, par4);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package noppes.npcs.client;
|
||||
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.controllers.MusicController;
|
||||
@@ -18,8 +18,8 @@ import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.SkinOverlay;
|
||||
import noppes.npcs.util.CacheHashMap;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -32,14 +32,14 @@ public class ClientCacheHandler {
|
||||
|
||||
private static String activeServerKey = "";
|
||||
private static String lastServerKey = "";
|
||||
private static final Map<String, EnumMap<EnumSyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
private static final Map<String, Map<SyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
|
||||
public static Party party;
|
||||
|
||||
public static boolean allowProfiles = true;
|
||||
public static boolean allowParties = true;
|
||||
|
||||
public static void setActiveServer(String serverKey, EnumMap<EnumSyncType, Integer> serverRevisions) {
|
||||
public static void setActiveServer(String serverKey, Map<SyncType, Integer> serverRevisions) {
|
||||
String normalizedKey = serverKey == null ? "" : serverKey;
|
||||
String previousKey = activeServerKey == null ? "" : activeServerKey;
|
||||
lastServerKey = previousKey;
|
||||
@@ -54,9 +54,9 @@ public class ClientCacheHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
EnumMap<EnumSyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
||||
Map<SyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
||||
activeServerKey,
|
||||
ignored -> new EnumMap<>(EnumSyncType.class)
|
||||
ignored -> new LinkedHashMap<>()
|
||||
);
|
||||
if (serverRevisions != null && !serverRevisions.isEmpty()) {
|
||||
cached.keySet().retainAll(serverRevisions.keySet());
|
||||
@@ -67,19 +67,19 @@ public class ClientCacheHandler {
|
||||
return lastServerKey == null ? "" : lastServerKey;
|
||||
}
|
||||
|
||||
public static EnumMap<EnumSyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
public static Map<SyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
String key = serverKey == null ? "" : serverKey;
|
||||
if (key.isEmpty()) {
|
||||
return new EnumMap<>(EnumSyncType.class);
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.get(key);
|
||||
Map<SyncType, Integer> revisions = clientRevisionCache.get(key);
|
||||
if (revisions == null) {
|
||||
return new EnumMap<>(EnumSyncType.class);
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
return new EnumMap<>(revisions);
|
||||
return new LinkedHashMap<>(revisions);
|
||||
}
|
||||
|
||||
public static void updateClientRevision(EnumSyncType type, int revision) {
|
||||
public static void updateClientRevision(SyncType type, int revision) {
|
||||
if (revision < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -87,9 +87,9 @@ public class ClientCacheHandler {
|
||||
if (key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
||||
Map<SyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
||||
key,
|
||||
ignored -> new EnumMap<>(EnumSyncType.class)
|
||||
ignored -> new LinkedHashMap<>()
|
||||
);
|
||||
revisions.put(type, revision);
|
||||
}
|
||||
@@ -126,14 +126,11 @@ public class ClientCacheHandler {
|
||||
ClientCacheHandler.playerAnimations.clear();
|
||||
ProfileClientConfig.reset();
|
||||
|
||||
// Clear Texture Caches
|
||||
GuiSoundSelection.cachedDomains.clear();
|
||||
GuiTextureSelection.cachedTextures.clear();
|
||||
|
||||
// Clear music/bard sounds
|
||||
MusicController.Instance.stopAllSounds();
|
||||
|
||||
// Clear Quest Tracker
|
||||
HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker);
|
||||
if (component != null) {
|
||||
component.loadData(new NBTTagCompound());
|
||||
@@ -146,7 +143,6 @@ public class ClientCacheHandler {
|
||||
ClientCacheHandler.customOverlays.clear();
|
||||
ClientCacheHandler.skinOverlays.clear();
|
||||
|
||||
// Clear Texture Caches
|
||||
GuiSoundSelection.cachedDomains.clear();
|
||||
GuiTextureSelection.cachedTextures.clear();
|
||||
}
|
||||
|
||||
@@ -8,22 +8,26 @@ import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.client.controllers.ClientCloneController;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiMenuSideButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.data.CloneFolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiData {
|
||||
public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiData, ICustomScrollListener {
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private GuiCustomScroll navScroll;
|
||||
private List<String> list;
|
||||
private List<String> navList = new ArrayList<String>();
|
||||
|
||||
private static String search = "";
|
||||
public int activeTab = 1;
|
||||
public String activeFolder = null;
|
||||
public boolean isServer = false;
|
||||
|
||||
public GuiNpcMobSpawnerSelector() {
|
||||
@@ -50,40 +54,62 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
|
||||
addButton(new GuiNpcButton(0, guiLeft + 171, guiTop + 80, 80, 20, "gui.done"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 171, guiTop + 103, 80, 20, "gui.cancel"));
|
||||
|
||||
addSideButton(new GuiMenuSideButton(21, guiLeft - 90, this.guiTop + 2, 90, 22, "1"));
|
||||
addSideButton(new GuiMenuSideButton(22, guiLeft - 90, this.guiTop + 23, 90, 22, "2"));
|
||||
addSideButton(new GuiMenuSideButton(23, guiLeft - 90, this.guiTop + 44, 90, 22, "3"));
|
||||
addSideButton(new GuiMenuSideButton(24, guiLeft - 90, this.guiTop + 65, 90, 22, "4"));
|
||||
addSideButton(new GuiMenuSideButton(25, guiLeft - 90, this.guiTop + 86, 90, 22, "5"));
|
||||
addSideButton(new GuiMenuSideButton(26, guiLeft - 45, this.guiTop + 107, 45, 22, "6"));
|
||||
addSideButton(new GuiMenuSideButton(27, guiLeft - 90, this.guiTop + 107, 45, 22, "7"));
|
||||
addSideButton(new GuiMenuSideButton(28, guiLeft - 45, this.guiTop + 128, 45, 22, "8"));
|
||||
addSideButton(new GuiMenuSideButton(29, guiLeft - 90, this.guiTop + 128, 45, 22, "9"));
|
||||
addSideButton(new GuiMenuSideButton(30, guiLeft - 45, this.guiTop + 149, 45, 22, "10"));
|
||||
addSideButton(new GuiMenuSideButton(31, guiLeft - 90, this.guiTop + 149, 45, 22, "11"));
|
||||
addSideButton(new GuiMenuSideButton(32, guiLeft - 45, this.guiTop + 170, 45, 22, "12"));
|
||||
addSideButton(new GuiMenuSideButton(33, guiLeft - 90, this.guiTop + 170, 45, 22, "13"));
|
||||
addSideButton(new GuiMenuSideButton(34, guiLeft - 45, this.guiTop + 191, 45, 22, "14"));
|
||||
addSideButton(new GuiMenuSideButton(35, guiLeft - 90, this.guiTop + 191, 45, 22, "15"));
|
||||
// Navigation scroll (tabs + folders) replacing hardcoded side buttons
|
||||
buildNavList();
|
||||
if (navScroll == null) {
|
||||
navScroll = new GuiCustomScroll(this, 1);
|
||||
} else {
|
||||
navScroll.clear();
|
||||
}
|
||||
navScroll.setSize(90, 210);
|
||||
navScroll.guiLeft = guiLeft - 94;
|
||||
navScroll.guiTop = guiTop + 2;
|
||||
navScroll.setList(navList);
|
||||
navScroll.setSelected(getNavSelection());
|
||||
addScroll(navScroll);
|
||||
|
||||
getSideButton(20 + activeTab).active = true;
|
||||
showClones();
|
||||
}
|
||||
|
||||
private void buildNavList() {
|
||||
navList.clear();
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
navList.add("Tab " + i);
|
||||
}
|
||||
if (ClientCloneController.Instance != null) {
|
||||
for (CloneFolder folder : ClientCloneController.Instance.getFolderList()) {
|
||||
navList.add(folder.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getNavSelection() {
|
||||
if (activeFolder != null) return activeFolder;
|
||||
if (activeTab >= 1 && activeTab <= 15) return "Tab " + activeTab;
|
||||
return "Tab 1";
|
||||
}
|
||||
|
||||
public String getSelected() {
|
||||
return scroll.getSelected();
|
||||
}
|
||||
|
||||
private void showClones() {
|
||||
|
||||
if (isServer) {
|
||||
PacketClient.sendClient(new CloneListPacket(activeTab));
|
||||
if (activeFolder != null) {
|
||||
PacketClient.sendClient(new CloneListPacket(activeFolder));
|
||||
} else {
|
||||
PacketClient.sendClient(new CloneListPacket(activeTab));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
|
||||
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeTab));
|
||||
if (activeFolder != null && ClientCloneController.Instance != null) {
|
||||
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeFolder));
|
||||
} else if (ClientCloneController.Instance != null) {
|
||||
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeTab));
|
||||
} else {
|
||||
this.list = new ArrayList<String>();
|
||||
}
|
||||
scroll.setList(getSearchList());
|
||||
}
|
||||
|
||||
@@ -97,6 +123,7 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
|
||||
}
|
||||
|
||||
private List<String> getSearchList() {
|
||||
if (list == null) list = new ArrayList<String>();
|
||||
if (search.isEmpty())
|
||||
return new ArrayList<String>(list);
|
||||
List<String> list = new ArrayList<String>();
|
||||
@@ -112,8 +139,15 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
|
||||
if (sel == null)
|
||||
return null;
|
||||
|
||||
NBTTagCompound compound = ClientCloneController.Instance.getCloneData(player, sel, activeTab);
|
||||
compound.setString("ClonedName", sel);
|
||||
NBTTagCompound compound;
|
||||
if (activeFolder != null && ClientCloneController.Instance != null) {
|
||||
compound = ClientCloneController.Instance.getCloneData(player, sel, activeFolder);
|
||||
} else {
|
||||
compound = ClientCloneController.Instance.getCloneData(player, sel, activeTab);
|
||||
}
|
||||
if (compound != null) {
|
||||
compound.setString("ClonedName", sel);
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -126,9 +160,28 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
|
||||
scroll.clear();
|
||||
close();
|
||||
}
|
||||
if (id > 20) {
|
||||
activeTab = id - 20;
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 1) {
|
||||
String selected = navScroll.getSelected();
|
||||
if (selected == null) return;
|
||||
|
||||
if (selected.startsWith("Tab ")) {
|
||||
try {
|
||||
int tabNum = Integer.parseInt(selected.substring(4));
|
||||
if (tabNum >= 1 && tabNum <= 15) {
|
||||
activeTab = tabNum;
|
||||
activeFolder = null;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
} else {
|
||||
activeFolder = selected;
|
||||
activeTab = -1;
|
||||
}
|
||||
showClones();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,19 +112,19 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS
|
||||
}
|
||||
if (button.id == 10) {
|
||||
slot = 1;
|
||||
setSubGui(new GuiDialogSelection(availabitily.questId));
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialogId));
|
||||
}
|
||||
if (button.id == 11) {
|
||||
slot = 2;
|
||||
setSubGui(new GuiDialogSelection(availabitily.quest2Id));
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialog2Id));
|
||||
}
|
||||
if (button.id == 12) {
|
||||
slot = 3;
|
||||
setSubGui(new GuiDialogSelection(availabitily.quest3Id));
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialog3Id));
|
||||
}
|
||||
if (button.id == 13) {
|
||||
slot = 4;
|
||||
setSubGui(new GuiDialogSelection(availabitily.quest4Id));
|
||||
setSubGui(new GuiDialogSelection(availabitily.dialog4Id));
|
||||
}
|
||||
if (button.id == 20) {
|
||||
availabitily.dialogId = -1;
|
||||
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
@@ -12,6 +13,25 @@ public class SubGuiTrapPresetSelector extends SubGuiInterface {
|
||||
|
||||
public String selectedPreset = null;
|
||||
|
||||
/**
|
||||
* Builds the trap editor's preset field.
|
||||
* <p>
|
||||
* This lives here rather than in AbilityTrap because the lambda below carries this class in
|
||||
* its method descriptor. AbilityTrap is a both-side class, and @SideOnly does not strip the
|
||||
* synthetic lambda methods it generates - so anything reflecting over its declared methods
|
||||
* on a server would resolve that descriptor and fail to find this client-only type.
|
||||
*/
|
||||
public static FieldDef createPresetField(java.util.function.Consumer<String> applyPreset) {
|
||||
return FieldDef.subGuiField("gui.applyPreset",
|
||||
SubGuiTrapPresetSelector::new,
|
||||
gui -> {
|
||||
SubGuiTrapPresetSelector selector = (SubGuiTrapPresetSelector) gui;
|
||||
if (selector.selectedPreset != null) {
|
||||
applyPreset.accept(selector.selectedPreset);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final String[] PRESET_NAMES = {"HIDDEN", "VENOM", "EXPLOSIVE", "CURSED", "SHOCK", "SNARE"};
|
||||
private static final String[] PRESET_LABELS = {
|
||||
"ability.preset.hidden", "ability.preset.venom", "ability.preset.explosive",
|
||||
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
@@ -12,6 +13,25 @@ public class SubGuiZonePresetSelector extends SubGuiInterface {
|
||||
|
||||
public String selectedPreset = null;
|
||||
|
||||
/**
|
||||
* Builds the zone editor's preset field.
|
||||
* <p>
|
||||
* This lives here rather than in AbilityZone because the lambda below carries this class in
|
||||
* its method descriptor. AbilityZone is a both-side class, and @SideOnly does not strip the
|
||||
* synthetic lambda methods it generates - so anything reflecting over its declared methods
|
||||
* on a server would resolve that descriptor and fail to find this client-only type.
|
||||
*/
|
||||
public static FieldDef createPresetField(java.util.function.Consumer<String> applyPreset) {
|
||||
return FieldDef.subGuiField("gui.applyPreset",
|
||||
SubGuiZonePresetSelector::new,
|
||||
gui -> {
|
||||
SubGuiZonePresetSelector selector = (SubGuiZonePresetSelector) gui;
|
||||
if (selector.selectedPreset != null) {
|
||||
applyPreset.accept(selector.selectedPreset);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final String[] PRESET_NAMES = {"DEFAULT", "TOXIC", "INFERNO", "ARCANE", "ELECTRIC", "FROST"};
|
||||
private static final String[] PRESET_LABELS = {
|
||||
"ability.preset.default", "ability.preset.toxic", "ability.preset.inferno",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -11,6 +13,7 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicData;
|
||||
import noppes.npcs.controllers.data.MagicEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -36,6 +39,30 @@ public class SubGuiAbilityMagic extends SubGuiInterface implements ICustomScroll
|
||||
|
||||
private GuiNpcTextField splitField;
|
||||
|
||||
/**
|
||||
* Builds the ability editor's magic field.
|
||||
* <p>
|
||||
* This lives here rather than in Ability because the lambdas below carry this class in
|
||||
* their method descriptors. Ability is a both-side class, and anything reflecting over its
|
||||
* declared methods on a server - Nashorn's adapter generator, for one - would resolve those
|
||||
* descriptors and fail to find this client-only type.
|
||||
*/
|
||||
public static FieldDef createMagicField(MagicData magicData) {
|
||||
return FieldDef.subGuiField("ability.magic.editor",
|
||||
() -> new SubGuiAbilityMagic(magicData.copy()),
|
||||
gui -> {
|
||||
MagicData result = ((SubGuiAbilityMagic) gui).magicData;
|
||||
magicData.getMagics().clear();
|
||||
for (Map.Entry<Integer, MagicEntry> e : result.getMagics().entrySet()) {
|
||||
magicData.getMagics().put(e.getKey(), e.getValue());
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> magicData.isEmpty()
|
||||
? StatCollector.translateToLocal("ability.magic.usesCaster")
|
||||
: magicData.getMagics().size() + " Magic(s)")
|
||||
.tab("General");
|
||||
}
|
||||
|
||||
public SubGuiAbilityMagic(MagicData data) {
|
||||
this.magicData = data;
|
||||
setBackground("menubg.png");
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import static kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition.MAX_CONDITIONS;
|
||||
|
||||
@@ -153,7 +154,11 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
fieldDefs.add(FieldDef.boolField("gui.enabled", chain::isEnabled, chain::setEnabled).tab("General"));
|
||||
fieldDefs.add(FieldDef.intField("ability.weight", chain::getWeight, chain::setWeight).range(1, 100).tab("General"));
|
||||
fieldDefs.add(FieldDef.boolField("ability.windUpAll", chain::isWindUpAll, chain::setWindUpAll).tab("General"));
|
||||
fieldDefs.add(FieldDef.intField("ability.cooldown", chain::getCooldownTicks, chain::setCooldownTicks).range(0, 12000).tab("General"));
|
||||
fieldDefs.add(FieldDef.row(
|
||||
FieldDef.intField("ability.cooldown", chain::getCooldownTicks, chain::setCooldownTicks).range(0, 12000),
|
||||
FieldDef.boolField("ability.perAbilityCooldown", chain::isPerAbilityCooldown, chain::setPerAbilityCooldown)
|
||||
).tab("General"));
|
||||
fieldDefs.add(FieldDef.boolField("ability.ignoreCooldown", chain::isIgnoreCooldown, chain::setIgnoreCooldown).tab("General"));
|
||||
|
||||
// ── Target tab ───────────────────────────────────────────────
|
||||
fieldDefs.add(FieldDef.row(
|
||||
@@ -163,16 +168,20 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
|
||||
// ── Icon tab ──────────────────────────────────────────────
|
||||
AbilityIconData chainIcon = AbilityIconData.fromChainedAbility(chain);
|
||||
BooleanSupplier isCustomIcon = chainIcon::isEnabled;
|
||||
|
||||
fieldDefs.add(FieldDef.section("ability.section.icon").tab("Icon"));
|
||||
fieldDefs.add(FieldDef.boolField("ability.hasIcon", chainIcon::isEnabled, chainIcon::setEnabled).tab("Icon"));
|
||||
fieldDefs.add(FieldDef.row(
|
||||
FieldDef.intField("gui.width", chainIcon::getWidth, chainIcon::setWidth).range(1, 256),
|
||||
FieldDef.intField("gui.height", chainIcon::getHeight, chainIcon::setHeight).range(1, 256)
|
||||
).tab("Icon"));
|
||||
fieldDefs.add(FieldDef.floatField("gui.scale", chainIcon::getScale, chainIcon::setScale).tab("Icon").range(0.1f, 10.0f));
|
||||
).tab("Icon").visibleWhen(isCustomIcon));
|
||||
fieldDefs.add(FieldDef.floatField("gui.scale", chainIcon::getScale, chainIcon::setScale).tab("Icon").range(0.1f, 10.0f).visibleWhen(isCustomIcon));
|
||||
fieldDefs.add(FieldDef.intField("ability.icon.layers", chainIcon::getLayerCount, chainIcon::setLayerCount)
|
||||
.tab("Icon").range(1, AbilityIconData.MAX_LAYERS));
|
||||
.tab("Icon").range(1, AbilityIconData.MAX_LAYERS).visibleWhen(isCustomIcon));
|
||||
for (int i = 0; i < AbilityIconData.MAX_LAYERS; i++) {
|
||||
final int idx = i;
|
||||
java.util.function.BooleanSupplier layerVisible = () -> chainIcon.getLayerCount() > idx;
|
||||
java.util.function.BooleanSupplier layerVisible = () -> isCustomIcon.getAsBoolean() && chainIcon.getLayerCount() > idx;
|
||||
String sectionLabel = net.minecraft.util.StatCollector.translateToLocal("ability.icon.layer") + " " + (idx + 1);
|
||||
fieldDefs.add(FieldDef.section(sectionLabel).tab("Icon").visibleWhen(layerVisible));
|
||||
fieldDefs.add(FieldDef.textureSubGui("gui.texture",
|
||||
@@ -194,12 +203,12 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
}
|
||||
|
||||
// Animation
|
||||
fieldDefs.add(FieldDef.section("Animation").tab("Icon"));
|
||||
fieldDefs.add(FieldDef.boolField("gui.animated", chainIcon::isAnimated, chainIcon::setAnimated).tab("Icon").hover("gui.animated.hover"));
|
||||
fieldDefs.add(FieldDef.section("Animation").tab("Icon").visibleWhen(isCustomIcon));
|
||||
fieldDefs.add(FieldDef.boolField("gui.animated", chainIcon::isAnimated, chainIcon::setAnimated).tab("Icon").hover("gui.animated.hover").visibleWhen(isCustomIcon));
|
||||
fieldDefs.add(FieldDef.intField("gui.frameCount", chainIcon::getFrameCount, chainIcon::setFrameCount)
|
||||
.tab("Icon").range(1, 256).visibleWhen(chainIcon::isAnimated));
|
||||
.tab("Icon").range(1, 256).visibleWhen(() -> isCustomIcon.getAsBoolean() && chainIcon.isAnimated()));
|
||||
fieldDefs.add(FieldDef.intField("gui.frameTime", chainIcon::getFrameTime, chainIcon::setFrameTime)
|
||||
.tab("Icon").range(1, 100).visibleWhen(chainIcon::isAnimated));
|
||||
.tab("Icon").range(1, 100).visibleWhen(() -> isCustomIcon.getAsBoolean() && chainIcon.isAnimated()));
|
||||
|
||||
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
|
||||
if (AbilityController.Instance != null) {
|
||||
|
||||
@@ -3,6 +3,8 @@ package noppes.npcs.client.gui.advanced;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHasEffect;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
@@ -25,6 +27,31 @@ import java.util.Map;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SubGuiCustomEffectSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
|
||||
|
||||
/**
|
||||
* Builds the condition editor's effect-select field.
|
||||
* <p>
|
||||
* This lives here rather than in ConditionHasEffect because the lambdas below carry this
|
||||
* class in their method descriptors. The condition is a both-side class, and @SideOnly does
|
||||
* not strip the synthetic lambda methods it generates - so anything reflecting over its
|
||||
* declared methods on a server would resolve those descriptors and fail to find this type.
|
||||
*/
|
||||
public static FieldDef createSelectField(ConditionHasEffect condition) {
|
||||
return FieldDef.subGuiField("condition.select_effect",
|
||||
() -> new SubGuiCustomEffectSelect(condition.getEffectId(), condition.getEffectIndex()),
|
||||
gui -> {
|
||||
SubGuiCustomEffectSelect sel = (SubGuiCustomEffectSelect) gui;
|
||||
if (sel.getSelectedEffectId() >= 0) {
|
||||
condition.setEffect(sel.getSelectedEffectId(), sel.getSelectedIndex());
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
if (condition.getEffectId() < 0) return "None";
|
||||
CustomEffect effect = condition.getEffect();
|
||||
return effect != null ? effect.getName() : "ID:" + condition.getEffectId();
|
||||
})
|
||||
.clearable(() -> condition.setEffect(-1, 0));
|
||||
}
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private final HashMap<String, Integer> displayNameToId = new HashMap<>();
|
||||
private final HashMap<String, Integer> allDisplayNameToId = new HashMap<>();
|
||||
|
||||
@@ -39,6 +39,7 @@ public class QuestTrackingComponent extends HudComponent {
|
||||
if (turnIn != null && !turnIn.isEmpty()) {
|
||||
turnInLines.add(convertColorCodes(turnIn));
|
||||
}
|
||||
updateOverlayHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,6 +240,19 @@ public class QuestTrackingComponent extends HudComponent {
|
||||
}
|
||||
|
||||
// ---------- Helper rendering methods ----------- (methods unchanged) ...
|
||||
private void updateOverlayHeight() {
|
||||
int lineHeight = mc.fontRenderer.FONT_HEIGHT + 4;
|
||||
int contentHeight = 5;
|
||||
contentHeight += questTitleLines.size() * lineHeight + 8;
|
||||
contentHeight += questCategoryLines.size() * lineHeight + 8;
|
||||
contentHeight += objectiveLines.size() * lineHeight;
|
||||
if (!turnInLines.isEmpty()) {
|
||||
contentHeight += 8;
|
||||
}
|
||||
contentHeight += turnInLines.size() * lineHeight;
|
||||
overlayHeight = contentHeight;
|
||||
}
|
||||
|
||||
private int renderTextBlock(List<String> lines, int startY, int align, int color) {
|
||||
int y = startY;
|
||||
FontRenderer font = mc.fontRenderer;
|
||||
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
|
||||
@@ -638,9 +639,12 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
|
||||
String key = slots[slotIndex].abilityKey;
|
||||
Ability ability = slots[slotIndex].ability;
|
||||
IAbilityAction action = slots[slotIndex].action;
|
||||
|
||||
if (ability != null && ability.isPerAbilityCooldown()) {
|
||||
return playerData.abilityData.getPerAbilityCooldownProgress(key);
|
||||
} else if (action instanceof ChainedAbility && ((ChainedAbility) action).isPerAbilityCooldown()) {
|
||||
return playerData.abilityData.getPerAbilityCooldownProgress(key);
|
||||
} else {
|
||||
return playerData.abilityData.getGlobalCooldownProgress();
|
||||
}
|
||||
|
||||
@@ -429,6 +429,9 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC
|
||||
}
|
||||
|
||||
private boolean isMouseOverScrollbar(int mouseX, int mouseY) {
|
||||
if (maxScrollY <= 0)
|
||||
return false;
|
||||
|
||||
int scrollbarX = guiLeft + xSize + 30;
|
||||
int scrollbarY = guiTop + 27;
|
||||
int scrollbarHeight = ySize - 35;
|
||||
|
||||
@@ -184,8 +184,13 @@ public class GuiNpcSpawner extends GuiNPCInterface2 implements ITextfieldListene
|
||||
GuiNpcMobSpawnerSelector selector = (GuiNpcMobSpawnerSelector) gui;
|
||||
if (selector.isServer) {
|
||||
String selected = selector.getSelected();
|
||||
if (selected != null)
|
||||
PacketClient.sendClient(new JobSpawnerAddPacket(selector.isServer, selected, selector.activeTab, slot));
|
||||
if (selected != null) {
|
||||
if (selector.activeFolder != null) {
|
||||
PacketClient.sendClient(new JobSpawnerAddPacket(selector.isServer, selected, selector.activeFolder, slot));
|
||||
} else {
|
||||
PacketClient.sendClient(new JobSpawnerAddPacket(selector.isServer, selected, selector.activeTab, slot));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NBTTagCompound compound = selector.getCompound();
|
||||
if (compound != null) {
|
||||
|
||||
@@ -21,6 +21,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
private final ResourceLocation slot = new ResourceLocation("customnpcs", "textures/gui/slot.png");
|
||||
private RoleTrader role;
|
||||
private boolean marketRelinked = false;
|
||||
|
||||
// Currency cost textfield IDs start at 100 (100-117 for slots 0-17)
|
||||
private static final int CURRENCY_FIELD_ID_START = 100;
|
||||
@@ -116,8 +117,14 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false));
|
||||
// Linking to a different market already replaced the server's role with that market's
|
||||
// data. Pushing this GUI's pre-link state back would overwrite the market being linked to.
|
||||
if (marketRelinked)
|
||||
return;
|
||||
|
||||
// Save the role first so the market is written from the edited data, not the stale data.
|
||||
PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound())));
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,6 +136,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
String name = guiNpcTextField.getText();
|
||||
if (!name.equalsIgnoreCase(role.marketName)) {
|
||||
role.marketName = name;
|
||||
marketRelinked = true;
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, true));
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -2,6 +2,8 @@ package noppes.npcs.client.gui.select;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionQuestCompleted;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -27,6 +29,31 @@ public class GuiQuestSelection extends SubGuiInterface implements ICustomScrollL
|
||||
private QuestCategory selectedCategory;
|
||||
public Quest selectedQuest;
|
||||
|
||||
/**
|
||||
* Builds the condition editor's quest-select field.
|
||||
* <p>
|
||||
* This lives here rather than in ConditionQuestCompleted because the lambdas below carry
|
||||
* this class in their method descriptors. The condition is a both-side class, and @SideOnly
|
||||
* does not strip the synthetic lambda methods it generates - so anything reflecting over its
|
||||
* declared methods on a server would resolve those descriptors and fail to find this type.
|
||||
*/
|
||||
public static FieldDef createConditionField(ConditionQuestCompleted condition) {
|
||||
return FieldDef.subGuiField("condition.select_quest",
|
||||
() -> new GuiQuestSelection(condition.getQuestId()),
|
||||
gui -> {
|
||||
GuiQuestSelection sel = (GuiQuestSelection) gui;
|
||||
if (sel.selectedQuest != null) {
|
||||
condition.setQuestId(sel.selectedQuest.id);
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
if (condition.getQuestId() < 0) return "None";
|
||||
Quest q = QuestController.Instance.quests.get(condition.getQuestId());
|
||||
return q != null ? q.title : "ID:" + condition.getQuestId();
|
||||
})
|
||||
.clearable(() -> condition.setQuestId(-1));
|
||||
}
|
||||
|
||||
private GuiSelectionListener listener;
|
||||
private String catSearch = "";
|
||||
private String questSearch = "";
|
||||
|
||||
@@ -515,15 +515,28 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
}
|
||||
|
||||
boolean subGui = hasSubGui();
|
||||
|
||||
// Mouse.getDWheel() clears the accumulated delta, so only the first caller in a frame
|
||||
// ever sees it. Read it once here and let each widget take it in turn; anything that
|
||||
// consumes it zeroes it so later widgets - the script editor, for one - are not left
|
||||
// reading an already-drained wheel.
|
||||
mouseScroll = Mouse.getDWheel();
|
||||
|
||||
drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff);
|
||||
for (GuiNpcLabel label : labels.values())
|
||||
label.drawLabel(this, fontRendererObj);
|
||||
for (GuiCustomScroll scroll : scrolls.values()) {
|
||||
scroll.updateSubGUI(subGui);
|
||||
scroll.drawScreen(drawX, drawY, f, !subGui && scroll.isMouseOver(drawX, drawY) ? Mouse.getDWheel() : 0);
|
||||
int delta = !subGui && scroll.isMouseOver(drawX, drawY) ? mouseScroll : 0;
|
||||
if (delta != 0)
|
||||
mouseScroll = 0;
|
||||
scroll.drawScreen(drawX, drawY, f, delta);
|
||||
}
|
||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
||||
guiScrollableComponent.drawScreen(drawX, drawY, f, !subGui && guiScrollableComponent.isMouseOver(drawX, drawY) ? Mouse.getDWheel() : 0);
|
||||
int delta = !subGui && guiScrollableComponent.isMouseOver(drawX, drawY) ? mouseScroll : 0;
|
||||
if (delta != 0)
|
||||
mouseScroll = 0;
|
||||
guiScrollableComponent.drawScreen(drawX, drawY, f, delta);
|
||||
}
|
||||
for (GuiDiagram diagram : diagrams.values()) {
|
||||
diagram.drawDiagram(drawX, drawY, subGui);
|
||||
|
||||
@@ -624,9 +624,11 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
int maxScroll = Math.max(0, getPaddedLineCount() - container.visibleLines);
|
||||
|
||||
// Handle mouse wheel scroll
|
||||
int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel();
|
||||
// Take whatever the parent screen has left for this frame rather than polling the wheel
|
||||
// again - the poll is destructive and the parent has already drained it.
|
||||
int wheelDelta = listener instanceof GuiNPCInterface ? ((GuiNPCInterface) listener).mouseScroll : Mouse.getDWheel();
|
||||
if (listener instanceof GuiNPCInterface) {
|
||||
((GuiNPCInterface) listener).mouseScroll = wheelDelta;
|
||||
((GuiNPCInterface) listener).mouseScroll = 0;
|
||||
|
||||
// Intercept wheel scroll for tooltip (highest priority)
|
||||
// Only consume the wheel event when the tooltip actually has content to scroll;
|
||||
|
||||
@@ -486,9 +486,11 @@ public class GuiScriptTextArea1 extends GuiNpcTextField {
|
||||
int maxScroll = Math.max(0, getPaddedLineCount() - container.visibleLines);
|
||||
|
||||
// Handle mouse wheel scroll
|
||||
int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel();
|
||||
// Take whatever the parent screen has left for this frame rather than polling the wheel
|
||||
// again - the poll is destructive and the parent has already drained it.
|
||||
int wheelDelta = listener instanceof GuiNPCInterface ? ((GuiNPCInterface) listener).mouseScroll : Mouse.getDWheel();
|
||||
if (listener instanceof GuiNPCInterface) {
|
||||
((GuiNPCInterface) listener).mouseScroll = wheelDelta;
|
||||
((GuiNPCInterface) listener).mouseScroll = 0;
|
||||
boolean canScroll = !KEYS_OVERLAY.isVisible() || KEYS_OVERLAY.isVisible() && !KEYS_OVERLAY.aboveOverlay;
|
||||
if (wheelDelta != 0 && canScroll)
|
||||
scroll.applyWheelScroll(wheelDelta, maxScroll);
|
||||
|
||||
@@ -1,7 +1,108 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.SyncHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* OVERHAULED IGuiData FRAMEWORK!
|
||||
* Based on the new {@link SyncController} and {@link SyncHandler} infrastructure
|
||||
*/
|
||||
public interface IGuiData {
|
||||
public void setGuiData(NBTTagCompound compound);
|
||||
|
||||
/**
|
||||
* Legacy data setter
|
||||
* @Deprecated Use {@link #onDataUpdated(NBTTagCompound)} or {@link #onDataRemoved(String)} instead
|
||||
*/
|
||||
default void setGuiData(NBTTagCompound compound) {
|
||||
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// USE THESE !!!
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
/** NOTE:
|
||||
* No need for full object dataset onDataReload on GUI open, as these datasets are
|
||||
* always freshly synced to their client's controllers thanks to {@link SyncController}
|
||||
*/
|
||||
|
||||
/**
|
||||
* When a controller's object gets saved on server side, the updated object is synced to the client
|
||||
* @param compound the compound of the updated object
|
||||
*/
|
||||
default void onDataUpdated(NBTTagCompound compound) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets saved on server side, the updated object is synced to the client
|
||||
* @param key key of updated object
|
||||
* @param compound compound of updated object
|
||||
*/
|
||||
default void onDataUpdated(NBTTagCompound compound, String key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets saved on server side, the updated object is synced to the client
|
||||
* @param id id of updated object
|
||||
* @param compound compound of updated object
|
||||
*/
|
||||
default void onDataUpdated(NBTTagCompound compound, int id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets deleted on server side, the deleted object is removed from the client
|
||||
* @param key key of removed object
|
||||
*/
|
||||
default void onDataRemoved(String key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* When a controller's object gets deleted on server side, the deleted object is removed from the client
|
||||
* @param id id of removed object
|
||||
*/
|
||||
default void onDataRemoved(int id) {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// Static dispatchers
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
static void legacySetGuiData(NBTTagCompound nbt) {
|
||||
GuiScreen gui = activeGui();
|
||||
if (gui instanceof IGuiData)
|
||||
((IGuiData) gui).setGuiData(nbt);
|
||||
}
|
||||
|
||||
static void notifyUpdate(NBTTagCompound nbt, String key, int id) {
|
||||
GuiScreen gui = activeGui();
|
||||
if (gui instanceof IGuiData) {
|
||||
((IGuiData) gui).onDataUpdated(nbt);
|
||||
((IGuiData) gui).onDataUpdated(nbt, key);
|
||||
((IGuiData) gui).onDataUpdated(nbt, id);
|
||||
}
|
||||
}
|
||||
|
||||
static void notifyRemove(String key, int id) {
|
||||
GuiScreen gui = activeGui();
|
||||
if (gui instanceof IGuiData) {
|
||||
((IGuiData) gui).onDataRemoved(key);
|
||||
((IGuiData) gui).onDataRemoved(id);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// Active Gui fetcher
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
|
||||
static GuiScreen activeGui() {
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if (gui instanceof GuiNPCInterface && ((GuiNPCInterface) gui).hasSubGui())
|
||||
return ((GuiNPCInterface) gui).getSubGui();
|
||||
if (gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface) gui).hasSubGui())
|
||||
return ((GuiContainerNPCInterface) gui).getSubGui();
|
||||
return gui;
|
||||
}
|
||||
}
|
||||
@@ -325,78 +325,94 @@ public class TypeInfo {
|
||||
* @return A TypeInfo preserving the generic structure, or null if type is null
|
||||
*/
|
||||
public static TypeInfo fromGenericType(Type type) {
|
||||
return fromGenericType(type, new HashSet<TypeVariable<?>>());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resolving type variables whose bounds are currently being expanded, so a
|
||||
* self-referential bound such as {@code E extends Enum<E>} terminates
|
||||
*/
|
||||
private static TypeInfo fromGenericType(Type type, Set<TypeVariable<?>> resolving) {
|
||||
if (type == null) return null;
|
||||
|
||||
|
||||
if (type instanceof Class<?>) {
|
||||
// Plain class - no generic info
|
||||
return fromClass((Class<?>) type);
|
||||
}
|
||||
|
||||
|
||||
if (type instanceof ParameterizedType) {
|
||||
// Generic type like List<String>
|
||||
ParameterizedType paramType = (ParameterizedType) type;
|
||||
Type rawType = paramType.getRawType();
|
||||
|
||||
|
||||
if (!(rawType instanceof Class<?>)) {
|
||||
// Edge case - should not happen normally
|
||||
return rawType != null ? fromGenericType(rawType) : null;
|
||||
return rawType != null ? fromGenericType(rawType, resolving) : null;
|
||||
}
|
||||
|
||||
|
||||
// Get the raw type as TypeInfo
|
||||
TypeInfo rawTypeInfo = fromClass((Class<?>) rawType);
|
||||
|
||||
|
||||
// Recursively convert type arguments
|
||||
Type[] typeArgs = paramType.getActualTypeArguments();
|
||||
List<TypeInfo> appliedArgs = new ArrayList<>(typeArgs.length);
|
||||
for (Type arg : typeArgs) {
|
||||
TypeInfo argInfo = fromGenericType(arg);
|
||||
TypeInfo argInfo = fromGenericType(arg, resolving);
|
||||
if (argInfo != null) {
|
||||
appliedArgs.add(argInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return a parameterized TypeInfo
|
||||
if (!appliedArgs.isEmpty()) {
|
||||
return rawTypeInfo.parameterize(appliedArgs);
|
||||
}
|
||||
return rawTypeInfo;
|
||||
}
|
||||
|
||||
|
||||
if (type instanceof GenericArrayType) {
|
||||
// Array of generic type, e.g. T[] or List<String>[]
|
||||
GenericArrayType arrayType = (GenericArrayType) type;
|
||||
TypeInfo elementType = fromGenericType(arrayType.getGenericComponentType());
|
||||
TypeInfo elementType = fromGenericType(arrayType.getGenericComponentType(), resolving);
|
||||
if (elementType != null) {
|
||||
return arrayOf(elementType);
|
||||
}
|
||||
return fromClass(Object[].class);
|
||||
}
|
||||
|
||||
|
||||
if (type instanceof TypeVariable<?>) {
|
||||
TypeVariable<?> typeVar = (TypeVariable<?>) type;
|
||||
String varName = typeVar.getName();
|
||||
// Check for bounds - if bounded, create typeParameter with bound
|
||||
Type[] bounds = typeVar.getBounds();
|
||||
if (bounds != null && bounds.length > 0 && bounds[0] != Object.class) {
|
||||
return TypeInfo.typeParameter(varName, fromGenericType(bounds[0]));
|
||||
// Already expanding this variable - emit it unbounded rather than recursing forever
|
||||
if (!resolving.add(typeVar)) {
|
||||
return TypeInfo.typeParameter(varName);
|
||||
}
|
||||
try {
|
||||
// Check for bounds - if bounded, create typeParameter with bound
|
||||
Type[] bounds = typeVar.getBounds();
|
||||
if (bounds != null && bounds.length > 0 && bounds[0] != Object.class) {
|
||||
return TypeInfo.typeParameter(varName, fromGenericType(bounds[0], resolving));
|
||||
}
|
||||
return TypeInfo.typeParameter(varName);
|
||||
} finally {
|
||||
resolving.remove(typeVar);
|
||||
}
|
||||
return TypeInfo.typeParameter(varName);
|
||||
}
|
||||
|
||||
|
||||
if (type instanceof WildcardType) {
|
||||
// Wildcard like ? or ? extends Number or ? super Integer
|
||||
WildcardType wildcard = (WildcardType) type;
|
||||
Type[] upperBounds = wildcard.getUpperBounds();
|
||||
|
||||
|
||||
// Use the upper bound if available (most useful for ? extends T)
|
||||
if (upperBounds.length > 0 && upperBounds[0] != Object.class) {
|
||||
return fromGenericType(upperBounds[0]);
|
||||
return fromGenericType(upperBounds[0], resolving);
|
||||
}
|
||||
|
||||
|
||||
// For ? super T or plain ?, just use Object
|
||||
return fromClass(Object.class);
|
||||
}
|
||||
|
||||
|
||||
// Unknown type - shouldn't happen in practice
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ public class ModelMonkeyTail extends ModelRenderer {
|
||||
|
||||
public ModelMonkeyTail(ModelBiped base) {
|
||||
super(base);
|
||||
float heightFactor = -9.0f;
|
||||
// Cancels ModelTail's rotationPointY of 11 so the boxes land where JBRA puts them
|
||||
// on players: plain tail at 10, wrapped tail at 0.
|
||||
float heightFactor = -11.0f;
|
||||
|
||||
(this.monkey_large = new ModelRenderer(base, 38, 54)).addBox(-2.0f, -2.0f, 0.0f, 4, 4, 6);
|
||||
this.setRotation(this.monkey_large, -0.5235988f, 0.0f, 0.0f);
|
||||
|
||||
@@ -125,6 +125,7 @@ public enum EnumScriptType {
|
||||
ABILITY_INTERRUPT("abilityInterrupt"),
|
||||
ABILITY_COMPLETE("abilityComplete"),
|
||||
ABILITY_HIT("abilityHit"),
|
||||
ABILITY_DEFEND("abilityDefend"),
|
||||
ABILITY_TICK("abilityTick"),
|
||||
ABILITY_TOGGLE("abilityToggle"),
|
||||
ABILITY_TOGGLE_TICK("abilityToggleTick"),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -128,7 +128,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
file.delete();
|
||||
}
|
||||
categoryManager.removeItem(id);
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
SyncController.syncRemove(SyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
}
|
||||
@@ -700,7 +700,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
nbtTagCompound.removeTag("ScriptData");
|
||||
SyncController.syncUpdate(EnumSyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
|
||||
SyncController.syncUpdate(SyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.controllers.sync.handlers.DialogCategorySyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -75,6 +76,7 @@ public class DialogController implements IDialogHandler {
|
||||
if (!file.isDirectory())
|
||||
continue;
|
||||
DialogCategory category = loadCategoryDir(file);
|
||||
List<Dialog> reassigned = new ArrayList<Dialog>();
|
||||
Iterator<Integer> ite = category.dialogs.keySet().iterator();
|
||||
while (ite.hasNext()) {
|
||||
int id = ite.next();
|
||||
@@ -82,12 +84,48 @@ public class DialogController implements IDialogHandler {
|
||||
lastUsedDialogID = id;
|
||||
Dialog dialog = category.dialogs.get(id);
|
||||
if (dialogs.containsKey(id)) {
|
||||
LogWriter.error("Duplicate id " + dialog.id + " from category " + category.title);
|
||||
// Dialog IDs live in the filename, not inside the JSON body,
|
||||
// so a simple rename permanently resolves the conflict.
|
||||
File catDir = new File(getDir(), category.title);
|
||||
|
||||
// Find the next free ID. It has to clear three things: the ids already
|
||||
// registered globally, the ids this category still holds but has not
|
||||
// reached yet, and any file already on disk - renameTo overwrites
|
||||
// silently on POSIX, so landing on an existing file would destroy it.
|
||||
int newId = lastUsedDialogID;
|
||||
do {
|
||||
newId++;
|
||||
} while (dialogs.containsKey(newId)
|
||||
|| category.dialogs.containsKey(newId)
|
||||
|| new File(catDir, newId + ".json").exists());
|
||||
lastUsedDialogID = newId;
|
||||
|
||||
File oldFile = new File(catDir, id + ".json");
|
||||
File newFile = new File(catDir, newId + ".json");
|
||||
boolean renamed = oldFile.renameTo(newFile);
|
||||
|
||||
dialog.id = newId;
|
||||
ite.remove();
|
||||
reassigned.add(dialog);
|
||||
|
||||
if (renamed) {
|
||||
LogWriter.info("Dialog ID conflict: reassigned \"" + dialog.title
|
||||
+ "\" from id " + id + " to " + newId
|
||||
+ " in category \"" + category.title + "\"");
|
||||
} else {
|
||||
LogWriter.error("Dialog ID conflict: could not rename file for \""
|
||||
+ dialog.title + "\" (id " + id
|
||||
+ " in category \"" + category.title + "\") to " + newId);
|
||||
}
|
||||
} else {
|
||||
dialogs.put(id, dialog);
|
||||
}
|
||||
}
|
||||
// Re-register reassigned dialogs under their new IDs.
|
||||
for (Dialog dialog : reassigned) {
|
||||
dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
lastUsedCatID++;
|
||||
category.id = lastUsedCatID;
|
||||
categories.put(category.id, category);
|
||||
@@ -239,7 +277,7 @@ public class DialogController implements IDialogHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
SyncController.syncUpdate(EnumSyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category));
|
||||
SyncController.syncUpdate(SyncType.DIALOG_CATEGORY, -1, DialogCategorySyncHandler.serializeCategory(category));
|
||||
}
|
||||
|
||||
public void removeCategory(int category) {
|
||||
@@ -252,7 +290,7 @@ public class DialogController implements IDialogHandler {
|
||||
for (int dia : cat.dialogs.keySet())
|
||||
dialogs.remove(dia);
|
||||
categories.remove(category);
|
||||
SyncController.syncRemove(EnumSyncType.DIALOG_CATEGORY, category);
|
||||
SyncController.syncRemove(SyncType.DIALOG_CATEGORY, category);
|
||||
}
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
@@ -302,7 +340,7 @@ public class DialogController implements IDialogHandler {
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
SyncController.syncUpdate(EnumSyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
|
||||
SyncController.syncUpdate(SyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
@@ -316,7 +354,7 @@ public class DialogController implements IDialogHandler {
|
||||
return;
|
||||
category.dialogs.remove(dialog.id);
|
||||
dialogs.remove(dialog.id);
|
||||
SyncController.syncRemove(EnumSyncType.DIALOG, dialog.id);
|
||||
SyncController.syncRemove(SyncType.DIALOG, dialog.id);
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -159,7 +159,7 @@ public class FactionController implements IFactionHandler {
|
||||
|
||||
NBTTagCompound facCompound = new NBTTagCompound();
|
||||
faction.writeNBT(facCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.FACTION, -1, facCompound);
|
||||
SyncController.syncUpdate(SyncType.FACTION, -1, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class FactionController implements IFactionHandler {
|
||||
} else {
|
||||
this.saveFactions();
|
||||
faction.id = -1;
|
||||
SyncController.syncRemove(EnumSyncType.FACTION, id);
|
||||
SyncController.syncRemove(SyncType.FACTION, id);
|
||||
return faction;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -275,7 +275,7 @@ public class MagicController implements IMagicHandler {
|
||||
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
mag.writeNBT(magicCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.MAGIC, -1, magicCompound);
|
||||
SyncController.syncUpdate(SyncType.MAGIC, -1, magicCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
@@ -283,7 +283,7 @@ public class MagicController implements IMagicHandler {
|
||||
public void removeMagic(int magicID) {
|
||||
if (magics.containsKey(magicID)) {
|
||||
magics.remove(magicID);
|
||||
SyncController.syncRemove(EnumSyncType.MAGIC, magicID);
|
||||
SyncController.syncRemove(SyncType.MAGIC, magicID);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public class MagicController implements IMagicHandler {
|
||||
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(cycleCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.MAGIC_CYCLE, -1, cycleCompound);
|
||||
SyncController.syncUpdate(SyncType.MAGIC_CYCLE, -1, cycleCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
@@ -353,7 +353,7 @@ public class MagicController implements IMagicHandler {
|
||||
public void removeCycle(int categoryId) {
|
||||
if (cycles.containsKey(categoryId)) {
|
||||
cycles.remove(categoryId);
|
||||
SyncController.syncRemove(EnumSyncType.MAGIC_CYCLE, categoryId);
|
||||
SyncController.syncRemove(SyncType.MAGIC_CYCLE, categoryId);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.controllers.sync.handlers.QuestCategorySyncHandler;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -69,6 +70,7 @@ public class QuestController implements IQuestHandler {
|
||||
if (!file.isDirectory())
|
||||
continue;
|
||||
QuestCategory category = loadCategoryDir(file);
|
||||
List<Quest> reassigned = new ArrayList<Quest>();
|
||||
Iterator<Integer> ite = category.quests.keySet().iterator();
|
||||
while (ite.hasNext()) {
|
||||
int id = ite.next();
|
||||
@@ -76,8 +78,39 @@ public class QuestController implements IQuestHandler {
|
||||
lastUsedQuestID = id;
|
||||
Quest quest = category.quests.get(id);
|
||||
if (quests.containsKey(id)) {
|
||||
LogWriter.error("Duplicate id " + quest.id + " from category " + category.title);
|
||||
// Quest IDs live in the filename, not inside the JSON body,
|
||||
// so a simple rename permanently resolves the conflict.
|
||||
File catDir = new File(getDir(), category.title);
|
||||
|
||||
// Find the next free ID. It has to clear three things: the ids already
|
||||
// registered globally, the ids this category still holds but has not
|
||||
// reached yet, and any file already on disk - renameTo overwrites
|
||||
// silently on POSIX, so landing on an existing file would destroy it.
|
||||
int newId = lastUsedQuestID;
|
||||
do {
|
||||
newId++;
|
||||
} while (quests.containsKey(newId)
|
||||
|| category.quests.containsKey(newId)
|
||||
|| new File(catDir, newId + ".json").exists());
|
||||
lastUsedQuestID = newId;
|
||||
|
||||
File oldFile = new File(catDir, id + ".json");
|
||||
File newFile = new File(catDir, newId + ".json");
|
||||
boolean renamed = oldFile.renameTo(newFile);
|
||||
|
||||
quest.id = newId;
|
||||
ite.remove();
|
||||
reassigned.add(quest);
|
||||
|
||||
if (renamed) {
|
||||
LogWriter.info("Quest ID conflict: reassigned \"" + quest.title
|
||||
+ "\" from id " + id + " to " + newId
|
||||
+ " in category \"" + category.title + "\"");
|
||||
} else {
|
||||
LogWriter.error("Quest ID conflict: could not rename file for \""
|
||||
+ quest.title + "\" (id " + id
|
||||
+ " in category \"" + category.title + "\") to " + newId);
|
||||
}
|
||||
} else {
|
||||
quests.put(id, quest);
|
||||
if (quest.profileOptions.enableOptions
|
||||
@@ -87,6 +120,16 @@ public class QuestController implements IQuestHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Re-register reassigned quests under their new IDs.
|
||||
for (Quest quest : reassigned) {
|
||||
quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
if (quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared)) {
|
||||
sharedQuests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
lastUsedCatID++;
|
||||
category.id = lastUsedCatID;
|
||||
categories.put(category.id, category);
|
||||
@@ -158,7 +201,7 @@ public class QuestController implements IQuestHandler {
|
||||
for (int dia : cat.quests.keySet())
|
||||
quests.remove(dia);
|
||||
categories.remove(category);
|
||||
SyncController.syncRemove(EnumSyncType.QUEST_CATEGORY, category);
|
||||
SyncController.syncRemove(SyncType.QUEST_CATEGORY, category);
|
||||
}
|
||||
|
||||
public void saveCategory(QuestCategory category) {
|
||||
@@ -188,7 +231,7 @@ public class QuestController implements IQuestHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
SyncController.syncUpdate(EnumSyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category));
|
||||
SyncController.syncUpdate(SyncType.QUEST_CATEGORY, -1, QuestCategorySyncHandler.serializeCategory(category));
|
||||
}
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
@@ -245,7 +288,7 @@ public class QuestController implements IQuestHandler {
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
SyncController.syncUpdate(EnumSyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
|
||||
SyncController.syncUpdate(SyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.SyncType;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
@@ -282,12 +283,12 @@ public class RecipeController implements IRecipeHandler {
|
||||
return null;
|
||||
RecipeCarpentry globalRecipe = globalRecipes.remove(recipe.id);
|
||||
if (globalRecipe != null)
|
||||
SyncController.syncAllWorkbenchRecipes();
|
||||
SyncController.syncAll(SyncType.WORKBENCH_RECIPES);
|
||||
|
||||
RecipeCarpentry carpentry = carpentryRecipes.remove(recipe.id);
|
||||
if (carpentry != null) {
|
||||
carpentryScripts.remove(recipe.id);
|
||||
SyncController.syncAllCarpentryRecipes();
|
||||
SyncController.syncAll(SyncType.CARPENTRY_RECIPES);
|
||||
}
|
||||
|
||||
saveCategories();
|
||||
@@ -302,7 +303,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
|
||||
RecipeAnvil anvilRecipe = anvilRecipes.remove(recipe.id);
|
||||
if (anvilRecipe != null)
|
||||
SyncController.syncAllAnvilRecipes();
|
||||
SyncController.syncAll(SyncType.ANVIL_RECIPES);
|
||||
|
||||
saveCategories();
|
||||
return recipe;
|
||||
|
||||
@@ -351,6 +351,7 @@ public class ScriptContainer implements IScriptUnit {
|
||||
}
|
||||
this.engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase());
|
||||
this.evaluated = false;
|
||||
this.lastGlobalsVersion = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(NPC, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(NPC, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(NPC, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(NPC, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(NPC, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(NPC, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(NPC, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
@@ -259,6 +260,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(PLAYER, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(PLAYER, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(PLAYER, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(PLAYER, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(PLAYER, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(PLAYER, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
@@ -357,6 +359,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(ABILITY, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(ABILITY, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(ABILITY, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(ABILITY, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(ABILITY, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(ABILITY, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(ABILITY, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
@@ -209,9 +210,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
compound.setInteger("Type", type.ordinal());
|
||||
|
||||
if (item != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
item.writeToNBT(itemTag);
|
||||
compound.setTag("Item", itemTag);
|
||||
compound.setTag("Item", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
|
||||
}
|
||||
|
||||
compound.setString("ItemName", itemName != null ? itemName : "");
|
||||
@@ -235,7 +234,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
type = EnumClaimType.fromOrdinal(compound.getInteger("Type"));
|
||||
|
||||
if (compound.hasKey("Item")) {
|
||||
item = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Item"));
|
||||
item = NoppesUtilServer.readItem(compound.getCompoundTag("Item"));
|
||||
} else {
|
||||
item = null;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.handler.data.IAuctionListing;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
@@ -214,9 +215,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
compound.setString("SellerName", sellerName != null ? sellerName : "");
|
||||
|
||||
if (item != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
item.writeToNBT(itemTag);
|
||||
compound.setTag("Item", itemTag);
|
||||
compound.setTag("Item", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
|
||||
}
|
||||
|
||||
compound.setLong("StartingPrice", startingPrice);
|
||||
@@ -243,7 +242,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
sellerName = compound.getString("SellerName");
|
||||
|
||||
if (compound.hasKey("Item")) {
|
||||
item = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Item"));
|
||||
item = NoppesUtilServer.readItem(compound.getCompoundTag("Item"));
|
||||
}
|
||||
|
||||
startingPrice = compound.getLong("StartingPrice");
|
||||
|
||||
@@ -45,7 +45,7 @@ public class DataScript implements IScriptHandlerPacket {
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
private EntityNPCInterface npc;
|
||||
public boolean enabled = false;
|
||||
private long lastGlobalsVersion = -1;
|
||||
private final Map<ScriptEngine, Long> engineGlobalsVersion = new IdentityHashMap<>();
|
||||
|
||||
public ICustomNpc dummyNpc;
|
||||
public IWorld dummyWorld;
|
||||
@@ -273,12 +273,13 @@ public class DataScript implements IScriptHandlerPacket {
|
||||
}
|
||||
|
||||
long currentGlobalsVersion = NpcAPI.engineObjectsVersion;
|
||||
if (lastGlobalsVersion != currentGlobalsVersion) {
|
||||
Long lastVersion = engineGlobalsVersion.get(engine);
|
||||
if (lastVersion == null || lastVersion != currentGlobalsVersion) {
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
|
||||
engine.put(engineObjects.getKey(), engineObjects.getValue());
|
||||
}
|
||||
lastGlobalsVersion = currentGlobalsVersion;
|
||||
engineGlobalsVersion.put(engine, currentGlobalsVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,17 @@ public class JaninoScriptHandler<S extends JaninoScript<?>> extends ScriptHandle
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
// JaninoScriptable's helper generics assume JaninoScript<T>, but most of our scripts are JaninoScript<?>.
|
||||
// Keep it simple and safe: treat it as raw.
|
||||
script = (S) JaninoScript.readFromNBT(compound, (JaninoScript) script, (Supplier) factory);
|
||||
NBTTagCompound tag = compound.getCompoundTag("Script");
|
||||
enabled = tag.getBoolean("enabled");
|
||||
script = (S) JaninoScript.readFromNBT(tag, (JaninoScript) script, (Supplier) factory);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
JaninoScript.writeToNBT(compound, (JaninoScript) script);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setBoolean("enabled", enabled);
|
||||
JaninoScript.writeToNBT(tag, (JaninoScript) script);
|
||||
compound.setTag("Script", tag);
|
||||
|
||||
}
|
||||
|
||||
// -------------------- IScriptHandler --------------------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
@@ -237,9 +237,19 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
@Override
|
||||
protected void rollChainCooldown(ChainedAbility chain) {
|
||||
if (chain.isIgnoreCooldown()) return;
|
||||
|
||||
int duration = chain.getCooldownTicks();
|
||||
cooldownEndTime = getWorldTime() + duration;
|
||||
globalCooldownDuration = duration;
|
||||
long endTime = getWorldTime() + duration;
|
||||
|
||||
if (chain.isPerAbilityCooldown()) {
|
||||
if (currentAbilityKey != null) {
|
||||
setPerAbilityCooldown(currentAbilityKey, endTime, duration);
|
||||
}
|
||||
} else {
|
||||
cooldownEndTime = endTime;
|
||||
globalCooldownDuration = duration;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -403,7 +413,14 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
// Dispatch: chain vs ability
|
||||
if (action.isChain()) {
|
||||
if (isOnCooldown()) return false;
|
||||
ChainedAbility chain = (ChainedAbility) action;
|
||||
if (!chain.isIgnoreCooldown()) {
|
||||
if (chain.isPerAbilityCooldown()) {
|
||||
if (isOnPerAbilityCooldown(key)) return false;
|
||||
} else {
|
||||
if (isOnCooldown()) return false;
|
||||
}
|
||||
}
|
||||
|
||||
currentAbilityKey = key;
|
||||
currentTarget = null;
|
||||
@@ -479,23 +496,23 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
/**
|
||||
* Full sync of all ability state to the client.
|
||||
* Delegates to {@link SyncController#syncAbilities(EntityPlayerMP)}.
|
||||
* Delegates to {@link PlayerAbilitySyncHelper#syncAbilities(EntityPlayerMP)}.
|
||||
*/
|
||||
public void syncToClient() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
SyncController.syncAbilities((EntityPlayerMP) player);
|
||||
PlayerAbilitySyncHelper.syncAbilities((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lightweight sync of cooldown state only to the client.
|
||||
* Delegates to {@link SyncController#syncAbilityCooldowns(EntityPlayerMP)}.
|
||||
* Delegates to {@link PlayerAbilitySyncHelper#syncAbilityCooldowns(EntityPlayerMP)}.
|
||||
*/
|
||||
public void syncCooldownToClient() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
SyncController.syncAbilityCooldowns((EntityPlayerMP) player);
|
||||
PlayerAbilitySyncHelper.syncAbilityCooldowns((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,21 +773,21 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
|
||||
/**
|
||||
* Fully reset ability state when changing dimensions.
|
||||
* Clears cooldowns so the player can immediately use abilities in the new dimension.
|
||||
* Fully reset transient ability execution state when changing dimensions.
|
||||
* Cooldowns are preserved so dimension changes cannot bypass them.
|
||||
* Keeps active toggles (dimension change shouldn't reset ongoing effects).
|
||||
*/
|
||||
public void resetOnDimensionChange() {
|
||||
trackingAbilityPosition = false;
|
||||
onEntityReconstructed(true, false);
|
||||
onEntityReconstructed(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset ability state when a large-distance teleport is detected during execution.
|
||||
* Same behavior as dimension change — silent cleanup, clear cooldowns, keep toggles.
|
||||
* Same behavior as dimension change: silent cleanup, preserve cooldowns, keep toggles.
|
||||
*/
|
||||
public void resetOnTeleport() {
|
||||
onEntityReconstructed(true, false);
|
||||
onEntityReconstructed(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -815,9 +832,8 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
currentTarget = null;
|
||||
lastAbilityActivationTime = -1;
|
||||
|
||||
// Clear cooldowns (fresh start after relog)
|
||||
cooldownEndTime = 0;
|
||||
resetAllPerAbilityCooldowns();
|
||||
// Cooldowns are absolute world-time deadlines and are restored from NBT, so relogging
|
||||
// must not clear them or it becomes a way to bypass them.
|
||||
interruptCooldownRolled = false;
|
||||
|
||||
// Reset sync tracking so next sync sends fresh state
|
||||
@@ -835,9 +851,10 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
interruptCurrentAbility(null, 0);
|
||||
}
|
||||
// Clear any remaining transient state (cooldowns, chains, locks)
|
||||
// Clear any remaining transient state (chains, locks)
|
||||
// Don't clear toggles — they were already saved to NBT by this point
|
||||
onEntityReconstructed(true, false);
|
||||
// Don't clear cooldowns — they persist across sessions
|
||||
onEntityReconstructed(false, false);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -1031,6 +1048,22 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
toggleList.appendTag(toggleNbt);
|
||||
}
|
||||
compound.setTag("ActiveToggles", toggleList);
|
||||
|
||||
// Cooldowns are absolute world-time deadlines, so they stay meaningful across sessions
|
||||
NBTTagCompound cooldowns = new NBTTagCompound();
|
||||
cooldowns.setLong("GlobalEnd", cooldownEndTime);
|
||||
cooldowns.setInteger("GlobalDuration", globalCooldownDuration);
|
||||
NBTTagList perAbilityList = new NBTTagList();
|
||||
for (Map.Entry<String, Long> entry : perAbilityCooldownEndTimes.entrySet()) {
|
||||
NBTTagCompound cooldownNbt = new NBTTagCompound();
|
||||
cooldownNbt.setString("Key", entry.getKey());
|
||||
cooldownNbt.setLong("End", entry.getValue());
|
||||
Integer duration = perAbilityCooldownDurations.get(entry.getKey());
|
||||
cooldownNbt.setInteger("Duration", duration == null ? 0 : duration);
|
||||
perAbilityList.appendTag(cooldownNbt);
|
||||
}
|
||||
cooldowns.setTag("PerAbility", perAbilityList);
|
||||
compound.setTag("AbilityCooldowns", cooldowns);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
@@ -1065,6 +1098,24 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
setToggleEntryDirect(key, state);
|
||||
}
|
||||
}
|
||||
|
||||
if (compound.hasKey("AbilityCooldowns")) {
|
||||
cooldownEndTime = 0;
|
||||
globalCooldownDuration = 0;
|
||||
resetAllPerAbilityCooldowns();
|
||||
|
||||
NBTTagCompound cooldowns = compound.getCompoundTag("AbilityCooldowns");
|
||||
cooldownEndTime = cooldowns.getLong("GlobalEnd");
|
||||
globalCooldownDuration = cooldowns.getInteger("GlobalDuration");
|
||||
NBTTagList perAbilityList = cooldowns.getTagList("PerAbility", 10); // 10 = TAG_COMPOUND
|
||||
for (int i = 0; i < perAbilityList.tagCount(); i++) {
|
||||
NBTTagCompound entry = perAbilityList.getCompoundTagAt(i);
|
||||
String key = entry.getString("Key");
|
||||
if (key == null || key.isEmpty()) continue;
|
||||
perAbilityCooldownEndTimes.put(key, entry.getLong("End"));
|
||||
perAbilityCooldownDurations.put(key, entry.getInteger("Duration"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
public abstract class ScriptHandler implements IScriptHandler {
|
||||
public List<IScriptUnit> scripts = new ArrayList<>();
|
||||
protected String scriptLanguage = "ECMAScript";
|
||||
protected boolean enabled = false;
|
||||
protected boolean enabled = true;
|
||||
protected long lastInited = -1;
|
||||
|
||||
protected boolean canRunScripts() {
|
||||
|
||||
@@ -301,7 +301,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
@Override
|
||||
public boolean getLeashed() {
|
||||
return false; //Prevents npcs from being leashed
|
||||
return false; // Prevents npcs from being leashed
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -544,15 +544,13 @@ public abstract class JaninoScript<T> implements IScriptUnit {
|
||||
}
|
||||
|
||||
public static <T, S extends JaninoScript<T>> S readFromNBT(NBTTagCompound compound, S script, Supplier<S> factory) {
|
||||
if (compound.hasKey("Script")) {
|
||||
if (script == null) script = factory.get();
|
||||
script.readFromNBT(compound.getCompoundTag("Script"));
|
||||
}
|
||||
if (script == null) script = factory.get();
|
||||
script.readFromNBT(compound);
|
||||
return script;
|
||||
}
|
||||
|
||||
public static <T> NBTTagCompound writeToNBT(NBTTagCompound compound, JaninoScript<T> script) {
|
||||
if (script != null) compound.setTag("Script", script.writeToNBT(new NBTTagCompound()));
|
||||
if (script != null) script.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,15 @@ public class RoleTrader extends RoleInterface {
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
readFromNBT(nbttagcompound, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param loadFromMarket pull the linked market's stored data over the compound just read.
|
||||
* False when the compound is an admin edit, which is authoritative and
|
||||
* would otherwise be overwritten by the market it is about to be saved to.
|
||||
*/
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound, boolean loadFromMarket) {
|
||||
String oldMarket = marketName;
|
||||
marketName = nbttagcompound.getString("TraderMarket");
|
||||
readNBT(nbttagcompound);
|
||||
@@ -101,6 +110,9 @@ public class RoleTrader extends RoleInterface {
|
||||
// Register with MarketRegistry for linked market sync
|
||||
MarketRegistry.updateTraderMarket(oldMarket, marketName, this);
|
||||
|
||||
if (!loadFromMarket)
|
||||
return;
|
||||
|
||||
try {
|
||||
Market.getMarket(this, marketName);
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -317,9 +317,7 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
Quest quest = QuestController.Instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
PlayerData data = PlayerData.get(player);
|
||||
PlayerQuestController.setQuestFinishedUtil(player, quest, data.questData);
|
||||
data.updateClient = true;
|
||||
PlayerQuestController.setQuestFinished(quest, player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -214,6 +214,46 @@ public class AbilityEvent extends CustomNPCsEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class DefendEvent extends AbilityEvent implements IAbilityEvent.DefendEvent {
|
||||
private final IEntityLivingBase attacker;
|
||||
private final IEntityLivingBase lastAttacker;
|
||||
private float damage;
|
||||
|
||||
public DefendEvent(EntityLivingBase entity, Ability ability, EntityLivingBase attacker,
|
||||
EntityLivingBase lastAttacker, float damage) {
|
||||
super(entity, ability, null);
|
||||
this.attacker = attacker != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(attacker) : null;
|
||||
this.lastAttacker = lastAttacker != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(lastAttacker) : null;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getAttacker() {
|
||||
return attacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getLastAttacker() {
|
||||
return lastAttacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_DEFEND.function;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class ToggleEvent extends AbilityEvent implements IAbilityEvent.ToggleEvent {
|
||||
private final int oldState;
|
||||
|
||||
Reference in new issue
Block a user