Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified

This commit is contained in:
bigguy345 committed 2026-03-11 08:39:56 +02:00
commit b5cff355e6
27 files changed
+1273 -857

No files matched your search

@@ -7,6 +7,7 @@ import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.CopyAbilityScriptsPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcSavePacket;
@@ -816,6 +817,14 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
* Adds as an inline slot.
*/
public void loadAbility(Ability loadedAbility) {
loadAbility(loadedAbility, null);
}
/**
* Called from SubGuiAbilityLoad when a cloned ability is loaded with a known source.
* Copies scripts server-side from source to the new inline ability.
*/
public void loadAbility(Ability loadedAbility, String sourceAbilityName) {
if (loadedAbility != null) {
loadedAbility.setId(UUID.randomUUID().toString());
npcSlots.add(AbilityAction.inline(loadedAbility));
@@ -825,6 +834,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
selectAbilityByIndex(selectedAbilityIndex);
initGui();
save();
// Copy scripts from source ability server-side (scripts are never sent to client)
if (sourceAbilityName != null && !sourceAbilityName.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(sourceAbilityName, loadedAbility.getId()));
}
}
}
@@ -981,12 +994,18 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
if (slot.isChain() && selectedEntryIndex == -1) {
// Chain header (must be CHAIN_REFERENCE)
if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
String sourceChainName = slot.getReferenceId();
if (slot.convertToInline()) {
ChainedAbility chain = slot.getInlineChain();
if (chain != null) {
pendingChain = chain;
pendingChainSlotIdx = selectedSlotIndex;
setSubGui(new SubGuiChainedAbilityConfig(chain, this, true, npcSlots));
// Copy chain scripts server-side (client never has script handlers)
if (sourceChainName != null && !sourceChainName.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(
CopyAbilityScriptsPacket.MODE_CHAINED, sourceChainName, chain.getId()));
}
}
updateNpcAbilitiesList();
save();
@@ -1015,6 +1034,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
ChainedAbility chain = slot.getInlineChain();
if (chain != null && selectedEntryIndex < chain.getEntries().size()) {
ChainedAbilityEntry entry = chain.getEntries().get(selectedEntryIndex);
// Capture source ability reference before convertToInline clears it
String sourceAbilityRef = entry.getAbilityReference();
if (entry.convertToInline()) {
Ability a = entry.getInlineAbility();
if (a != null && !a.isBuiltIn()) {
@@ -1023,6 +1044,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
editChainEntryIdx = selectedEntryIndex;
a.setNpcInlineEdit(true);
setSubGui(a.createConfigGui(this));
// Copy ability scripts server-side (client never has script handlers)
if (sourceAbilityRef != null && !sourceAbilityRef.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(sourceAbilityRef, a.getId()));
}
}
}
}
@@ -1043,12 +1068,18 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
// Standalone ability reference → convert to inline
Ability preCheck = slot.getAbility();
if (preCheck != null && preCheck.isBuiltIn()) return;
// Capture source reference before convertToInline clears it
String sourceAbilityRef = slot.getReferenceId();
if (slot.convertToInline()) {
Ability ability = slot.getAbility();
if (ability != null && !ability.isBuiltIn()) {
ability.setId(UUID.randomUUID().toString());
// UUID already generated by convertToInline() - don't reassign or script handler is orphaned
ability.setNpcInlineEdit(true);
setSubGui(ability.createConfigGui(this));
// Copy ability scripts server-side (client never has script handlers)
if (sourceAbilityRef != null && !sourceAbilityRef.isEmpty()) {
PacketClient.sendClient(new CopyAbilityScriptsPacket(sourceAbilityRef, ability.getId()));
}
}
updateNpcAbilitiesList();
save();
@@ -216,7 +216,7 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
if (parentConfig != null) {
parentConfig.loadAbility(loaded);
} else if (parentAbilities != null) {
parentAbilities.loadAbility(loaded);
parentAbilities.loadAbility(loaded, selectedName);
}
}
close();
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.global;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
import kamkeel.npcs.network.packets.request.animation.AnimationRemovePacket;
import kamkeel.npcs.network.packets.request.animation.AnimationClonePacket;
import kamkeel.npcs.network.packets.request.animation.AnimationSavePacket;
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
import kamkeel.npcs.network.packets.request.animation.BuiltInAnimationGetPacket;
@@ -169,11 +170,7 @@ public class GuiAnimationDirectory extends GuiDirectoryCategorized {
protected void onCloneItem() {
if (showingBuiltIn || currentIsBuiltIn) return;
if (animation != null && animation.id >= 0) {
Animation clone = new Animation();
clone.readFromNBT(animation.writeToNBT());
clone.id = -1;
while (itemData.containsKey(clone.name)) clone.name += "_";
PacketClient.sendClient(new AnimationSavePacket(clone.writeToNBT()));
PacketClient.sendClient(new AnimationClonePacket(animation.id));
}
}
@@ -544,65 +544,80 @@ public class RenderNPCInterface extends RenderLiving {
@Override
public ResourceLocation getEntityTexture(Entity entity) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
if (npc.textureLocation == null) {
if (npc.display.skinType == 0) {
// Early exit if texture already resolved
if (npc.textureLocation != null) {
return npc.textureLocation;
}
// SkinType 0: custom texture or default
if (npc.display.skinType == 0) {
if (npc.display.texture.isEmpty()) {
return npc.textureLocation = fallBackSkin(npc);
}
try {
if (npc instanceof EntityCustomNpc && ((EntityCustomNpc) npc).modelData.entityClass == null) {
if (!(npc.display.texture).isEmpty()) {
try {
npc.textureLocation = adjustLocalTexture(npc, new ResourceLocation(npc.display.texture));
} catch (IOException ignored) {
}
}
npc.textureLocation = adjustLocalTexture(npc, new ResourceLocation(npc.display.texture));
} else {
npc.textureLocation = new ResourceLocation(npc.display.texture);
ResourceLocation resLoc = new ResourceLocation(npc.display.texture);
Minecraft.getMinecraft().getResourceManager().getResource(resLoc);
npc.textureLocation = resLoc;
}
} else if (npc.display.skinType == 1 && npc.display.playerProfile != null) {
Minecraft minecraft = Minecraft.getMinecraft();
Map map = minecraft.func_152342_ad().func_152788_a(npc.display.playerProfile);
if (map.containsKey(Type.SKIN)) {
npc.textureLocation = minecraft.func_152342_ad().func_152792_a((MinecraftProfileTexture) map.get(Type.SKIN), Type.SKIN);
}
LastTextureTick = 0;
} else if (npc.display.skinType == 2 || npc.display.skinType == 3) {
ResourceLocation location = new ResourceLocation("skins/" + (npc.display.skinType + npc.display.url).hashCode());
// If URL Empty Steve
if (npc.display.url.isEmpty()) {
return fallBackSkin(npc);
}
// If URL Cached then grab it
else if (ClientCacheHandler.isCachedNPC(location)) {
try {
ResourceLocation loc = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.skinType == 3, location).getLocation();
if (loc != null) {
npc.textureLocation = loc;
} else {
return fallBackSkin(npc);
}
} catch (Exception ignored) {
}
}
// For New URL Requests do not spam it
else if (LastTextureTick < 5) { //fixes request flood somewhat
return fallBackSkin(npc);
} else {
try {
ResourceLocation loc = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.skinType == 3, location).getLocation();
if (loc != null) {
npc.textureLocation = loc;
} else {
return fallBackSkin(npc);
}
LastTextureTick = 0;
} catch (Exception ignored) {
}
}
} else {
} catch (IOException ignored) {
return fallBackSkin(npc);
}
}
return npc.textureLocation;
// SkinType 1: player profile skin
else if (npc.display.skinType == 1 && npc.display.playerProfile != null) {
final Minecraft minecraft = Minecraft.getMinecraft();
Map map = minecraft.func_152342_ad().func_152788_a(npc.display.playerProfile);
if (map.containsKey(Type.SKIN)) {
npc.textureLocation = minecraft.func_152342_ad()
.func_152792_a((MinecraftProfileTexture) map.get(Type.SKIN), Type.SKIN);
}
LastTextureTick = 0;
}
// SkinType 2 / 3: load from URL
else if (npc.display.skinType == 2 || npc.display.skinType == 3) {
if (npc.display.url.isEmpty()) { // If URL is empty → fallback
return fallBackSkin(npc);
}
ResourceLocation location = new ResourceLocation("skins/" + (npc.display.skinType + npc.display.url).hashCode());
try {
if (ClientCacheHandler.isCachedNPC(location)) { // If URL is cached
ResourceLocation loc = ClientCacheHandler
.getNPCTexture(npc.display.url, npc.display.skinType == 3, location)
.getLocation();
if (loc == null) return fallBackSkin(npc);
npc.textureLocation = loc;
} else if (LastTextureTick >= 5) { // Prevent request flooding
ResourceLocation loc = ClientCacheHandler
.getNPCTexture(npc.display.url, npc.display.skinType == 3, location)
.getLocation();
if (loc == null) return fallBackSkin(npc);
npc.textureLocation = loc;
LastTextureTick = 0;
} else {
return fallBackSkin(npc);
}
} catch (Exception ignored) {
return fallBackSkin(npc);
}
}
// Fallback: if no valid skin type matched
else {
return fallBackSkin(npc);
}
// Final safety net
return npc.textureLocation == null ? fallBackSkin(npc) : npc.textureLocation;
}
private ResourceLocation adjustLocalTexture(EntityNPCInterface npc, ResourceLocation location) throws IOException {
@@ -311,6 +311,28 @@ public class AnimationController implements IAnimationHandler {
return false;
}
public Animation cloneAnimation(int originalId) {
Animation original = animations.get(originalId);
if (original == null || original instanceof BuiltInAnimation) return null;
int originalCatId = categoryManager.getItemCategory(originalId);
Animation clone = new Animation();
clone.readFromNBT(original.writeToNBT());
clone.id = getUnusedId();
String name = clone.name;
while (hasName(name)) name += "_";
clone.name = name;
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
categoryManager.registerItem(clone.id, originalCatId);
}
saveAnimation(clone);
return clone;
}
public void delete(String name) {
Animation delete = getAnimationFromName(name);
if (delete != null) {
@@ -712,6 +712,8 @@ public class CustomEffectController implements ICustomEffectHandler {
CustomEffect original = getCustomEffects().get(originalId);
if (original == null) return null;
int originalCatId = categoryManager.getItemCategory(originalId);
NBTTagCompound nbt = original.writeToNBT(true);
int newId = getUnusedId();
nbt.setInteger("ID", newId);
@@ -723,6 +725,10 @@ public class CustomEffectController implements ICustomEffectHandler {
while (has(name)) name += "_";
clone.name = name;
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
categoryManager.registerItem(newId, originalCatId);
}
saveEffect(clone);
return clone;
}
@@ -245,6 +245,8 @@ public class LinkedItemController implements ILinkedItemHandler {
LinkedItem original = linkedItems.get(originalId);
if (original == null) return null;
int originalCatId = categoryManager.getItemCategory(originalId);
NBTTagCompound nbt = original.writeToNBT(true);
int newId = getUnusedId();
nbt.setInteger("Id", newId);
@@ -256,6 +258,10 @@ public class LinkedItemController implements ILinkedItemHandler {
while (hasName(name)) name += "_";
clone.name = name;
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
categoryManager.registerItem(newId, originalCatId);
}
saveLinkedItem(clone);
return clone;
}
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.api.handler.data.IQuestCategory;
@@ -21,8 +22,8 @@ public class QuestCategory implements IQuestCategory {
public void readNBT(NBTTagCompound nbttagcompound) {
id = nbttagcompound.getInteger("Slot");
title = nbttagcompound.getString("Title");
NBTTagList questList = nbttagcompound.getTagList("Quests", 10);
if (questList != null) {
NBTTagList questList = getFirstValidList(nbttagcompound, Constants.NBT.TAG_COMPOUND, "Quests", "Dialogs");
if (questList.tagCount() > 0) {
for (int ii = 0; ii < questList.tagCount(); ii++) {
NBTTagCompound nbttagcompound2 = questList.getCompoundTagAt(ii);
Quest quest = new Quest();
@@ -33,6 +34,18 @@ public class QuestCategory implements IQuestCategory {
}
}
private NBTTagList getFirstValidList(NBTTagCompound nbt, int type, String... keys) {
for (String key : keys) {
if (nbt.hasKey(key, Constants.NBT.TAG_LIST)) {
NBTTagList list = nbt.getTagList(key, type);
if (list.tagCount() > 0) {
return list;
}
}
}
return new NBTTagList();
}
public NBTTagCompound writeNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("Slot", id);
nbttagcompound.setString("Title", title);