Compare commits

...
36 Commits
Author SHA1 Message Date
Kam 0fe357d360 Remove Duplicate 2025-03-16 15:44:21 -04:00
Kam 0f6e190538 Merge branch 'dev' into edit-gui 2025-03-16 15:43:50 -04:00
Kam 6c9b74ceb0 beta7 + todo update 2025-03-16 04:46:21 -04:00
Kam 425760c96a Fix Animation Editor 2025-03-16 04:26:25 -04:00
Kam 0cbee3cdb9 This the best i can make it for now 🎱 2025-03-16 04:10:33 -04:00
Kam 8cf67e9ad2 Fix Cast Crash 2025-03-16 00:06:48 -04:00
Kam 18eb9c5494 Fix Connections 2025-03-15 17:59:35 -04:00
Kam da5102765b Working 2 Way Diagram Arrows 2025-03-15 17:42:28 -04:00
Kam 9bd7575b3c Fixed two way drawing 2025-03-15 17:38:49 -04:00
Kam e74e41b594 Fix Coloring 2025-03-15 17:13:19 -04:00
Kam dbe49cae10 improved color scaling 2025-03-15 16:03:45 -04:00
Kam 0e8cc2256b Future Fix 2025-03-15 15:47:44 -04:00
Kam 823b4b95a0 Revert "More Diagram Fixes"
This reverts commit 2964100311.
2025-03-15 15:01:49 -04:00
Kam 2964100311 More Diagram Fixes 2025-03-15 06:30:11 -04:00
Kam d42dc0052f Fix Arrow Heads 2025-03-14 20:58:46 -04:00
Kam d6dc743611 Better Default Magic Cycle 2025-03-14 20:57:43 -04:00
Kam 0cfd11298d More Advanced Perms 2025-03-14 20:38:18 -04:00
Kam 6237856f70 Better Advanced Packet Permissions 2025-03-14 20:38:11 -04:00
Kam 3e10207b41 Magic Book Item + Magic Player Packets 2025-03-14 20:32:26 -04:00
Kam 62046b10e6 Add Nates Hammer Texture 2025-03-14 19:21:01 -04:00
Kam 258e376516 Fix Overlay crash 2025-03-14 19:20:52 -04:00
Kam c3da8f27dc DBC Addon Supporting Better Animations 2025-03-14 16:27:13 -04:00
Kam 8d55502f6e If DBC Addon installed handle Animations on DBC Addon End 2025-03-14 16:03:06 -04:00
Kam 1abb1bd679 Update todo.txt 2025-03-14 05:47:39 -04:00
Kam e7c46c18be 1.10 beta 6 2025-03-14 05:37:10 -04:00
Kam 9691c90ffc Scripting for Attribute Handling on Players, Items, Totals, etc 2025-03-14 05:35:23 -04:00
Kam 7f5ba9a1c4 Add Movement Speed, Knockback Res and Health % Boost Modifiers to Items 2025-03-14 04:40:19 -04:00
Kam 3dc08696f7 Fix Inventory Script for DBC Players 2025-03-14 04:22:31 -04:00
Kam 7432373533 Change Hooks for Effects 2025-03-14 03:33:10 -04:00
Kam d9aea174f4 Fix GetEffectDuration 2025-03-13 19:55:35 -04:00
Kam fb7e13d70a Beta 5 2025-03-13 17:54:58 -04:00
Kam 500bfc3b3c FACTION TAB TAKES TO EDITOR - REMOVE 2025-03-05 04:47:54 -05:00
Kam b2fb46db64 Unfocus Textfield on Close 2025-03-05 04:45:38 -05:00
Kam cba1f6268f Better Working GUI Component Editor 2025-03-05 04:43:39 -05:00
Kam 3c1f7f9e60 Another Rendition Rewrite 2025-03-05 03:34:30 -05:00
Kam f94f80ea41 Push of Custom Editor GUI to Public 2025-03-05 03:19:29 -05:00
84 changed files with 2596 additions and 360 deletions

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ plugins {
id 'idea'
}
version = "1.10-testingbeta1"
version = "1.10-testingbeta7"
group= "kamkeel.customnpc-plus"
archivesBaseName = "CustomNPC-Plus"
+1 -1
Submodule src/api updated: c7a74a3e0e...dfa15687d0.
@@ -12,6 +12,7 @@ import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestCompletedR
*/
public class CustomAttributes {
public static final String HEALTH_KEY = "health";
public static final String HEALTH_BOOST_KEY = "health_boost";
public static final String MAIN_ATTACK_KEY = "main_attack";
public static final String MAIN_ATTACK_BOOST_KEY = "main_attack_boost";
public static final String NEUTRAL_KEY = "neutral";
@@ -22,24 +23,28 @@ public class CustomAttributes {
public static final String MAGIC_BOOST_KEY = "magic_boost";
public static final String MAGIC_DEFENSE_KEY = "magic_defense";
public static final String MAGIC_RESISTANCE_KEY = "magic_resistance";
public static final String MOVEMENT_SPEED_KEY = "movement_speed";
public static final String KNOCKBACK_RES_KEY = "knockback_res";
public static AttributeDefinition HEALTH;
public static AttributeDefinition HEALTH_BOOST;
public static AttributeDefinition MAIN_ATTACK;
public static AttributeDefinition MAIN_BOOST;
public static AttributeDefinition NEUTRAL_ATTACK;
public static AttributeDefinition NEUTRAL_BOOST;
public static AttributeDefinition HEALTH;
public static AttributeDefinition CRITICAL_CHANCE;
public static AttributeDefinition CRITICAL_DAMAGE;
public static AttributeDefinition MAGIC_DAMAGE;
public static AttributeDefinition MAGIC_BOOST;
public static AttributeDefinition MAGIC_DEFENSE;
public static AttributeDefinition MAGIC_RESISTANCE;
public static AttributeDefinition MOVEMENT_SPEED;
public static AttributeDefinition KNOCKBACK_RES;
public CustomAttributes() {
HEALTH = AttributeController.registerAttribute(HEALTH_KEY, "Health", 'c', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
HEALTH_BOOST = AttributeController.registerAttribute(HEALTH_BOOST_KEY, "Health Boost", 'c', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
HEALTH_BOOST.setTranslationKey("attribute.name.generic.maxHealth");
MAIN_ATTACK = AttributeController.registerAttribute(MAIN_ATTACK_KEY, "Main Attack Damage", '4', AttributeValueType.FLAT, AttributeDefinition.AttributeSection.BASE);
MAIN_BOOST = AttributeController.registerAttribute(MAIN_ATTACK_BOOST_KEY, "Main Attack Damage", '4', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
@@ -56,6 +61,11 @@ public class CustomAttributes {
MAGIC_DEFENSE = AttributeController.registerAttribute(MAGIC_DEFENSE_KEY, "Magic Defense", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.BASE);
MAGIC_RESISTANCE = AttributeController.registerAttribute(MAGIC_RESISTANCE_KEY, "Magic Resistance", 'b', AttributeValueType.MAGIC, AttributeDefinition.AttributeSection.MODIFIER);
MOVEMENT_SPEED = AttributeController.registerAttribute(MOVEMENT_SPEED_KEY, "Movement Speed", 'a', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
MOVEMENT_SPEED.setTranslationKey("attribute.name.generic.movementSpeed");
KNOCKBACK_RES = AttributeController.registerAttribute(KNOCKBACK_RES_KEY, "Knockback Resistance", 'b', AttributeValueType.PERCENT, AttributeDefinition.AttributeSection.MODIFIER);
KNOCKBACK_RES.setTranslationKey("attribute.name.generic.knockbackResistance");
// TODO: Attributes
// Durability Attribute
@@ -1,6 +1,11 @@
package kamkeel.npcs.addon.client;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.mainmenu.GuiNpcStats;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
@@ -42,4 +47,8 @@ public class DBCClient {
public GuiNPCInterface2 manageCustomAuras(EntityNPCInterface npcInterface) {
return null;
}
// Animation Render Helper
public void applyRenderModel(ModelRenderer renderer){}
public boolean firstPersonAnimation(float partialRenderTick, EntityPlayer player, ModelBiped model, RenderBlocks renderBlocksIr, ResourceLocation resItemGlint) { return false; }
}
@@ -5,6 +5,10 @@ import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
import kamkeel.npcs.controllers.data.attribute.AttributeValueType;
import kamkeel.npcs.controllers.data.attribute.tracker.PlayerAttributeTracker;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.IAttributeHandler;
import noppes.npcs.api.handler.data.IAttributeDefinition;
import noppes.npcs.api.handler.data.IPlayerAttributes;
import java.util.Collection;
import java.util.HashMap;
@@ -15,9 +19,9 @@ import java.util.UUID;
* AttributeController is the central registry for attribute definitions.
* It ensures that keys are unique.
*/
public class AttributeController {
public class AttributeController implements IAttributeHandler {
public AttributeController Instance;
public static AttributeController Instance;
public CustomAttributes attributes;
// Tracking Player Attributes
@@ -25,7 +29,7 @@ public class AttributeController {
private static final Map<String, AttributeDefinition> definitions = new HashMap<>();
public AttributeController() {
this.Instance = this;
Instance = this;
definitions.clear();
trackers.clear();
attributes = new CustomAttributes();
@@ -75,4 +79,20 @@ public class AttributeController {
tracker.updateIfChanged(player);
}
}
public IPlayerAttributes getPlayerAttributes(IPlayer player) {
if(player == null || player.getMCEntity() == null)
return null;
EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity();
return trackers.computeIfAbsent(entityPlayer.getUniqueID(), id -> new PlayerAttributeTracker(id));
}
public IAttributeDefinition getAttributeDefinition(String key) {
return definitions.get(key);
}
public IAttributeDefinition[] getAllAttributesArray() {
return definitions.values().toArray(new AttributeDefinition[definitions.size()]);
}
}
@@ -1,6 +1,8 @@
package kamkeel.npcs.controllers.data.attribute;
public class AttributeDefinition {
import noppes.npcs.api.handler.data.IAttributeDefinition;
public class AttributeDefinition implements IAttributeDefinition {
private final String key;
private String translationKey;// e.g., "main_attack_flat"
private final String displayName; // Human‑readable name
@@ -1,12 +0,0 @@
package kamkeel.npcs.controllers.data.attribute;
/**
* IAttributeInstance represents an instance of an attribute (with a base value and applied modifiers).
*/
public interface ICustomAttribute {
AttributeDefinition getAttribute();
float getValue();
void setValue(float value);
}
@@ -1,13 +1,15 @@
package kamkeel.npcs.controllers.data.attribute;
import noppes.npcs.api.handler.data.ICustomAttribute;
public class PlayerAttribute implements ICustomAttribute {
private final AttributeDefinition attribute;
private float baseValue;
public float value;
public PlayerAttribute(AttributeDefinition attribute, float baseValue) {
public PlayerAttribute(AttributeDefinition attribute, float value) {
this.attribute = attribute;
this.baseValue = baseValue;
this.value = value;
}
@Override
@@ -17,11 +19,6 @@ public class PlayerAttribute implements ICustomAttribute {
@Override
public float getValue() {
return baseValue;
}
@Override
public void setValue(float value) {
this.baseValue = value;
return value;
}
}
@@ -1,5 +1,7 @@
package kamkeel.npcs.controllers.data.attribute;
import noppes.npcs.api.handler.data.ICustomAttribute;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -8,22 +10,18 @@ import java.util.Map;
* CustomAttributeMap holds a set of attribute instances for an entity (or item).
*/
public class PlayerAttributeMap {
private final Map<AttributeDefinition, ICustomAttribute> map = new HashMap<>();
public final Map<AttributeDefinition, PlayerAttribute> map = new HashMap<>();
public ICustomAttribute registerAttribute(AttributeDefinition attribute, float baseValue) {
public PlayerAttribute registerAttribute(AttributeDefinition attribute, float baseValue) {
if (map.containsKey(attribute)) {
throw new IllegalArgumentException("Attribute already registered: " + attribute.getKey());
}
ICustomAttribute instance = new PlayerAttribute(attribute, baseValue);
PlayerAttribute instance = new PlayerAttribute(attribute, baseValue);
map.put(attribute, instance);
return instance;
}
public ICustomAttribute getAttributeInstance(AttributeDefinition attribute) {
public PlayerAttribute getAttributeInstance(AttributeDefinition attribute) {
return map.get(attribute);
}
public Collection<ICustomAttribute> getAllAttributes() {
return map.values();
}
}
@@ -11,6 +11,8 @@ public interface IRequirementChecker {
String getTooltipValue(NBTTagCompound nbt);
Object getValue(NBTTagCompound nbt);
void apply(NBTTagCompound nbt, Object value);
/**
@@ -29,6 +29,14 @@ public class QuestActiveRequirement implements IRequirementChecker {
return "null";
}
@Override
public Object getValue(NBTTagCompound nbt) {
if (nbt.hasKey(getKey())) {
return nbt.getInteger(getKey());
}
return null;
}
@Override
public void apply(NBTTagCompound nbt, Object value) {
if (value instanceof Integer) {
@@ -36,6 +36,14 @@ public class QuestCompletedRequirement implements IRequirementChecker {
}
}
@Override
public Object getValue(NBTTagCompound nbt) {
if (nbt.hasKey(getKey())) {
return nbt.getInteger(getKey());
}
return null;
}
@Override
public boolean check(EntityPlayer player, NBTTagCompound nbt) {
if (nbt.hasKey(getKey())) {
@@ -3,7 +3,9 @@ package kamkeel.npcs.controllers.data.attribute.tracker;
import kamkeel.npcs.CustomAttributes;
import kamkeel.npcs.controllers.AttributeController;
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
import kamkeel.npcs.controllers.data.attribute.ICustomAttribute;
import kamkeel.npcs.controllers.data.attribute.PlayerAttribute;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.ICustomAttribute;
import kamkeel.npcs.controllers.data.attribute.PlayerAttributeMap;
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
import kamkeel.npcs.util.AttributeAttackUtil;
@@ -14,21 +16,28 @@ import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IPlayerAttributes;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
public class PlayerAttributeTracker {
public class PlayerAttributeTracker implements IPlayerAttributes {
public static UUID healthUUID = UUID.fromString("48a0ad75-2cf8-4838-ad2f-9a0aadc57dfe");
public static UUID healthBoostUUID = UUID.fromString("93cfba41-294a-4e6b-a98b-bee76a9f813b");
public static UUID movementSpeedUUID = UUID.fromString("e7e0dd10-8ed5-42fb-8167-e71f8de4ea0c");
public static UUID knockbackResUUID = UUID.fromString("b2f261e8-34f0-4140-9828-b56c1f6e0ff2");
private final UUID playerId;
private PlayerAttributeMap playerAttributes = new PlayerAttributeMap();
public float extraHealth = 0;
public float extraHealthBoost = 0;
public float movementSpeed = 0;
public float knockbackRes = 0;
public float gearOutput = 0.0f;
public final Map<Integer, Float> magicDamage = new HashMap<>();
@@ -44,10 +53,6 @@ public class PlayerAttributeTracker {
recalcAttributes(null);
}
public PlayerAttributeMap getPlayerAttributes() {
return playerAttributes;
}
public void recalcAttributes(EntityPlayer player) {
// Reset aggregated attributes and magic maps.
playerAttributes = new PlayerAttributeMap();
@@ -77,11 +82,11 @@ public class PlayerAttributeTracker {
float value = entry.getValue();
AttributeDefinition def = AttributeController.getAttribute(key);
if (def != null) {
ICustomAttribute inst = playerAttributes.getAttributeInstance(def);
PlayerAttribute inst = playerAttributes.getAttributeInstance(def);
if (inst == null) {
inst = playerAttributes.registerAttribute(def, 0.0f);
}
inst.setValue(inst.getValue() + value);
inst.value = (inst.getValue() + value);
}
}
// Process Magic
@@ -117,9 +122,16 @@ public class PlayerAttributeTracker {
}
equipmentTracker = currentEquip;
gearOutput = AttributeAttackUtil.calculateGearOutput(this);
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
extraHealth = getAttributeValue(CustomAttributes.HEALTH);
extraHealthBoost = getAttributeValue(CustomAttributes.HEALTH_BOOST);
movementSpeed = getAttributeValue(CustomAttributes.MOVEMENT_SPEED);
knockbackRes = getAttributeValue(CustomAttributes.KNOCKBACK_RES);
// Update vanilla attributes with our aggregated values.
updatePlayerMaxHealth(player);
updatePlayerMovementSpeed(player);
updatePlayerKnockbackRes(player);
// Post Recalculation Event to Listeners
AttributeRecalcEvent.post(player, this);
@@ -134,24 +146,61 @@ public class PlayerAttributeTracker {
*/
public void updatePlayerMaxHealth(EntityPlayer player) {
float bonusHealth = extraHealth;
float healthBoostPercent = extraHealthBoost / 100;
IAttributeInstance maxHealthAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth);
try {
AttributeModifier old = maxHealthAttr.getModifier(healthUUID);
if (old != null) {
maxHealthAttr.removeModifier(old);
AttributeModifier oldFlat = maxHealthAttr.getModifier(healthUUID);
if (oldFlat != null) {
maxHealthAttr.removeModifier(oldFlat);
}
} catch (Exception ignored) {
}
AttributeModifier oldBoost = maxHealthAttr.getModifier(healthBoostUUID);
if (oldBoost != null) {
maxHealthAttr.removeModifier(oldBoost);
}
} catch (Exception ignored) { }
// Apply the flat bonus (operation 0)
if (bonusHealth != 0) {
maxHealthAttr.applyModifier(new AttributeModifier(healthUUID, "RPGCoreHealthBonus", bonusHealth, 0));
}
// Ensure the player's current health does not exceed the new maximum.
// Apply the percent boost (operation 1 multiplies the base health, here assumed to be 20)
if (healthBoostPercent != 0) {
maxHealthAttr.applyModifier(new AttributeModifier(healthBoostUUID, "RPGCoreHealthBoost", healthBoostPercent, 1));
}
// Ensure current health is within the new maximum.
float currentHealth = player.getHealth();
if (currentHealth > maxHealthAttr.getAttributeValue()) {
player.setHealth((float) maxHealthAttr.getAttributeValue());
}
}
public void updatePlayerMovementSpeed(EntityPlayer player) {
float extraSpeed = movementSpeed / 100;
IAttributeInstance speedAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.movementSpeed);
try {
AttributeModifier old = speedAttr.getModifier(movementSpeedUUID);
if (old != null) {
speedAttr.removeModifier(old);
}
} catch (Exception ignored) { }
if (extraSpeed != 0) {
speedAttr.applyModifier(new AttributeModifier(movementSpeedUUID, "RPGCoreMovementSpeed", extraSpeed, 1));
}
}
public void updatePlayerKnockbackRes(EntityPlayer player) {
float extraRes = knockbackRes / 100;
IAttributeInstance knockResAttr = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.knockbackResistance);
try {
AttributeModifier old = knockResAttr.getModifier(knockbackResUUID);
if (old != null) {
knockResAttr.removeModifier(old);
}
} catch (Exception ignored) { }
if (extraRes != 0) {
knockResAttr.applyModifier(new AttributeModifier(knockbackResUUID, "RPGCoreKnockbackRes", extraRes, 1));
}
}
/**
* Checks if the player's equipment has changed and recalculates attributes if needed.
*/
@@ -167,4 +216,43 @@ public class PlayerAttributeTracker {
ICustomAttribute inst = playerAttributes.getAttributeInstance(def);
return inst != null ? inst.getValue() : 0.0f;
}
public void recalculate(IPlayer player) {
if(player == null || player.getMCEntity() == null)
return;
recalcAttributes((EntityPlayer) player.getMCEntity());
}
public ICustomAttribute[] getAttributes() {
return playerAttributes.map.values().toArray(new ICustomAttribute[playerAttributes.map.size()]);
}
public float getAttributeValue(String key) {
for (ICustomAttribute inst : getAttributes()) {
if (inst.getAttribute().getKey().equalsIgnoreCase(key)) {
return inst.getValue();
}
}
return 0.0f;
}
public boolean hasAttribute(String key) {
for (ICustomAttribute inst : getAttributes()) {
if (inst.getAttribute().getKey().equalsIgnoreCase(key)) {
return true;
}
}
return false;
}
public ICustomAttribute getAttribute(String key) {
for (ICustomAttribute inst : getAttributes()) {
if (inst.getAttribute().getKey().equalsIgnoreCase(key)) {
return inst;
}
}
return null;
}
}
@@ -0,0 +1,57 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.gui.Gui;
/**
* AbstractEditorComponent provides common fields and methods for all editor components.
*/
public abstract class AbstractEditorComponent extends Gui implements IEditorComponent {
// Store the editor component's ID.
protected int id;
// Position and size.
public int posX, posY, width, height;
protected boolean selected = false;
public AbstractEditorComponent(int posX, int posY, int width, int height) {
this.posX = posX;
this.posY = posY;
this.width = width;
this.height = height;
}
/**
* Returns the ID for this editor component.
*/
public int getID() {
return id;
}
@Override
public void setSelected(boolean selected) {
this.selected = selected;
}
@Override
public boolean isSelected() {
return selected;
}
/**
* Draws an outline around the component.
* Yellow if selected; grey if not.
*/
protected void renderSelectionOutline() {
int outlineColor = selected ? 0xFFFFFF00 : 0xFF888888;
// Top border
drawRect(posX - 1, posY - 1, posX + width + 1, posY, outlineColor);
// Bottom border
drawRect(posX - 1, posY + height, posX + width + 1, posY + height + 1, outlineColor);
// Left border
drawRect(posX - 1, posY - 1, posX, posY + height + 1, outlineColor);
// Right border
drawRect(posX + width, posY - 1, posX + width + 1, posY + height + 1, outlineColor);
}
@Override
public void update() { }
}
@@ -0,0 +1,42 @@
package kamkeel.npcs.editorgui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
/**
* CustomGuiEditorController handles saving and loading of ScriptGui objects.
*/
public class CustomGuiEditorController {
private ScriptGui currentGui;
public CustomGuiEditorController() {
currentGui = new ScriptGui();
}
public void saveGui(File file, ScriptGui gui) {
NBTTagCompound compound = gui.toNBT();
try {
NBTJsonUtil.SaveFile(file, compound);
} catch(Exception e) {
e.printStackTrace();
}
currentGui = gui;
}
public ScriptGui loadGui(File file) {
try {
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
currentGui = (ScriptGui) (new ScriptGui()).fromNBT(compound);
} catch(Exception e) {
e.printStackTrace();
}
return currentGui;
}
public void applyGuiToPlayer(EntityPlayer player) {
// player.showCustomGui(currentGui);
}
}
@@ -0,0 +1,148 @@
package kamkeel.npcs.editorgui;
import noppes.npcs.scripted.gui.ScriptGuiButton;
import noppes.npcs.client.gui.custom.components.CustomGuiButton;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.util.List;
/**
* EditorButtonComponent wraps a ScriptGuiButton for editing.
*/
public class EditorButtonComponent extends AbstractEditorComponent {
private ScriptGuiButton buttonComponent;
public EditorButtonComponent(ScriptGuiButton button) {
super(button.getPosX(), button.getPosY(), button.getWidth(), button.getHeight());
this.buttonComponent = button;
this.id = button.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiButton renderBtn = CustomGuiButton.fromComponent(buttonComponent);
renderBtn.xPosition = this.posX;
renderBtn.yPosition = this.posY;
renderBtn.scale = buttonComponent.getScale();
renderBtn.alpha = buttonComponent.getAlpha();
renderBtn.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX <= posX + width &&
mouseY >= posY && mouseY <= posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
buttonComponent.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return buttonComponent;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(101, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(102, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(103, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(104, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(105, 0, 0, 30, 20, "Sc"));
buttonList.add(new GuiButton(106, 0, 0, 30, 20, "Al"));
buttonList.add(new GuiButton(107, 0, 0, 30, 20, "Rt"));
buttonList.add(new GuiButton(108, 0, 0, 30, 20, "Lbl"));
buttonList.add(new GuiButton(110, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch (button.id) {
case 101:
width += 5;
buttonComponent.setSize(width, height);
break;
case 102:
width = Math.max(10, width - 5);
buttonComponent.setSize(width, height);
break;
case 103:
height += 5;
buttonComponent.setSize(width, height);
break;
case 104:
height = Math.max(10, height - 5);
buttonComponent.setSize(width, height);
break;
case 105:
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(buttonComponent.getScale()),
newValue -> {
try {
float newScale = Float.parseFloat(newValue);
buttonComponent.setScale(newScale);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 106:
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(buttonComponent.getAlpha()),
newValue -> {
try {
float newAlpha = Float.parseFloat(newValue);
buttonComponent.setAlpha(newAlpha);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 107:
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(buttonComponent.getRotation()),
newValue -> {
try {
float newRot = Float.parseFloat(newValue);
buttonComponent.setRotation(newRot);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 108:
editor.setSubGuiOverlay(new SubGuiEditProperty("Label", buttonComponent.getLabel(),
newValue -> buttonComponent.setLabel(newValue), () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 110:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(buttonComponent.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
buttonComponent.setID(newID);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,146 @@
package kamkeel.npcs.editorgui;
import noppes.npcs.scripted.gui.ScriptGuiLabel;
import noppes.npcs.client.gui.custom.components.CustomGuiLabel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.util.List;
public class EditorLabelComponent extends AbstractEditorComponent {
private ScriptGuiLabel labelComponent;
public EditorLabelComponent(ScriptGuiLabel label) {
super(label.getPosX(), label.getPosY(), label.getWidth(), label.getHeight());
this.labelComponent = label;
this.id = label.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiLabel renderLbl = CustomGuiLabel.fromComponent(labelComponent);
renderLbl.x = this.posX;
renderLbl.y = this.posY;
renderLbl.setScale(labelComponent.getScale());
renderLbl.alpha = labelComponent.getAlpha();
renderLbl.rotation = labelComponent.getRotation();
renderLbl.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX <= posX + width &&
mouseY >= posY && mouseY <= posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
labelComponent.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return labelComponent;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(201, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(202, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(203, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(204, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(205, 0, 0, 30, 20, "Sc"));
buttonList.add(new GuiButton(206, 0, 0, 30, 20, "Al"));
buttonList.add(new GuiButton(207, 0, 0, 30, 20, "Rt"));
buttonList.add(new GuiButton(208, 0, 0, 30, 20, "Txt"));
buttonList.add(new GuiButton(210, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch(button.id) {
case 201:
width += 5;
labelComponent.setSize(width, height);
break;
case 202:
width = Math.max(10, width - 5);
labelComponent.setSize(width, height);
break;
case 203:
height += 5;
labelComponent.setSize(width, height);
break;
case 204:
height = Math.max(10, height - 5);
labelComponent.setSize(width, height);
break;
case 205:
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(labelComponent.getScale()),
newValue -> {
try {
float newScale = Float.parseFloat(newValue);
labelComponent.setScale(newScale);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 206:
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(labelComponent.getAlpha()),
newValue -> {
try {
float newAlpha = Float.parseFloat(newValue);
labelComponent.setAlpha(newAlpha);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 207:
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(labelComponent.getRotation()),
newValue -> {
try {
float newRot = Float.parseFloat(newValue);
labelComponent.setRotation(newRot);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 208:
editor.setSubGuiOverlay(new SubGuiEditProperty("Text", labelComponent.getText(),
newValue -> labelComponent.setText(newValue), () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 210:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(labelComponent.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
labelComponent.setID(newID);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,109 @@
package kamkeel.npcs.editorgui;
import noppes.npcs.scripted.gui.ScriptGuiTextField;
import noppes.npcs.client.gui.custom.components.CustomGuiTextField;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.util.List;
/**
* EditorTextFieldComponent wraps a ScriptGuiTextField.
* It renders the actual text field and provides editing buttons for width, height, default text, and ID.
*/
public class EditorTextFieldComponent extends AbstractEditorComponent {
private ScriptGuiTextField textFieldComponent;
public EditorTextFieldComponent(ScriptGuiTextField textField) {
// TextField uses its original width, height, and position.
super(textField.getPosX(), textField.getPosY(), textField.getWidth(), textField.getHeight());
this.textFieldComponent = textField;
this.id = textField.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiTextField renderField = CustomGuiTextField.fromComponent(textFieldComponent);
renderField.xPosition = this.posX;
renderField.yPosition = this.posY;
renderField.drawTextBox();
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX < posX + width &&
mouseY >= posY && mouseY < posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
textFieldComponent.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return textFieldComponent;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(301, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(302, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(303, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(304, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(307, 0, 0, 30, 20, "Txt"));
buttonList.add(new GuiButton(310, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch(button.id) {
case 301:
width += 5;
textFieldComponent.setSize(width, height);
break;
case 302:
width = Math.max(10, width - 5);
textFieldComponent.setSize(width, height);
break;
case 303:
height += 5;
textFieldComponent.setSize(width, height);
break;
case 304:
height = Math.max(10, height - 5);
textFieldComponent.setSize(width, height);
break;
case 307:
editor.setSubGuiOverlay(new SubGuiEditProperty("Default Text", textFieldComponent.getText(),
newValue -> textFieldComponent.setText(newValue), () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 310:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(textFieldComponent.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
textFieldComponent.setID(newID);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,172 @@
package kamkeel.npcs.editorgui;
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
import noppes.npcs.client.gui.custom.components.CustomGuiTexturedRect;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.util.List;
public class EditorTexturedRectComponent extends AbstractEditorComponent {
private ScriptGuiTexturedRect texturedRect;
public EditorTexturedRectComponent(ScriptGuiTexturedRect rect) {
super(rect.getPosX(), rect.getPosY(), rect.getWidth(), rect.getHeight());
this.texturedRect = rect;
this.id = rect.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiTexturedRect renderRect = CustomGuiTexturedRect.fromComponent(texturedRect);
renderRect.x = this.posX;
renderRect.y = this.posY;
renderRect.scale = texturedRect.getScale();
renderRect.alpha = texturedRect.getAlpha();
renderRect.rotation = texturedRect.getRotation();
renderRect.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX < posX + width &&
mouseY >= posY && mouseY < posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
texturedRect.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return texturedRect;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(401, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(402, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(403, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(404, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(405, 0, 0, 30, 20, "Sc"));
buttonList.add(new GuiButton(406, 0, 0, 30, 20, "Al"));
buttonList.add(new GuiButton(407, 0, 0, 30, 20, "Rt"));
buttonList.add(new GuiButton(408, 0, 0, 30, 20, "Tex"));
buttonList.add(new GuiButton(409, 0, 0, 30, 20, "TxX"));
buttonList.add(new GuiButton(410, 0, 0, 30, 20, "TxY"));
buttonList.add(new GuiButton(411, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch(button.id) {
case 401:
width += 5;
texturedRect.setSize(width, height);
break;
case 402:
width = Math.max(10, width - 5);
texturedRect.setSize(width, height);
break;
case 403:
height += 5;
texturedRect.setSize(width, height);
break;
case 404:
height = Math.max(10, height - 5);
texturedRect.setSize(width, height);
break;
case 405:
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(texturedRect.getScale()),
newValue -> {
try {
float newScale = Float.parseFloat(newValue);
texturedRect.setScale(newScale);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 406:
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(texturedRect.getAlpha()),
newValue -> {
try {
float newAlpha = Float.parseFloat(newValue);
texturedRect.setAlpha(newAlpha);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 407:
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(texturedRect.getRotation()),
newValue -> {
try {
float newRot = Float.parseFloat(newValue);
texturedRect.setRotation(newRot);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 408:
editor.setSubGuiOverlay(new SubGuiEditProperty("Texture", texturedRect.getTexture(),
newValue -> texturedRect.setTexture(newValue), () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 409:
editor.setSubGuiOverlay(new SubGuiEditProperty("TxX", Integer.toString(texturedRect.getTextureX()),
newValue -> {
try {
int newX = Integer.parseInt(newValue);
texturedRect.setTextureOffset(newX, texturedRect.getTextureY());
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 410:
editor.setSubGuiOverlay(new SubGuiEditProperty("TxY", Integer.toString(texturedRect.getTextureY()),
newValue -> {
try {
int newY = Integer.parseInt(newValue);
texturedRect.setTextureOffset(texturedRect.getTextureX(), newY);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 411:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(texturedRect.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
texturedRect.setID(newID);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,91 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import java.util.ArrayList;
import java.util.List;
/**
* EditorToolBar renders a toolbar at the bottom with buttons to add components or save the GUI.
*/
public class EditorToolBar extends Gui {
private List<GuiButton> buttons = new ArrayList<>();
private int x, y, width, height;
public EditorToolBar(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
initButtons();
}
private void initButtons() {
buttons.clear();
// IDs: 1 = Add Button, 2 = Add Label, 3 = Add TextField, 4 = Add Rect, 8 = Save.
buttons.add(new GuiButton(1, x + 10, y + 10, 80, 20, "Add Button"));
buttons.add(new GuiButton(2, x + 100, y + 10, 80, 20, "Add Label"));
buttons.add(new GuiButton(3, x + 190, y + 10, 80, 20, "Add TextField"));
buttons.add(new GuiButton(4, x + 280, y + 10, 80, 20, "Add Rect"));
buttons.add(new GuiButton(8, x + 370, y + 10, 80, 20, "Save"));
}
public void render(int mouseX, int mouseY, float partialTicks) {
// Optionally draw a background (commented out if undesired).
// drawRect(x, y, x + width, y + height, 0xAA333333);
for (GuiButton btn : buttons) {
btn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
}
}
public List<GuiButton> getButtons() {
return buttons;
}
public void updateDimensions(int newX, int newY, int newWidth, int newHeight) {
this.x = newX;
this.y = newY;
this.width = newWidth;
this.height = newHeight;
initButtons();
}
private int getDefaultId() {
return 1;
}
public void actionPerformed(GuiButton button, GuiCustomGuiEditor editor) {
int centerX = editor.canvasX + editor.canvasWidth / 2;
int centerY = editor.canvasY + editor.canvasHeight / 2;
switch (button.id) {
case 1:
noppes.npcs.scripted.gui.ScriptGuiButton newButton =
new noppes.npcs.scripted.gui.ScriptGuiButton(getDefaultId(), "New Button", centerX - 40, centerY - 10, 80, 20);
EditorButtonComponent eButton = new EditorButtonComponent(newButton);
editor.addEditorComponent(eButton);
break;
case 2:
noppes.npcs.scripted.gui.ScriptGuiLabel newLabel =
new noppes.npcs.scripted.gui.ScriptGuiLabel(getDefaultId(), "New Label", centerX - 40, centerY - 10, 80, 20);
EditorLabelComponent eLabel = new EditorLabelComponent(newLabel);
editor.addEditorComponent(eLabel);
break;
case 3:
noppes.npcs.scripted.gui.ScriptGuiTextField newField =
new noppes.npcs.scripted.gui.ScriptGuiTextField(getDefaultId(), centerX - 50, centerY - 10, 100, 20);
EditorTextFieldComponent eField = new EditorTextFieldComponent(newField);
editor.addEditorComponent(eField);
break;
case 4:
noppes.npcs.scripted.gui.ScriptGuiTexturedRect newRect =
new noppes.npcs.scripted.gui.ScriptGuiTexturedRect(getDefaultId(), "default:texture", centerX - 40, centerY - 10, 80, 20);
EditorTexturedRectComponent eRect = new EditorTexturedRectComponent(newRect);
editor.addEditorComponent(eRect);
break;
case 8:
editor.saveAndClose();
break;
}
}
}
@@ -0,0 +1,277 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import noppes.npcs.scripted.gui.ScriptGui;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* GuiCustomGuiEditor is the main editor screen.
* The canvas covers the full scaled resolution.
* The toolbar is positioned at the bottom.
* Custom editing buttons (IDs 101–500) are arranged in a single row at the top.
* Components are sorted by ID so that higher IDs render on top.
* A SubGuiEditProperty overlay is used for property editing.
*/
public class GuiCustomGuiEditor extends GuiScreen {
// Full-screen canvas.
public int canvasX = 0;
public int canvasY = 0;
public int canvasWidth;
public int canvasHeight;
private List<IEditorComponent> editorComponents = new ArrayList<>();
private EditorToolBar toolBar;
private IEditorComponent selectedComponent;
private CustomGuiEditorController controller;
// The sub–GUI overlay for property editing; null if none is open.
private SubGuiEditProperty subGuiOverlay = null;
// For dragging: offset from mouse to component's top–left.
private int dragOffsetX, dragOffsetY;
private boolean isDragging = false;
public GuiCustomGuiEditor() {
controller = new CustomGuiEditorController();
mc = Minecraft.getMinecraft();
}
@Override
public void initGui() {
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
canvasWidth = res.getScaledWidth();
canvasHeight = res.getScaledHeight();
canvasX = 0;
canvasY = 0;
toolBar = new EditorToolBar(canvasX, canvasY + canvasHeight - 40, canvasWidth, 40);
toolBar.updateDimensions(canvasX, canvasY + canvasHeight - 40, canvasWidth, 40);
}
@Override
public void drawDefaultBackground() {
// Fill the full screen with a light background.
drawRect(canvasX, canvasY, canvasX + canvasWidth, canvasY + canvasHeight, 0xFFCCCCCC);
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
// Sort components by ID ascending so that higher IDs render on top.
toolBar.render(mouseX, mouseY, partialTicks);
super.drawScreen(mouseX, mouseY, partialTicks);
// If a sub–GUI overlay is open, draw it on top.
if (subGuiOverlay != null) {
subGuiOverlay.drawScreen(mouseX, mouseY, partialTicks);
} else {
Collections.sort(editorComponents, new Comparator<IEditorComponent>() {
@Override
public int compare(IEditorComponent o1, IEditorComponent o2) {
int id1 = ((AbstractEditorComponent) o1).getID();
int id2 = ((AbstractEditorComponent) o2).getID();
return Integer.compare(id1, id2);
}
});
for (IEditorComponent comp : editorComponents) {
comp.render(mouseX, mouseY, partialTicks);
}
}
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (subGuiOverlay != null) {
subGuiOverlay.mouseClicked(mouseX, mouseY, mouseButton);
return;
}
// Check if any custom editing button (IDs 101–500) is clicked.
for (Object obj : this.buttonList) {
GuiButton btn = (GuiButton) obj;
if (btn.id >= 101 && btn.id < 500 && btn.mousePressed(mc, mouseX, mouseY)) {
this.actionPerformed(btn);
updateCustomButtons();
return;
}
}
// Let toolbar buttons handle clicks.
for (GuiButton btn : toolBar.getButtons()) {
if (btn.mousePressed(mc, mouseX, mouseY)) {
toolBar.actionPerformed(btn, this);
updateCustomButtons();
return;
}
}
boolean anySelected = false;
for (IEditorComponent comp : editorComponents) {
if (comp.mouseClicked(mouseX, mouseY, mouseButton)) {
selectedComponent = comp;
anySelected = true;
} else {
comp.setSelected(false);
}
}
if (!anySelected) {
selectedComponent = null;
} else if (selectedComponent != null) {
dragOffsetX = mouseX - ((AbstractEditorComponent) selectedComponent).posX;
dragOffsetY = mouseY - ((AbstractEditorComponent) selectedComponent).posY;
isDragging = true;
}
updateCustomButtons();
super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void mouseMovedOrUp(int mouseX, int mouseY, int state) {
if (subGuiOverlay != null) {
subGuiOverlay.mouseMovedOrUp(mouseX, mouseY, state);
return;
}
if (selectedComponent != null) {
selectedComponent.mouseReleased(mouseX, mouseY, state);
}
isDragging = false;
super.mouseMovedOrUp(mouseX, mouseY, state);
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
if (subGuiOverlay != null) {
subGuiOverlay.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
return;
}
if (isDragging && selectedComponent != null) {
int newX = mouseX - dragOffsetX;
int newY = mouseY - dragOffsetY;
int compW = ((AbstractEditorComponent) selectedComponent).width;
int compH = ((AbstractEditorComponent) selectedComponent).height;
if (newX < canvasX) newX = canvasX;
if (newY < canvasY) newY = canvasY;
if (newX + compW > canvasWidth) newX = canvasWidth - compW;
if (newY + compH > canvasHeight) newY = canvasHeight - compH;
((AbstractEditorComponent) selectedComponent).posX = newX;
((AbstractEditorComponent) selectedComponent).posY = newY;
selectedComponent.mouseDragged(mouseX, mouseY, mouseButton);
}
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
}
@Override
public void keyTyped(char typedChar, int keyCode) {
if (subGuiOverlay != null) {
subGuiOverlay.keyTyped(typedChar, keyCode);
return;
}
if (keyCode == Keyboard.KEY_ESCAPE) {
saveAndClose();
return;
}
if (keyCode == Keyboard.KEY_DELETE || keyCode == Keyboard.KEY_BACK) {
if (selectedComponent != null) {
Iterator<IEditorComponent> iter = editorComponents.iterator();
while (iter.hasNext()) {
IEditorComponent comp = iter.next();
if (comp == selectedComponent) {
iter.remove();
selectedComponent = null;
break;
}
}
}
}
updateCustomButtons();
super.keyTyped(typedChar, keyCode);
}
@Override
protected void actionPerformed(GuiButton button) {
if (button.id >= 101 && button.id < 500) {
if (selectedComponent != null)
selectedComponent.onEditorButtonPressed(button);
updateCustomButtons();
} else {
toolBar.actionPerformed(button, this);
}
}
/**
* Updates custom editing buttons (IDs 101–500) so they appear in a single row at the top.
*/
private void updateCustomButtons() {
for (int i = buttonList.size() - 1; i >= 0; i--) {
GuiButton btn = (GuiButton) buttonList.get(i);
if (btn.id >= 101 && btn.id < 500) {
buttonList.remove(i);
}
}
if (selectedComponent != null) {
List<GuiButton> customButtons = new ArrayList<>();
selectedComponent.addEditorButtons(customButtons);
int startX = 5;
int startY = 5;
int buttonWidth = 30;
int buttonHeight = 20;
int spacing = 5;
int currentX = startX;
for (GuiButton btn : customButtons) {
btn.xPosition = currentX;
btn.yPosition = startY;
btn.width = buttonWidth;
btn.height = buttonHeight;
currentX += buttonWidth + spacing;
}
buttonList.addAll(customButtons);
}
}
/**
* Adds a new editor component.
*/
public void addEditorComponent(IEditorComponent comp) {
editorComponents.add(comp);
}
/**
* Sets the selected editor component.
*/
public void setSelectedComponent(IEditorComponent comp) {
this.selectedComponent = comp;
}
/**
* Builds a ScriptGui from the editor components, saves it, and closes the editor.
*/
public void saveAndClose() {
ScriptGui newGui = new ScriptGui();
for (IEditorComponent comp : editorComponents) {
newGui.updateComponent((noppes.npcs.api.gui.ICustomGuiComponent) comp.toScriptComponent());
}
CustomGuiEditorController controller = new CustomGuiEditorController();
controller.saveGui(new File("customgui.json"), newGui);
Minecraft.getMinecraft().displayGuiScreen(null);
}
/**
* Sets the current sub–GUI overlay (for property editing) and forwards events to it.
*/
public void setSubGuiOverlay(SubGuiEditProperty overlay) {
overlay.initGui();
this.subGuiOverlay = overlay;
}
/**
* Clears the sub–GUI overlay.
*/
public void clearSubGuiOverlay() {
this.subGuiOverlay = null;
}
}
@@ -0,0 +1,33 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import java.util.List;
/**
* IEditorComponent defines the methods that all editor wrappers must implement.
*/
public interface IEditorComponent {
void render(int mouseX, int mouseY, float partialTicks);
boolean mouseClicked(int mouseX, int mouseY, int mouseButton);
void mouseDragged(int mouseX, int mouseY, int mouseButton);
void mouseReleased(int mouseX, int mouseY, int state);
void update();
Object toScriptComponent();
void setSelected(boolean selected);
boolean isSelected();
/**
* Add custom editing buttons (IDs 101–500) to the provided list.
*/
default void addEditorButtons(List<GuiButton> buttonList) { }
/**
* Called when one of the custom editing buttons is pressed.
*/
default void onEditorButtonPressed(GuiButton button) { }
default NBTTagCompound toEditorNBT() {
return new NBTTagCompound();
}
}
@@ -0,0 +1,9 @@
package kamkeel.npcs.editorgui;
/**
* IPropertyEditorCallback is used by the property editor overlay
* to return the updated value.
*/
public interface IPropertyEditorCallback {
void propertyUpdated(String newValue);
}
@@ -0,0 +1,8 @@
package kamkeel.npcs.editorgui;
/**
* ISubGuiCallback allows a sub–GUI overlay to notify its parent when it’s done.
*/
public interface ISubGuiCallback {
void onSubGuiClosed();
}
@@ -0,0 +1,131 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.ScaledResolution;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
/**
* SubGuiEditProperty is a modal overlay for editing a single property.
* It overlays on top of the current editor screen.
* When "Done" is pressed, the provided property callback is invoked and the overlay is closed.
* All overridden methods are declared public.
*/
public class SubGuiEditProperty extends GuiScreen {
private ISubGuiCallback subGuiCallback;
private IPropertyEditorCallback propCallback;
private GuiTextField textField;
private String propertyName;
private String initialValue;
// Overlay dimensions
private int overlayX, overlayY, overlayWidth, overlayHeight;
/**
* Creates a new property editor overlay.
* @param propertyName the name of the property being edited
* @param initialValue the current value (as String)
* @param propCallback callback for when the property is updated
* @param subGuiCallback callback for when the overlay is closed
*/
public SubGuiEditProperty(String propertyName, String initialValue, IPropertyEditorCallback propCallback, ISubGuiCallback subGuiCallback) {
this.propertyName = propertyName;
this.initialValue = (initialValue == null ? "" : initialValue);
this.propCallback = propCallback;
this.subGuiCallback = subGuiCallback;
}
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
this.mc = Minecraft.getMinecraft();
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
if (this.fontRendererObj == null) {
this.fontRendererObj = Minecraft.getMinecraft().fontRenderer;
}
// Use the current width/height from this screen.
this.width = res.getScaledWidth();
this.height = res.getScaledHeight();
overlayWidth = 150;
overlayHeight = 20;
overlayX = (this.width - overlayWidth) / 2;
overlayY = (this.height - overlayHeight) / 2;
textField = new GuiTextField(this.fontRendererObj, overlayX, overlayY, overlayWidth, overlayHeight);
textField.setText(initialValue);
textField.setFocused(true);
buttonList.clear();
// "Done" button positioned below the text field.
buttonList.add(new GuiButton(1000000, overlayX, overlayY + overlayHeight + 5, overlayWidth, 20, "Done"));
}
@Override
public void updateScreen() {
textField.updateCursorCounter();
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
if (this.fontRendererObj == null) {
this.fontRendererObj = Minecraft.getMinecraft().fontRenderer;
}
GL11.glDisable(GL11.GL_DEPTH_TEST);
// Draw semi-transparent background and overlay elements
drawRect(0, 0, this.width, this.height, 0x88000000);
drawCenteredString(this.fontRendererObj, "Edit " + propertyName, this.width / 2, overlayY - 30, 0xFFFFFF);
textField.drawTextBox();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glPopMatrix();
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void keyTyped(char typedChar, int keyCode) {
textField.textboxKeyTyped(typedChar, keyCode);
if (keyCode == Keyboard.KEY_ESCAPE) {
closeOverlay();
}
}
@Override
public void actionPerformed(GuiButton button) {
if (button.id == 1000000) {
if (propCallback != null) {
propCallback.propertyUpdated(textField.getText());
}
closeOverlay();
}
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void mouseMovedOrUp(int mouseX, int mouseY, int state) {
super.mouseMovedOrUp(mouseX, mouseY, state);
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
}
public void closeOverlay() {
Keyboard.enableRepeatEvents(false);
if(textField != null) {
textField.setFocused(false);
}
if (subGuiCallback != null) {
subGuiCallback.onSubGuiClosed();
}
}
}
@@ -20,6 +20,9 @@ import kamkeel.npcs.network.packets.player.customgui.CustomGuiButtonPacket;
import kamkeel.npcs.network.packets.player.customgui.CustomGuiClosePacket;
import kamkeel.npcs.network.packets.player.customgui.CustomGuiUnfocusedPacket;
import kamkeel.npcs.network.packets.player.customgui.CustomScrollClickPacket;
import kamkeel.npcs.network.packets.player.item.GuiMagicBookPacket;
import kamkeel.npcs.network.packets.player.item.GuiPaintbrushPacket;
import kamkeel.npcs.network.packets.player.item.MagicCyclesPacket;
import kamkeel.npcs.network.packets.player.profile.*;
import kamkeel.npcs.network.packets.request.*;
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
@@ -429,6 +432,11 @@ public class PacketHandler {
PLAYER_PACKET.registerPacket(new CustomGuiUnfocusedPacket());
PLAYER_PACKET.registerPacket(new CustomScrollClickPacket());
// Item Gui Packets
PLAYER_PACKET.registerPacket(new GuiPaintbrushPacket());
PLAYER_PACKET.registerPacket(new GuiMagicBookPacket());
PLAYER_PACKET.registerPacket(new MagicCyclesPacket());
// Profile Packets
PLAYER_PACKET.registerPacket(new ProfileCreatePacket());
PLAYER_PACKET.registerPacket(new ProfileRemovePacket());
@@ -95,7 +95,14 @@ public class PacketUtil {
break;
case HAMMER:
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 0) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker",
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Hammer, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
break;
case MAGIC_BOOK:
if (item.getItem() != CustomItems.tool || item.getItemDamage() != 2) {
LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Magic Book, they could be a hacker",
player.getCommandSenderName(), type));
return false;
}
@@ -158,6 +165,8 @@ public class PacketUtil {
return item.getItem() == CustomItems.tool && item.getItemDamage() == 1;
case HAMMER:
return item.getItem() == CustomItems.tool && item.getItemDamage() == 0;
case MAGIC_BOOK:
return item.getItem() == CustomItems.tool && item.getItemDamage() == 2;
default:
return false;
}
@@ -197,6 +206,8 @@ public class PacketUtil {
return "Paintbrush";
case HAMMER:
return "Hammer";
case MAGIC_BOOK:
return "Magic Book";
default:
return type.toString();
}
@@ -9,5 +9,6 @@ public enum EnumItemPacketType {
PATHER,
BLOCK,
BRUSH,
HAMMER
HAMMER,
MAGIC_BOOK
}
@@ -1,5 +1,7 @@
package kamkeel.npcs.network.enums;
import noppes.npcs.client.gui.custom.components.CustomGuiButton;
public enum EnumPlayerPacket {
FollowerAction,
Transport,
@@ -14,12 +16,16 @@ public enum EnumPlayerPacket {
GetRole,
InputDevice,
ScreenSize,
MagicCycles,
CustomGuiButton,
CustomGuiScrollClick,
CustomGuiClose,
CustomGuiUnfocused,
GuiPaintbrush,
GuiMagicBook,
ProfileCreate,
ProfileRemove,
ProfileRename,
@@ -0,0 +1,66 @@
package kamkeel.npcs.network.packets.player.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.constants.EnumGuiType;
import java.io.IOException;
public class GuiMagicBookPacket extends AbstractPacket {
public static String packetName = "Player|GuiMagicBook";
private int guiIndex, posX, posY, posZ;
public GuiMagicBookPacket(int guiIndex, int posX, int posY, int posZ) {
this.guiIndex = guiIndex;
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
}
public GuiMagicBookPacket() {}
@Override
public Enum getType() {
return EnumPlayerPacket.GuiMagicBook;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(guiIndex);
out.writeInt(posX);
out.writeInt(posY);
out.writeInt(posZ);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.MAGIC_BOOK))
return;
int index = in.readInt();
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
EnumGuiType gui = EnumGuiType.values()[index];
NoppesUtilServer.sendOpenGui(player, gui, null, x, y, z);
}
}
@@ -0,0 +1,67 @@
package kamkeel.npcs.network.packets.player.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.constants.EnumGuiType;
import java.io.IOException;
public class GuiPaintbrushPacket extends AbstractPacket {
public static String packetName = "Player|GuiPaintbrush";
private int guiIndex, posX, posY, posZ;
public GuiPaintbrushPacket(int guiIndex, int posX, int posY, int posZ) {
this.guiIndex = guiIndex;
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
}
public GuiPaintbrushPacket() {}
@Override
public Enum getType() {
return EnumPlayerPacket.GuiPaintbrush;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(guiIndex);
out.writeInt(posX);
out.writeInt(posY);
out.writeInt(posZ);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.BRUSH))
return;
int index = in.readInt();
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
EnumGuiType gui = EnumGuiType.values()[index];
NoppesUtilServer.sendOpenGui(player, gui, null, x, y, z);
}
}
@@ -0,0 +1,85 @@
package kamkeel.npcs.network.packets.player.item;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.*;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumPlayerPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.network.packets.request.magic.MagicGetPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.data.MagicCycle;
import java.io.IOException;
import java.util.HashMap;
import static kamkeel.npcs.network.packets.data.large.ScrollDataPacket.sendScrollData;
public class MagicCyclesPacket extends AbstractPacket {
public static String packetName = "Player|MagicCycles";
private int id;
public MagicCyclesPacket() {}
public MagicCyclesPacket(int id) {
this.id = id;
}
@Override
public Enum getType() {
return EnumPlayerPacket.MagicCycles;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.PLAYER_PACKET;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.id);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.MAGIC_BOOK))
return;
int id = in.readInt();
if(id == -1){
HashMap<String, Integer> map = new HashMap<>();
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
map.put(magicCycle.displayName.replace("&", "\u00A7"), magicCycle.id);
}
sendScrollData((EntityPlayerMP) player, map, EnumScrollData.MAGIC_CYCLES);
} else {
MagicCycle cycle = MagicController.getInstance().getCycle(id);
if(cycle == null)
return;
NBTTagCompound compound = new NBTTagCompound();
NBTTagCompound magicCompound = new NBTTagCompound();
cycle.writeNBT(magicCompound);
compound.setTag("MagicCycle", magicCompound);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
public static void GetAll() {
PacketClient.sendClient(new MagicCyclesPacket(-1));
}
public static void GetCycle(int id) {
PacketClient.sendClient(new MagicCyclesPacket(id));
}
}
@@ -54,7 +54,7 @@ public final class GuiRequestPacket extends AbstractPacket {
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER, EnumItemPacketType.BRUSH))
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND, EnumItemPacketType.CLONER, EnumItemPacketType.BRUSH, EnumItemPacketType.MAGIC_BOOK))
return;
int index = in.readInt();
int x = in.readInt();
@@ -44,7 +44,7 @@ public final class TraderMarketSavePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_TRADER;
}
@Override
@@ -39,7 +39,7 @@ public final class DialogNpcRemovePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_DIALOG;
}
@Override
@@ -45,7 +45,7 @@ public final class DialogNpcSetPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_DIALOG;
}
@Override
@@ -39,7 +39,7 @@ public final class FactionSetPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_FACTION;
}
@Override
@@ -37,7 +37,7 @@ public final class JobGetPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
}
@Override
@@ -40,7 +40,7 @@ public final class JobSavePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
}
@Override
@@ -60,7 +60,7 @@ public final class JobSpawnerAddPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
}
@Override
@@ -42,7 +42,7 @@ public final class JobSpawnerRemovePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_JOB;
}
@Override
@@ -41,7 +41,7 @@ public final class LinkedSetPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_LINKED;
}
@Override
@@ -52,7 +52,7 @@ public final class MagicGetPacket extends AbstractPacket {
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
if (!PacketUtil.verifyItemPacket(player, EnumItemPacketType.WAND))
return;
Action action = Action.values()[in.readInt()];
@@ -46,7 +46,7 @@ public final class MagicNpcSavePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_MAGIC;
}
@SideOnly(Side.CLIENT)
@@ -42,7 +42,7 @@ public final class RoleCompanionUpdatePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_ROLE;
}
@Override
@@ -41,7 +41,7 @@ public final class RoleSavePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_ROLE;
}
@Override
@@ -44,7 +44,7 @@ public final class TagSetPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_TAGS;
}
@Override
@@ -35,7 +35,7 @@ public final class TransformGetPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_TRANSFORM;
}
@Override
@@ -39,7 +39,7 @@ public final class TransformLoadPacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_TRANSFORM;
}
@Override
@@ -41,7 +41,7 @@ public final class TransformSavePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_TRANSFORM;
}
@Override
@@ -47,7 +47,7 @@ public final class TransportSavePacket extends AbstractPacket {
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.NPC_ADVANCED;
return CustomNpcsPermissions.NPC_ADVANCED_TRANSPORT;
}
@Override
@@ -281,10 +281,14 @@ public class AttributeItemUtil {
baseOrder.put("Health", 1);
baseOrder.put("Main Attack Damage", 2);
baseOrder.put("Neutral Damage", 3);
// For Modifier: Main Attack Damage then Neutral Damage.
Map<String, Integer> modOrder = new HashMap<>();
modOrder.put("Main Attack Damage", 1);
modOrder.put("Neutral Damage", 2);
modOrder.put("Health Boost", 1);
modOrder.put("Main Attack Damage", 2);
modOrder.put("Neutral Damage", 3);
modOrder.put("Movement Speed", 4);
modOrder.put("Knockback Resistance", 5);
// Build sections using our custom sorting.
newTooltips.addAll(buildSection(baseList, baseOrder));
@@ -1,6 +1,7 @@
package noppes.npcs;
import kamkeel.npcs.addon.DBCAddon;
import kamkeel.npcs.addon.client.DBCClient;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
@@ -52,7 +53,9 @@ public class AnimationMixinFunctions {
return false;
}
if (ClientEventHandler.renderingPlayer != null) {
if(DBCAddon.IsAvailable() && ClientEventHandler.renderingPlayer != null){
DBCClient.Instance.applyRenderModel(modelRenderer);
} else if (!DBCAddon.IsAvailable() && ClientEventHandler.renderingPlayer != null) {
ClientEventHandler.playerModel = (modelRenderer).baseModel;
if (ClientCacheHandler.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
AnimationData animData = ClientCacheHandler.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID());
@@ -221,6 +224,10 @@ public class AnimationMixinFunctions {
}
public static boolean mixin_renderFirstPersonAnimation(float partialRenderTick, EntityPlayer player, ModelBiped model, RenderBlocks renderBlocksIr, ResourceLocation resItemGlint) {
if (DBCAddon.IsAvailable()) {
return DBCClient.Instance.firstPersonAnimation(partialRenderTick, player,model, renderBlocksIr, resItemGlint);
}
AnimationData animationData = ClientCacheHandler.playerAnimations.get(player.getUniqueID());
if (animationData != null && animationData.isActive()) {
Frame frame = (Frame) animationData.animation.currentFrame();
@@ -898,9 +905,9 @@ public class AnimationMixinFunctions {
tailCol = (int) JRMCoreH.getMethod(
"stat", Entity.class, int.class, int.class, int.class, int.class, int.class, int.class, float.class).invoke(null,
par1EntityPlayer, 2,
(byte) JRMCoreH.getField("Pwrtyp").get(null), 2,
JRMCoreH.getField("Pwrtyp").get(null), 2,
((int[]) JRMCoreH.getField("PlyrAttrbts").get(null))[2], race,
(byte) JRMCoreH.getField("Class").get(null), 0.0F);
JRMCoreH.getField("Class").get(null), 0.0F);
jx = Integer.parseInt((String) JRMCoreH.getMethod("data", String.class, int.class, String.class).invoke(null, par1EntityPlayer.getCommandSenderName(), 8, "200"));
float one = (float) tailCol / 100.0F;
int perc = (int) ((float) jx / one);
@@ -39,9 +39,20 @@ public class CustomNpcsPermissions {
public static final Permission NPC_STATS = new Permission("customnpcs.npc.stats");
public static final Permission NPC_CLONE = new Permission("customnpcs.npc.clone");
public static final Permission NPC_ADVANCED_TRADER = new Permission("customnpcs.npc.advanced.trader");
public static final Permission NPC_ADVANCED_DIALOG = new Permission("customnpcs.npc.advanced.dialog");
public static final Permission NPC_ADVANCED_FACTION = new Permission("customnpcs.npc.advanced.faction");
public static final Permission NPC_ADVANCED_JOB = new Permission("customnpcs.npc.advanced.job");
public static final Permission NPC_ADVANCED_ROLE = new Permission("customnpcs.npc.advanced.role");
public static final Permission NPC_ADVANCED_TRANSPORT = new Permission("customnpcs.npc.advanced.transport");
public static final Permission NPC_ADVANCED_TRANSFORM = new Permission("customnpcs.npc.advanced.transform");
public static final Permission NPC_ADVANCED_LINKED = new Permission("customnpcs.npc.advanced.linked");
public static final Permission NPC_ADVANCED_MAGIC = new Permission("customnpcs.npc.advanced.linked");
public static final Permission NPC_ADVANCED_TAGS = new Permission("customnpcs.npc.advanced.tags");
public static final Permission GLOBAL_REMOTE = new Permission("customnpcs.global.remote");
// Save Globel Preferences
// Save Global Preferences
public static final Permission GLOBAL_LINKED = new Permission("customnpcs.global.linked");
public static final Permission GLOBAL_PLAYERDATA = new Permission("customnpcs.global.playerdata");
public static final Permission GLOBAL_BANK = new Permission("customnpcs.global.bank");
+22
View File
@@ -21,6 +21,7 @@ import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.api.handler.data.IPlayerEffect;
import noppes.npcs.api.handler.data.IProfile;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemLinked;
@@ -406,6 +407,27 @@ public class EventHooks {
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onEffectAdded(IPlayer player, IPlayerEffect effect) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(player, effect);
handler.callScript(EffectScript.ScriptType.OnEffectAdd.function, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onEffectTick(IPlayer player, IPlayerEffect effect) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(player, effect);
handler.callScript(EffectScript.ScriptType.OnEffectTick.function, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onEffectRemove(IPlayer player, IPlayerEffect effect, EffectEvent.ExpirationType type) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(player, effect, type);
handler.callScript(EffectScript.ScriptType.OnEffectRemove.function, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onStartUsingItem(PlayerDataScript handler, IPlayer player, int duration, ItemStack item) {
PlayerEvent.StartUsingItem event = new PlayerEvent.StartUsingItem(player, item, duration);
handler.callScript(EnumScriptType.START_USING_ITEM, event);
@@ -706,15 +706,15 @@ public class NoppesUtilServer {
public static void sendMagicInfo(EntityPlayerMP player, boolean cycles) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (cycles) {
for (Magic magic : MagicController.getInstance().magics.values()) {
map.put(magic.name, magic.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC);
} else {
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
map.put(magicCycle.name, magicCycle.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC_CYCLES);
} else {
for (Magic magic : MagicController.getInstance().magics.values()) {
map.put(magic.name, magic.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC);
}
}
@@ -6,6 +6,7 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import kamkeel.npcs.addon.client.DBCClient;
import kamkeel.npcs.editorgui.GuiCustomGuiEditor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.model.ModelBiped;
@@ -43,6 +44,7 @@ import noppes.npcs.client.fx.EntityRainbowFX;
import noppes.npcs.client.gui.*;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.global.*;
import noppes.npcs.client.gui.item.GuiNpcMagicBook;
import noppes.npcs.client.gui.item.GuiNpcPaintbrush;
import noppes.npcs.client.gui.mainmenu.*;
import noppes.npcs.client.gui.player.*;
@@ -266,8 +268,10 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.MovingPath)
return new GuiNpcPather(npc);
else if (gui == EnumGuiType.ManageFactions)
return new GuiNPCManageFactions(npc);
else if (gui == EnumGuiType.ManageFactions)
return new GuiCustomGuiEditor();
// TODO: CHANGE BACK
// return new GuiNPCManageFactions(npc);
else if (gui == EnumGuiType.ManageCustomForms)
return DBCClient.Instance.manageCustomForms(npc);
@@ -422,6 +426,9 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.Paintbrush)
return new GuiNpcPaintbrush();
else if (gui == EnumGuiType.MagicBook)
return new GuiNpcMagicBook();
else if (gui == EnumGuiType.GlobalRemote)
return new GuiNPCGlobalMainMenu(null);
@@ -54,10 +54,12 @@ public class GuiMagicCycleMap extends GuiDiagram {
// Use the cycle's layout if set; otherwise default to CIRCULAR_MANUAL.
setLayout(cycle.layout != null ? cycle.layout : EnumDiagramLayout.CIRCULAR_MANUAL);
setLayout(EnumDiagramLayout.CIRCULAR_MANUAL);
setCurvedArrows(true);
setCurveAngle(-20);
invalidateCache();
this.allowTwoWay = true;
this.iconSize = 20;
this.slotSize = iconSize + slotPadding;
}
@@ -109,7 +111,10 @@ public class GuiMagicCycleMap extends GuiDiagram {
int targetId = entry.getKey();
if (!orderMap.containsKey(targetId)) continue;
float percent = entry.getValue();
String hover = "+" + (int) (percent * 100) + "%";
String modifier = "";
if(percent > 0.0)
modifier += "+";
String hover = modifier + (int) (percent * 100) + "%";
conns.add(new DiagramConnection(m.id, targetId, percent, hover));
}
}
@@ -23,9 +23,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
String label;
String[] hoverText;
int color;
float alpha;
float scale = 1.0F;
public int color;
public float alpha;
public float scale = 1.0F;
public CustomGuiButton(int id, String buttonText, int x, int y) {
super(id, x, y, buttonText);
@@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
public class CustomGuiLabel extends Gui implements IGuiComponent {
int x, y, width, height;
public int x, y, width, height;
GuiCustom parent;
String fullLabel;
String[] hoverText;
@@ -30,9 +30,9 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
boolean labelBgEnabled = true;
boolean labelShadowEnabled = false;
int color;
float alpha;
float rotation;
public int color;
public float alpha;
public float rotation;
protected int field_146167_a;
protected int field_146161_f;
@@ -15,20 +15,20 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
GuiCustom parent;
ImageData imageData = null;
String texture;
int id;
int x;
int y;
int width;
int height;
int textureX;
int textureY;
float scale;
public String texture;
public int id;
public int x;
public int y;
public int width;
public int height;
public int textureX;
public int textureY;
public float scale;
String[] hoverText;
int color;
float alpha;
float rotation;
public int color;
public float alpha;
public float rotation;
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
@@ -510,7 +510,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
AnimationData data = npc.display.animationData;
if (!data.isActive() && this.playingAnimation) {
this.playingAnimation = false;
@@ -518,6 +517,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
} else if (data.isActive()) {
long time = mc.theWorld.getTotalWorldTime();
if (time != prevTick) {
npc.display.animationData.increaseTime();
GuiNpcLabel label = this.getLabel(213);
if (label != null) {
label.label += ".";
@@ -529,6 +529,8 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
prevTick = time;
}
super.drawScreen(par1, par2, par3);
for (int i = 0; i < this.visibleFrames; i++) {
if (getButton(300 + i) != null) {
GuiTexturedButton button = (GuiTexturedButton) getButton(300 + i);
@@ -104,8 +104,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
public void drawScreen(int par1, int par2, float partialTicks) {
AnimationData data = npc.display.animationData;
if (!data.isActive() && this.playingAnimation) {
this.playingAnimation = false;
@@ -113,6 +112,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
} else if (data.isActive()) {
long time = mc.theWorld.getTotalWorldTime();
if (time != prevTick) {
npc.display.animationData.increaseTime();
GuiNpcLabel label = this.getLabel(94);
if (label != null) {
label.label += ".";
@@ -123,6 +123,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
}
prevTick = time;
}
super.drawScreen(par1, par2, partialTicks);
}
@Override
@@ -0,0 +1,176 @@
package noppes.npcs.client.gui.item;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.player.item.MagicCyclesPacket;
import kamkeel.npcs.network.packets.request.magic.MagicGetAllPacket;
import kamkeel.npcs.network.packets.request.magic.MagicGetPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.gui.GuiMagicCycleMap;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.controllers.data.Magic;
import noppes.npcs.controllers.data.MagicCycle;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
public class GuiNpcMagicBook extends GuiNPCInterface implements ICustomScrollListener, IScrollData, IGuiData {
private MagicCycle magicCycle;
private GuiMagicCycleMap magicMap;
private GuiCustomScroll leftScroll;
public HashMap<String, Integer> cycleData = new HashMap<>();
public GuiNpcMagicBook() {
super();
xSize = 350;
setBackground("menubg.png");
closeOnEsc = true;
MagicCyclesPacket.GetAll();
}
@Override
public void initGui() {
super.initGui();
int spacing = 10;
int scrollWidth = 120;
addLabel(new GuiNpcLabel(0, "menu.cycles", guiLeft + 14, guiTop + 10, 0xFFFFFF));
// --- Left Scroll List ---
leftScroll = new GuiCustomScroll(this, 0, 0);
leftScroll.guiLeft = guiLeft + spacing;
leftScroll.guiTop = guiTop + 22;
leftScroll.setSize(scrollWidth, ySize - 32);
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
addScroll(leftScroll);
// --- Magic Map (Diagram) on the Right ---
if(magicCycle == null)
return;
String displayName = magicCycle.getDisplayName().replace("&", "\u00A7");
leftScroll.setSelected(displayName);
int mapX = guiLeft + scrollWidth + 2 * spacing;
int mapY = guiTop + 22;
int mapWidth = xSize - (scrollWidth + 3 * spacing);
int mapHeight = ySize - 32;
magicMap = new GuiMagicCycleMap(this, mapX, mapY, mapWidth, mapHeight, magicCycle);
addDiagram(0, magicMap);
int labelY = guiTop + 10;
int textWidth = fontRendererObj.getStringWidth(displayName);
int labelX = mapX + (mapWidth / 2) - (textWidth / 2);
GuiNpcLabel magicLabel = new GuiNpcLabel(1, displayName, labelX, labelY, CustomNpcResourceListener.DefaultTextColor);
addLabel(magicLabel);
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (i == 1) {
close();
}
}
@Override
public void actionPerformed(GuiButton guibutton) {}
@Override
public void drawScreen(int i, int j, float f) {
super.drawScreen(i, j, f);
}
@Override
protected void drawBackground(){
super.drawBackground();
int spacing = 10;
int scrollWidth = 120;
int barHeight = 16; // Same height as the magic map bar
int barY = guiTop + 22 - barHeight - 1;
// Draw dark rectangle above the left scroll (same width as left scroll)
if (leftScroll != null) {
int leftRectX = guiLeft + spacing;
drawRect(leftRectX, barY, leftRectX + scrollWidth, barY + barHeight, 0xFF333333);
}
// Draw dark rectangle above the magic map
if (magicMap != null) {
int mapX = guiLeft + scrollWidth + 2 * spacing;
int mapWidth = xSize - (scrollWidth + 3 * spacing);
drawRect(mapX, barY, mapX + mapWidth, barY + barHeight, 0xFF333333);
}
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
if (magicMap != null) {
magicMap.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
@Override
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
if (magicMap != null) {
magicMap.mouseReleased(mouseX, mouseY, state);
}
super.mouseMovedOrUp(mouseX, mouseY, state);
}
@Override
public void save() {
// Implement save logic if needed.
}
// --- ICustomScrollListener Methods ---
@Override
public void customScrollClicked(int id, int index, int clickType, GuiCustomScroll scroll) {
if (scroll == leftScroll) {
String selectedName = scroll.getSelected();
MagicCyclesPacket.GetCycle(cycleData.get(selectedName));
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
// Handle double-click if necessary.
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
if(type == EnumScrollData.MAGIC_CYCLES){
cycleData.clear();
cycleData.putAll(data);
if (leftScroll != null) {
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
}
initGui();
}
}
@Override
public void setSelected(String selected) {
}
@Override
public void setGuiData(NBTTagCompound compound) {
if (compound.hasKey("MagicCycle")) {
magicCycle = new MagicCycle();
magicCycle.readNBT(compound.getCompoundTag("MagicCycle"));
initGui();
}
}
}
@@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NBTTags;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.data.EffectScript;
import noppes.npcs.controllers.data.PlayerDataScript;
import java.util.List;
@@ -80,6 +81,9 @@ public class GuiScriptPlayers extends GuiScriptInterface {
hookList.add(EnumScriptType.PROFILE_CHANGE.function);
hookList.add(EnumScriptType.PROFILE_REMOVE.function);
hookList.add(EnumScriptType.PROFILE_CREATE.function);
hookList.add(EffectScript.ScriptType.OnEffectAdd.function);
hookList.add(EffectScript.ScriptType.OnEffectTick.function);
hookList.add(EffectScript.ScriptType.OnEffectRemove.function);
this.handler = this.script;
PlayerScriptPacket.Get();
@@ -18,8 +18,8 @@ import java.util.*;
* Abstract GUI class for drawing diagrams with icons (nodes) and connections (arrows).
* <p>
* This revised version ensures that non‑Chart layouts use the full diagram bounds for positioning
* (so that the outer icons lie flush with the edges) and that curved arrow drawing selects the
* best control point (using both curveAngle and its negative) to avoid icons.
* and that curved arrow drawing selects the best control point (using both curveAngle and its negative)
* to avoid icons.
*/
public abstract class GuiDiagram extends Gui {
@@ -46,6 +46,11 @@ public abstract class GuiDiagram extends Gui {
protected boolean showArrowHeads = true;
protected boolean useColorScaling = true;
// This flag determines how two‑way connections are drawn.
// When true, a two‑way connection is drawn as one line with dual arrowheads and combined tooltips.
// When false, each direction is drawn as a separate line with its own hitbox and tooltip.
protected boolean allowTwoWay = false;
// --- Layout Options ---
protected EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
@@ -116,6 +121,10 @@ public abstract class GuiDiagram extends Gui {
return null;
}
/**
* Returns the tooltip for a connection. When allowTwoWay is true the tooltip combines both directions,
* otherwise it shows only the current connection's info.
*/
protected List<String> getConnectionTooltip(DiagramConnection conn) {
List<String> tooltip = new ArrayList<>();
DiagramIcon iconFrom = getIconById(conn.idFrom);
@@ -124,10 +133,12 @@ public abstract class GuiDiagram extends Gui {
String nameTo = iconTo != null ? getIconName(iconTo) : "Unknown";
tooltip.add(nameFrom + " > " + nameTo + ":");
tooltip.add(conn.hoverText);
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
if (reverse != null) {
tooltip.add(nameTo + " > " + nameFrom + ":");
tooltip.add(reverse.hoverText);
if (allowTwoWay) {
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
if (reverse != null) {
tooltip.add(nameTo + " > " + nameFrom + ":");
tooltip.add(reverse.hoverText);
}
}
return tooltip;
}
@@ -194,7 +205,7 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
// Square: fill the entire bounds
// Square: fill the entire bounds.
protected Map<Integer, Point> calculateSquarePositions() {
List<DiagramIcon> icons = getIcons();
Map<Integer, Point> positions = new HashMap<>();
@@ -203,7 +214,6 @@ public abstract class GuiDiagram extends Gui {
int n = (int) Math.ceil(Math.sqrt(count));
int cellWidth = width / n;
int cellHeight = height / n;
// Start exactly at the diagram bounds.
int startX = x, startY = y;
for (int i = 0; i < count; i++) {
int row = i / n, col = i % n;
@@ -214,29 +224,18 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
// Tree: distribute levels vertically and icons horizontally so that the top and bottom icons touch y and y+height.
// Tree: distribute levels vertically and icons horizontally.
protected Map<Integer, Point> calculateTreePositions() {
List<DiagramIcon> icons = getIcons();
Map<Integer, Point> positions = new HashMap<>();
int count = icons.size();
if (count == 0) return positions;
// Determine number of levels by a simple breadth-first approach.
int levels = (int) Math.ceil(Math.log(count + 1) / Math.log(2));
// If only one level, place the icon in the center.
for (int level = 0; level < levels; level++) {
// Determine number of nodes at this level.
int nodesThisLevel = (level == 0) ? 1 : (int) Math.min(Math.pow(2, level), count - (int) Math.pow(2, level) + 1);
// Calculate vertical position: if more than one level, linearly space from y to y+height.
int posY = (levels == 1) ? y + height / 2 : y + (int) ((height * level) / (levels - 1.0));
// Horizontal spacing: if only one node, center it; otherwise, nodes are evenly spaced from x to x+width.
for (int i = 0; i < nodesThisLevel; i++) {
int posX;
if (nodesThisLevel == 1) {
posX = x + width / 2;
} else {
posX = x + (int) ((width * i) / (nodesThisLevel - 1.0));
}
// Here we assign IDs in order. (You may want to use your own ordering.)
int posX = (nodesThisLevel == 1) ? x + width / 2 : x + (int) ((width * i) / (nodesThisLevel - 1.0));
int index = (int) (Math.pow(2, level) - 1 + i);
if (index < count) {
positions.put(icons.get(index).id, new Point(posX, posY));
@@ -246,14 +245,13 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
// Generated: Break icons into clusters and fill each cluster’s area exactly.
// Generated layout methods (unchanged)...
protected Map<Integer, Point> calculateGeneratedPositions() {
List<DiagramIcon> icons = getIcons();
List<DiagramConnection> connections = getConnections();
Map<Integer, List<Integer>> graph = buildGraph(icons, connections);
List<Set<Integer>> clusters = getConnectedComponents(graph);
int clusterCount = clusters.size();
// Arrange clusters in a grid that fills the diagram exactly.
int gridCols = (int) Math.ceil(Math.sqrt(clusterCount));
int gridRows = (int) Math.ceil((double) clusterCount / gridCols);
Map<Integer, Point> globalPositions = new HashMap<>();
@@ -346,8 +344,7 @@ public abstract class GuiDiagram extends Gui {
return sqrt * sqrt == n;
}
// --- Layout Algorithms for Clusters ---
// Cycle: now use the full available circle.
// Layout algorithms for clusters (unchanged methods: layoutCycle, layoutTree, layoutSquare, layoutForceDirected)...
private Map<Integer, Point> layoutCycle(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight) {
Map<Integer, Point> positions = new HashMap<>();
if (cluster.isEmpty()) return positions;
@@ -364,13 +361,11 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
// Tree for clusters: use full comp area.
private Map<Integer, Point> layoutTree(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight,
Map<Integer, List<Integer>> fullGraph) {
Map<Integer, Point> positions = new HashMap<>();
if (cluster.isEmpty()) return positions;
// Build a subgraph
Map<Integer, List<Integer>> subgraph = new HashMap<>();
for (Integer id : cluster) {
List<Integer> neighbors = new ArrayList<>();
@@ -380,9 +375,7 @@ public abstract class GuiDiagram extends Gui {
}
subgraph.put(id, neighbors);
}
// Pick a root (lowest id)
Integer root = Collections.min(cluster);
// Perform BFS to assign levels.
Map<Integer, Integer> levelMap = new HashMap<>();
Map<Integer, List<Integer>> levels = new HashMap<>();
Queue<Integer> queue = new LinkedList<>();
@@ -403,7 +396,6 @@ public abstract class GuiDiagram extends Gui {
}
}
int maxLevel = levels.keySet().stream().max(Integer::compare).orElse(0);
// Vertical positions: if only one level, center; otherwise span from compY to compY+compHeight.
for (Map.Entry<Integer, List<Integer>> entry : levels.entrySet()) {
int lvl = entry.getKey();
int posY = (maxLevel == 0) ? compY + compHeight / 2 : compY + (int) ((compHeight * lvl) / (maxLevel));
@@ -418,7 +410,6 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
// Square: fill the available comp area.
private Map<Integer, Point> layoutSquare(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight) {
Map<Integer, Point> positions = new HashMap<>();
if (cluster.isEmpty()) return positions;
@@ -439,7 +430,6 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
// Force-directed layout (unchanged)
private Map<Integer, Point> layoutForceDirected(Set<Integer> cluster, int compX, int compY, int compWidth, int compHeight,
List<DiagramConnection> connections) {
Map<Integer, Point> positions = new HashMap<>();
@@ -520,6 +510,7 @@ public abstract class GuiDiagram extends Gui {
List<DiagramIcon> icons = getIcons();
Map<Integer, Point> positions = new HashMap<>();
if (icons.isEmpty()) return positions;
// Group icons by their manual index.
Map<Integer, List<DiagramIcon>> groups = new TreeMap<>();
for (DiagramIcon icon : icons) {
groups.computeIfAbsent(icon.index, k -> new ArrayList<>()).add(icon);
@@ -527,13 +518,21 @@ public abstract class GuiDiagram extends Gui {
int centerX = x + width / 2, centerY = y + height / 2;
int maxRing = groups.isEmpty() ? 0 : Collections.max(groups.keySet());
int maxRadius = (Math.min(width, height) - iconSize) / 2;
double ringSpacing = (maxRing + 1) > 0 ? (double) maxRadius / (maxRing + 1) : 0;
// Adjustable parameters:
// spacingExponent controls the non-linear spacing between rings. Increasing this value will push outer rings farther apart.
double spacingExponent = 1.5; // default value; adjust as needed
// ringMultiplier lets you directly scale the computed radius of each ring.
double ringMultiplier = 1.5; // default value; adjust as needed
// Calculate positions for each ring using a power function and multiplier.
for (Map.Entry<Integer, List<DiagramIcon>> entry : groups.entrySet()) {
int ring = entry.getKey();
List<DiagramIcon> groupIcons = entry.getValue();
if (groupIcons.isEmpty()) continue;
groupIcons.sort(Comparator.comparingInt(icon -> icon.priority));
double radius = ringSpacing * (ring + 1);
double normalizedRing = (ring + 1) / (double) (maxRing + 1);
double radius = maxRadius * Math.pow(normalizedRing, spacingExponent) * ringMultiplier;
int count = groupIcons.size();
double startAngle = (ring == 0) ? -Math.PI / 2 : -3 * Math.PI / 4;
for (int i = 0; i < count; i++) {
@@ -546,6 +545,7 @@ public abstract class GuiDiagram extends Gui {
return positions;
}
private Map<Integer, Point> calculateSquareManualPositions() {
List<DiagramIcon> icons = getIcons();
Map<Integer, Point> positions = new HashMap<>();
@@ -597,7 +597,6 @@ public abstract class GuiDiagram extends Gui {
Map<Integer, Point> positions = new HashMap<>();
if (icons.isEmpty()) return positions;
int maxLevel = levels.isEmpty() ? 0 : Collections.max(levels.keySet());
// If more than one level, span vertically from y to y+height.
for (Map.Entry<Integer, List<DiagramIcon>> entry : levels.entrySet()) {
int level = entry.getKey();
List<DiagramIcon> levelIcons = entry.getValue();
@@ -629,7 +628,7 @@ public abstract class GuiDiagram extends Gui {
}
/**
* Returns the minimum distance from the given control point to any icon (except the endpoints of the connection).
* Returns the minimum distance from the given control point to any icon (except endpoints).
*/
private double getMinDistanceToIcon(Point control, DiagramConnection conn) {
double minDist = Double.MAX_VALUE;
@@ -648,92 +647,269 @@ public abstract class GuiDiagram extends Gui {
}
// --- Arrow Drawing Methods ---
/**
* Draws a connection line between two endpoints.
* If a reverse connection exists and allowTwoWay is false, the line is drawn with a perpendicular offset.
*/
protected void drawConnectionLine(int x1, int y1, int x2, int y2, DiagramConnection conn, boolean dim) {
int color = getConnectionColor(conn);
if (!useColorScaling) color = 0xFFFFFFFF;
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
if (!allowTwoWay && reverse != null) {
if (x1 > x2 || (x1 == x2 && y1 > y2)) {
return;
}
}
boolean twoWay = (reverse != null && allowTwoWay);
// When allowTwoWay is false and a reverse exists, draw each connection separately.
boolean separateTwoWay = (reverse != null && !allowTwoWay);
if (!curvedArrows) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glLineWidth(2.0F);
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = (color & 0xFF) / 255f;
if (dim) {
r *= 0.4f;
g *= 0.4f;
b *= 0.4f;
if (separateTwoWay) {
int offsetAmount = 4;
double dx = x2 - x1, dy = y2 - y1;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
double offsetX = -dy / len * offsetAmount;
double offsetY = dx / len * offsetAmount;
if (conn.idFrom >= conn.idTo) {
offsetX = -offsetX;
offsetY = -offsetY;
}
int newX1 = x1 + (int) offsetX;
int newY1 = y1 + (int) offsetY;
int newX2 = x2 + (int) offsetX;
int newY2 = y2 + (int) offsetY;
int color = getConnectionColor(conn);
if (!useColorScaling) {
color = 0xFFFFFFFF;
}
drawColoredLine(newX1, newY1, newX2, newY2, color, dim);
} else if (twoWay) {
int midX = (x1 + x2) / 2;
int midY = (y1 + y2) / 2;
int color1 = getConnectionColor(reverse);
int color2 = getConnectionColor(conn);
if (!useColorScaling) {
color1 = color2 = 0xFFFFFFFF;
}
drawColoredLine(x1, y1, midX, midY, color1, dim);
drawColoredLine(midX, midY, x2, y2, color2, dim);
} else {
int color = getConnectionColor(conn);
if (!useColorScaling) {
color = 0xFFFFFFFF;
}
drawColoredLine(x1, y1, x2, y2, color, dim);
}
GL11.glColor4f(r, g, b, 1f);
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex2i(x1, y1);
GL11.glVertex2i(x2, y2);
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glPopAttrib();
} else {
// Compute two potential control points and choose the one farther from nearby icons.
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
double d1 = getMinDistanceToIcon(cp1, conn);
double d2 = getMinDistanceToIcon(cp2, conn);
Point control = (d1 >= d2) ? cp1 : cp2;
int segments = 400;
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glLineWidth(2.0F);
float rr = ((color >> 16) & 0xFF) / 255f;
float gg = ((color >> 8) & 0xFF) / 255f;
float bb = (color & 0xFF) / 255f;
if (dim) {
rr *= 0.4f;
gg *= 0.4f;
bb *= 0.4f;
// Curved arrows
if (separateTwoWay) {
int offsetAmount = 4;
double dx = x2 - x1, dy = y2 - y1;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
double normX = -dy / len;
double normY = dx / len;
double sign = (conn.idFrom < conn.idTo) ? 1 : -1;
Point baseControl = computeControlPoint(x1, y1, x2, y2, curveAngle);
Point offsetControl = new Point(baseControl.x + (int) (normX * offsetAmount * sign),
baseControl.y + (int) (normY * offsetAmount * sign));
int segments = 800;
int color = getConnectionColor(conn);
if (!useColorScaling) {
color = 0xFFFFFFFF;
}
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glLineWidth(2.0F);
setColor(color, dim);
GL11.glBegin(GL11.GL_LINE_STRIP);
for (int i = 0; i <= segments; i++) {
double t = (double) i / segments;
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * offsetControl.x + t * t * x2);
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * offsetControl.y + t * t * y2);
GL11.glVertex2i(bx, by);
}
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopAttrib();
} else if (twoWay) {
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
double d1 = getMinDistanceToIcon(cp1, conn);
double d2 = getMinDistanceToIcon(cp2, conn);
Point control = (d1 >= d2) ? cp1 : cp2;
int segments = 800;
int color1 = getConnectionColor(reverse);
int color2 = getConnectionColor(conn);
if (!useColorScaling) {
color1 = color2 = 0xFFFFFFFF;
}
int halfSegments = segments / 2;
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glLineWidth(2.0F);
setColor(color1, dim);
GL11.glBegin(GL11.GL_LINE_STRIP);
for (int i = 0; i <= halfSegments; i++) {
double t = (double) i / halfSegments;
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2);
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2);
GL11.glVertex2i(bx, by);
}
GL11.glEnd();
setColor(color2, dim);
GL11.glBegin(GL11.GL_LINE_STRIP);
for (int i = halfSegments; i <= segments; i++) {
double t = (double) i / segments;
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2);
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2);
GL11.glVertex2i(bx, by);
}
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopAttrib();
} else {
int color = getConnectionColor(conn);
if (!useColorScaling) {
color = 0xFFFFFFFF;
}
Point cp = computeControlPoint(x1, y1, x2, y2, curveAngle);
int segments = 800;
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glLineWidth(2.0F);
setColor(color, dim);
GL11.glBegin(GL11.GL_LINE_STRIP);
for (int i = 0; i <= segments; i++) {
double t = (double) i / segments;
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * cp.x + t * t * x2);
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * cp.y + t * t * y2);
GL11.glVertex2i(bx, by);
}
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopAttrib();
}
GL11.glColor4f(rr, gg, bb, 1f);
GL11.glBegin(GL11.GL_LINE_STRIP);
for (int i = 0; i <= segments; i++) {
double t = (double) i / segments;
int bx = (int) ((1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2);
int by = (int) ((1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2);
GL11.glVertex2i(bx, by);
}
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopAttrib();
}
}
// Helper method to draw a straight colored line.
private void drawColoredLine(int x1, int y1, int x2, int y2, int color, boolean dim) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glLineWidth(2.0F);
setColor(color, dim);
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex2i(x1, y1);
GL11.glVertex2i(x2, y2);
GL11.glEnd();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glPopAttrib();
}
// Helper to set color with dimming applied.
private void setColor(int color, boolean dim) {
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = (color & 0xFF) / 255f;
if (dim) {
r *= 0.4f;
g *= 0.4f;
b *= 0.4f;
}
GL11.glColor4f(r, g, b, 1f);
}
/**
* Draws the arrow head for a connection.
* When the connection is drawn separately (two-way with allowTwoWay false),
* the arrow head is positioned using the same offset.
*/
// Fixed drawArrowHead:
protected void drawArrowHead(int x1, int y1, int x2, int y2, DiagramConnection conn, boolean dim) {
int color = getConnectionColor(conn);
if (!useColorScaling) color = 0xFFFFFFFF;
DiagramConnection reverse = getConnectionByIds(conn.idFrom, conn.idTo);
if (!allowTwoWay && reverse != null) {
if (x1 > x2 || (x1 == x2 && y1 > y2)) {
return;
}
}
int color = (reverse != null) ? getConnectionColor(reverse) : getConnectionColor(conn);
if (!useColorScaling)
color = 0xFFFFFFFF;
boolean separateTwoWay = (reverse != null && !allowTwoWay);
double angle;
if (!curvedArrows) {
angle = Math.atan2(y2 - y1, x2 - x1);
if (separateTwoWay) {
int offsetAmount = 4;
double dx = x2 - x1, dy = y2 - y1;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
double offsetX = -dy / len * offsetAmount;
double offsetY = dx / len * offsetAmount;
if (conn.idFrom >= conn.idTo) {
offsetX = -offsetX;
offsetY = -offsetY;
}
int newX2 = x2 + (int) offsetX;
int newY2 = y2 + (int) offsetY;
angle = Math.atan2(newY2 - y1, newX2 - x1);
x2 = newX2;
y2 = newY2;
} else {
angle = Math.atan2(y2 - y1, x2 - x1);
}
} else {
// Compute two control points and choose the one farther from icons.
double dx = x2 - x1, dy = y2 - y1;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
double d1 = getMinDistanceToIcon(cp1, conn);
double d2 = getMinDistanceToIcon(cp2, conn);
Point control = (d1 >= d2) ? cp1 : cp2;
double t = 0.95;
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2;
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2;
double dBx = 2 * (1 - t) * (control.x - x1) + 2 * t * (x2 - control.x);
double dBy = 2 * (1 - t) * (control.y - y1) + 2 * t * (y2 - control.y);
angle = Math.atan2(dBy, dBx);
if (separateTwoWay) {
int offsetAmount = 4;
double dx = x2 - x1, dy = y2 - y1;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
double normX = -dy / len;
double normY = dx / len;
double sign = (conn.idFrom < conn.idTo) ? 1 : -1;
Point baseControl = computeControlPoint(x1, y1, x2, y2, curveAngle);
Point offsetControl = new Point(baseControl.x + (int) (normX * offsetAmount * sign),
baseControl.y + (int) (normY * offsetAmount * sign));
double t = 0.95;
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * offsetControl.x + t * t * x2;
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * offsetControl.y + t * t * y2;
double dBx = 2 * (1 - t) * (offsetControl.x - x1) + 2 * t * (x2 - offsetControl.x);
double dBy = 2 * (1 - t) * (offsetControl.y - y1) + 2 * t * (y2 - offsetControl.y);
angle = Math.atan2(dBy, dBx);
} else {
double dx = x2 - x1, dy = y2 - y1;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
Point cp1 = computeControlPoint(x1, y1, x2, y2, curveAngle);
Point cp2 = computeControlPoint(x1, y1, x2, y2, -curveAngle);
double d1 = getMinDistanceToIcon(cp1, conn);
double d2 = getMinDistanceToIcon(cp2, conn);
Point control = (d1 >= d2) ? cp1 : cp2;
double t = 0.95;
double bx = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * t * control.x + t * t * x2;
double by = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * t * control.y + t * t * y2;
double dBx = 2 * (1 - t) * (control.x - x1) + 2 * t * (x2 - control.x);
double dBy = 2 * (1 - t) * (control.y - y1) + 2 * t * (y2 - control.y);
angle = Math.atan2(dBy, dBx);
}
}
float defenderEdgeX = x2 - (slotSize / 2f) * (float) Math.cos(angle);
float defenderEdgeY = y2 - (slotSize / 2f) * (float) Math.sin(angle);
@@ -764,27 +940,6 @@ public abstract class GuiDiagram extends Gui {
GL11.glPopAttrib();
}
// --- Standard Icon Box Drawing ---
protected void drawIconBox(int slotX, int slotY, int slotSize, boolean highlighted) {
int bg = highlighted ? mixColors(iconBackgroundColor, 0xFFFFFFFF, 0.2f) : iconBackgroundColor;
drawRect(slotX, slotY, slotX + slotSize, slotY + slotSize, bg);
for (int i = 0; i < iconBorderThickness; i++) {
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + i, iconBorderColor);
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + slotSize - 1 - i, iconBorderColor);
drawVerticalLine(slotX + i, slotY + i, slotY + slotSize - i, iconBorderColor);
drawVerticalLine(slotX + slotSize - 1 - i, slotY + i, slotY + slotSize - i, iconBorderColor);
}
}
protected int mixColors(int color1, int color2, float ratio) {
int a1 = (color1 >> 24) & 0xFF, r1 = (color1 >> 16) & 0xFF, g1 = (color1 >> 8) & 0xFF, b1 = color1 & 0xFF;
int a2 = (color2 >> 24) & 0xFF, r2 = (color2 >> 16) & 0xFF, g2 = (color2 >> 8) & 0xFF, b2 = color2 & 0xFF;
int a = (int) (a1 + (a2 - a1) * ratio);
int r = (int) (r1 + (r2 - r1) * ratio);
int g = (int) (g1 + (g2 - g1) * ratio);
int b = (int) (b1 + (b2 - b1) * ratio);
return (a << 24) | (r << 16) | (g << 8) | b;
}
// --- Hit-detection helpers ---
private double distanceToBezier(Point start, Point control, Point end, int segments, int px, int py) {
@@ -826,7 +981,6 @@ public abstract class GuiDiagram extends Gui {
// --- CHART Layout Drawing (unchanged) ---
private void drawChartDiagram(int mouseX, int mouseY, boolean subGui) {
// ... (chart layout code remains unchanged)
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int factor = sr.getScaleFactor();
@@ -845,8 +999,8 @@ public abstract class GuiDiagram extends Gui {
/**
* Main method for drawing the diagram.
* For non‑Chart layouts, applies pan/zoom, draws connections (with improved curved hit-detection)
* and icons, and shows tooltips.
* Applies pan/zoom, draws connections (using adjusted endpoints for separate two-way lines),
* icons, and shows tooltips.
*/
public void drawDiagram(int mouseX, int mouseY, boolean subGui) {
boolean allowInput = (parent == null || !parent.hasSubGui());
@@ -891,18 +1045,49 @@ public abstract class GuiDiagram extends Gui {
Point pTo = positions.get(conn.idTo);
if (pFrom == null || pTo == null) continue;
double dist;
if (curvedArrows) {
// Compute both potential control points
Point cp1 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, curveAngle);
Point cp2 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, -curveAngle);
// Choose the control point that's farther from interfering icons (as done when drawing)
double d1 = getMinDistanceToIcon(cp1, conn);
double d2 = getMinDistanceToIcon(cp2, conn);
Point control = (d1 >= d2) ? cp1 : cp2;
// Use the chosen control point for hit detection
dist = distanceToBezier(pFrom, control, pTo, 200, effectiveMouseX, effectiveMouseY);
// If drawing separate two-way connections, use the offset endpoints for hit detection.
boolean separateTwoWay = (getConnectionByIds(conn.idTo, conn.idFrom) != null && !allowTwoWay);
if (separateTwoWay) {
if (curvedArrows) {
int offsetAmount = 4;
double dx = pTo.x - pFrom.x, dy = pTo.y - pFrom.y;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
double normX = -dy / len;
double normY = dx / len;
double sign = (conn.idFrom < conn.idTo) ? 1 : -1;
Point baseControl = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, curveAngle);
Point offsetControl = new Point(baseControl.x + (int) (normX * offsetAmount * sign),
baseControl.y + (int) (normY * offsetAmount * sign));
dist = distanceToBezier(pFrom, offsetControl, pTo, 200, effectiveMouseX, effectiveMouseY);
} else {
int offsetAmount = 4;
double dx = pTo.x - pFrom.x, dy = pTo.y - pFrom.y;
double len = Math.sqrt(dx * dx + dy * dy);
if (len == 0) len = 1;
double offsetX = -dy / len * offsetAmount;
double offsetY = dx / len * offsetAmount;
if (conn.idFrom >= conn.idTo) {
offsetX = -offsetX;
offsetY = -offsetY;
}
int newX1 = pFrom.x + (int) offsetX;
int newY1 = pFrom.y + (int) offsetY;
int newX2 = pTo.x + (int) offsetX;
int newY2 = pTo.y + (int) offsetY;
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, newX1, newY1, newX2, newY2);
}
} else {
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, pFrom.x, pFrom.y, pTo.x, pTo.y);
if (curvedArrows) {
Point cp1 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, curveAngle);
Point cp2 = computeControlPoint(pFrom.x, pFrom.y, pTo.x, pTo.y, -curveAngle);
double d1 = getMinDistanceToIcon(cp1, conn);
double d2 = getMinDistanceToIcon(cp2, conn);
Point control = (d1 >= d2) ? cp1 : cp2;
dist = distanceToBezier(pFrom, control, pTo, 200, effectiveMouseX, effectiveMouseY);
} else {
dist = pointLineDistance(effectiveMouseX, effectiveMouseY, pFrom.x, pFrom.y, pTo.x, pTo.y);
}
}
if (dist < threshold) {
hoveredConnFrom = conn.idFrom;
@@ -910,7 +1095,6 @@ public abstract class GuiDiagram extends Gui {
selectedIconIds.add(conn.idFrom);
selectedIconIds.add(conn.idTo);
onConnectionHover(conn);
break outer;
}
}
}
@@ -977,6 +1161,28 @@ public abstract class GuiDiagram extends Gui {
}
}
protected void drawIconBox(int slotX, int slotY, int slotSize, boolean highlighted) {
int bg = highlighted ? mixColors(iconBackgroundColor, 0xFFFFFFFF, 0.2f) : iconBackgroundColor;
drawRect(slotX, slotY, slotX + slotSize, slotY + slotSize, bg);
for (int i = 0; i < iconBorderThickness; i++) {
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + i, iconBorderColor);
drawHorizontalLine(slotX + i, slotX + slotSize - i, slotY + slotSize - 1 - i, iconBorderColor);
drawVerticalLine(slotX + i, slotY + i, slotY + slotSize - i, iconBorderColor);
drawVerticalLine(slotX + slotSize - 1 - i, slotY + i, slotY + slotSize - i, iconBorderColor);
}
}
protected int mixColors(int color1, int color2, float ratio) {
int a1 = (color1 >> 24) & 0xFF, r1 = (color1 >> 16) & 0xFF, g1 = (color1 >> 8) & 0xFF, b1 = color1 & 0xFF;
int a2 = (color2 >> 24) & 0xFF, r2 = (color2 >> 16) & 0xFF, g2 = (color2 >> 8) & 0xFF, b2 = color2 & 0xFF;
int a = (int) (a1 + (a2 - a1) * ratio);
int r = (int) (r1 + (r2 - r1) * ratio);
int g = (int) (g1 + (g2 - g1) * ratio);
int b = (int) (b1 + (b2 - b1) * ratio);
return (a << 24) | (r << 16) | (g << 8) | b;
}
// --- Utility Methods ---
protected DiagramIcon getIconById(int id) {
for (DiagramIcon icon : getIcons()) {
@@ -993,20 +1199,20 @@ public abstract class GuiDiagram extends Gui {
}
protected int getConnectionColor(DiagramConnection conn) {
float percent = conn.percent;
if (percent <= 0.10f) return 0xFF80FF80;
else if (percent <= 0.40f) return 0xFFCCFF66;
else if (percent <= 0.50f) return 0xFFFFA500;
else {
float ratio = (percent - 0.50f) / 0.50f;
ratio = Math.min(1f, Math.max(0f, ratio));
int r1 = 0xFF, g1 = 0xA5, b1 = 0x00;
int r2 = 0xFF, g2 = 0x00, b2 = 0x00;
int r = r1 + (int) ((r2 - r1) * ratio);
int g = g1 + (int) ((g2 - g1) * ratio);
int b = b1 + (int) ((b2 - b1) * ratio);
return (0xFF << 24) | (r << 16) | (g << 8) | b;
float value = Math.max(-1f, Math.min(1f, conn.percent));
int r, g, b;
if (value >= 0f) {
float t = value;
r = (int)(144 + (0 - 144) * t);
g = (int)(238 + (100 - 238) * t);
b = (int)(144 + (0 - 144) * t);
} else {
float t = -value;
r = (int)(255 + (139 - 255) * t);
g = (int)(200 + (0 - 200) * t);
b = 0;
}
return (0xFF << 24) | (r << 16) | (g << 8) | b;
}
private double pointLineDistance(int px, int py, int x1, int y1, int x2, int y2) {
@@ -11,6 +11,7 @@ public class GuiNpcLabel {
public int x, y, color;
public boolean enabled = true;
public int id;
public boolean drawShadow = false;
public GuiNpcLabel(int id, Object label, int x, int y, int color) {
this.id = id;
@@ -26,7 +27,7 @@ public class GuiNpcLabel {
public void drawLabel(GuiScreen gui, FontRenderer fontRenderer) {
if (enabled)
fontRenderer.drawString(label, x, y, color);
fontRenderer.drawString(label, x, y, color, drawShadow);
}
public void center(int width) {
@@ -319,7 +319,9 @@ public class RenderCNPCPlayer extends RenderPlayer {
// Render the arm
this.modelBipedMain.onGround = 0.0F;
this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, player);
this.modelBipedMain.bipedRightArm.render(0.0625F);
if(this.modelBipedMain.bipedRightArm != null)
this.modelBipedMain.bipedRightArm.render(0.0625F);
postRenderOverlay();
}
@@ -26,8 +26,8 @@ public class ItemToolRenderer implements IItemRenderer {
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png");
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png");
private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcHammer.png");
private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcToolHammer.png");
private static final ResourceLocation MAGIC_BOOK = new ResourceLocation("customnpcs", "textures/items/npcToolMagicBook.png");
private final Random random = new Random();
@@ -78,8 +78,10 @@ public class ItemToolRenderer implements IItemRenderer {
float blue = (color & 0xFF) / 255.0F;
GL11.glColor3f(red, green, blue);
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH);
} else {
} else if (itemStack.getItemDamage() == 0){
renderEntityCustomItem(itemStack, entityItem, HAMMER);
} else if (itemStack.getItemDamage() == 2){
renderEntityCustomItem(itemStack, entityItem, MAGIC_BOOK);
}
GL11.glPopMatrix();
return;
@@ -112,10 +114,14 @@ public class ItemToolRenderer implements IItemRenderer {
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH);
GL11.glPopMatrix();
} else {
} else if (itemStack.getItemDamage() == 0){
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, HAMMER);
GL11.glPopMatrix();
} else if (itemStack.getItemDamage() == 2){
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, MAGIC_BOOK);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
@@ -291,9 +297,12 @@ public class ItemToolRenderer implements IItemRenderer {
float blue = (color & 0xFF) / 255.0F;
textureManager.bindTexture(PAINTBRUSH_BRUSH);
renderCustomItemSlot(0, 0, 16, 16, red, green, blue);
} else {
} else if (itemStack.getItemDamage() == 0){
textureManager.bindTexture(HAMMER);
renderCustomItemSlot(0, 0, 16, 16, 1.0f, 1.0f, 1.0f);
} else if (itemStack.getItemDamage() == 2){
textureManager.bindTexture(MAGIC_BOOK);
renderCustomItemSlot(0, 0, 16, 16, 1.0f, 1.0f, 1.0f);
}
GL11.glEnable(GL11.GL_LIGHTING);
@@ -62,5 +62,6 @@ public enum EnumGuiType {
CustomGui,
ScriptItem,
ScriptBlock,
Paintbrush;
Paintbrush,
MagicBook;
}
@@ -251,7 +251,6 @@ public class CustomEffectController implements ICustomEffectHandler {
CustomEffect parent = get(id, index);
if (parent != null) {
PlayerEffect playerEffect = new PlayerEffect(id, duration, level, index);
playerEffect.index = index;
currentEffects.put(new EffectKey(id, index), playerEffect);
parent.onAdded(player, playerEffect);
}
@@ -519,7 +518,9 @@ public class CustomEffectController implements ICustomEffectHandler {
@Override
public int getEffectDuration(IPlayer player, ICustomEffect effect) {
return getEffectDuration(player, effect.getID());
if(effect == null)
return -1;
return getEffectDuration(player, effect.getID(), effect.getIndex());
}
@Override
@@ -10,6 +10,7 @@ import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.handler.IMagicHandler;
import noppes.npcs.constants.EnumDiagramLayout;
import noppes.npcs.controllers.data.Magic;
import noppes.npcs.controllers.data.MagicAssociation;
import noppes.npcs.controllers.data.MagicCycle;
@@ -99,26 +100,55 @@ public class MagicController implements IMagicHandler {
arcane.setItem(new ItemStack(CustomItems.spellArcane));
// Insiders
earth.interactions.put(air.id, 0.60f);
water.interactions.put(earth.id, 0.60f);
fire.interactions.put(water.id, 0.60f);
air.interactions.put(fire.id, 0.60f);
earth.interactions.put(air.id, -0.50f);
air.interactions.put(earth.id, 0.50f);
water.interactions.put(earth.id, -0.50f);
earth.interactions.put(water.id, 0.50f);
fire.interactions.put(water.id, -0.50f);
water.interactions.put(fire.id, 0.50f);
air.interactions.put(fire.id, -0.50f);
fire.interactions.put(air.id, 0.50f);
// Outsiders
dark.interactions.put(nature.id, 0.60f);
nature.interactions.put(holy.id, 0.60f);
holy.interactions.put(arcane.id, 0.60f);
arcane.interactions.put(dark.id, 0.60f);
dark.interactions.put(nature.id, -0.50f);
nature.interactions.put(dark.id, 0.50f);
nature.interactions.put(holy.id, -0.50f);
holy.interactions.put(nature.id, 0.50f);
holy.interactions.put(arcane.id, -0.50f);
arcane.interactions.put(holy.id, 0.50f);
arcane.interactions.put(dark.id, -0.50f);
dark.interactions.put(arcane.id, 0.50f);
// Cross Interactions
earth.interactions.put(nature.id, 0.30f);
water.interactions.put(holy.id, 0.30f);
fire.interactions.put(arcane.id, 0.30f);
air.interactions.put(dark.id, 0.30f);
dark.interactions.put(fire.id, 0.30f);
nature.interactions.put(air.id, 0.30f);
holy.interactions.put(earth.id, 0.30f);
arcane.interactions.put(water.id, 0.30f);
earth.interactions.put(nature.id, -0.25f);
nature.interactions.put(earth.id, 0.25f);
water.interactions.put(holy.id, -0.25f);
holy.interactions.put(water.id, 0.25f);
fire.interactions.put(arcane.id, -0.25f);
arcane.interactions.put(fire.id, 0.25f);
air.interactions.put(dark.id, -0.25f);
dark.interactions.put(air.id, 0.25f);
dark.interactions.put(fire.id, -0.25f);
fire.interactions.put(dark.id, 0.25f);
nature.interactions.put(air.id, -0.25f);
air.interactions.put(nature.id, 0.25f);
holy.interactions.put(earth.id, -0.25f);
earth.interactions.put(holy.id, 0.25f);
arcane.interactions.put(water.id, -0.25f);
water.interactions.put(arcane.id, 0.25f);
// Add them to the registry
magics.put(earth.id, earth);
@@ -133,7 +163,8 @@ public class MagicController implements IMagicHandler {
MagicCycle defaultCycle = new MagicCycle();
defaultCycle.id = getUnusedCycleId();
defaultCycle.name = "Universal";
defaultCycle.displayName = "Elementa Cycle";
defaultCycle.layout = EnumDiagramLayout.CIRCULAR_MANUAL;
defaultCycle.displayName = "&6Elementa Cycle";
cycles.put(defaultCycle.id, defaultCycle);
// Add magic associations using your old index and priority values:
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.EventHooks;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.ICustomEffect;
@@ -181,48 +182,62 @@ public class CustomEffect implements ICustomEffect {
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
if(playerEffect.index == 0){
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
if (onAddedConsumer != null) onAddedConsumer.accept(event);
EffectScript script = getScriptHandler();
if (script == null) {
return;
if (onAddedConsumer != null)
onAddedConsumer.accept(event);
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnEffectAdd, event);
}
script.callScript(EffectScript.ScriptType.OnAdd, event);
EventHooks.onEffectAdded(iPlayer, playerEffect);
}
public void onTick(EntityPlayer player, PlayerEffect playerEffect) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
if(playerEffect.index == 0){
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
if (onTickConsumer != null) {
onTickConsumer.accept(event);
if (onTickConsumer != null) {
onTickConsumer.accept(event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnEffectTick, event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnTick, event);
EventHooks.onEffectTick(iPlayer, playerEffect);
}
public void onRemoved(EntityPlayer player, PlayerEffect playerEffect, PlayerEvent.EffectEvent.ExpirationType type) {
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
if(playerEffect.index == 0){
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
if (onRemovedConsumer != null) {
onRemovedConsumer.accept(event);
if (onRemovedConsumer != null) {
onRemovedConsumer.accept(event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnEffectRemove, event);
}
EffectScript script = getScriptHandler();
if (script == null) {
return;
}
script.callScript(EffectScript.ScriptType.OnRemove, event);
EventHooks.onEffectRemove(iPlayer, playerEffect, type);
}
public NBTTagCompound writeToNBT(boolean saveScripts) {
@@ -165,9 +165,9 @@ public class EffectScript implements INpcScriptHandler {
}
public enum ScriptType {
OnAdd("onAdded"),
OnTick("onTick"),
OnRemove("onRemove");
OnEffectAdd("onEffectAdd"),
OnEffectTick("onEffectTick"),
OnEffectRemove("onEffectRemove");
public final String function;
@@ -84,7 +84,7 @@ public class PlayerDataScript implements INpcScriptHandler {
scriptContainer.errored = false;
}
if (!Objects.equals(hookName, EnumScriptType.INIT.function)) {
if (!Objects.equals(hookName, EnumScriptType.INIT.function) && event instanceof noppes.npcs.scripted.event.PlayerEvent) {
noppes.npcs.scripted.event.PlayerEvent playerEvent = (noppes.npcs.scripted.event.PlayerEvent) event;
EventHooks.onPlayerInit(this, playerEvent.player);
}
@@ -2,6 +2,8 @@ package noppes.npcs.items;
import cpw.mods.fml.common.registry.GameRegistry;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.player.item.GuiMagicBookPacket;
import kamkeel.npcs.network.packets.player.item.GuiPaintbrushPacket;
import kamkeel.npcs.network.packets.request.item.ColorBrushPacket;
import kamkeel.npcs.network.packets.request.item.ColorSetPacket;
import kamkeel.npcs.network.packets.request.item.HammerPacket;
@@ -32,7 +34,7 @@ public class ItemNpcTool extends Item {
// Define our tool types based on metadata:
// meta 0: Hammer, meta 1: Paintbrush, meta 2: Wrench
public static final String[] toolTypes = new String[]{"hammer", "paintbrush"};
public static final String[] toolTypes = new String[]{"hammer", "paintbrush", "magic_book"};
public static String BRUSH_COLOR_TAG = "BrushColor";
public ItemNpcTool() {
@@ -62,13 +64,18 @@ public class ItemNpcTool extends Item {
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (world.isRemote)
if (!world.isRemote)
return stack;
if (isPaintbrush(stack) && player.isSneaking()) {
if (CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.PAINTBRUSH_GUI)) {
NoppesUtil.requestOpenGUI(EnumGuiType.Paintbrush);
PacketClient.sendClient(new GuiPaintbrushPacket(EnumGuiType.Paintbrush.ordinal(), 0, 0, 0));
}
return stack;
}
if (isMagicBook(stack)) {
PacketClient.sendClient(new GuiMagicBookPacket(EnumGuiType.MagicBook.ordinal(), 0, 0, 0));
return stack;
}
return stack;
}
@@ -145,6 +152,10 @@ public class ItemNpcTool extends Item {
return itemStack.getItemDamage() == 0;
}
public static boolean isMagicBook(ItemStack itemStack) {
return itemStack.getItemDamage() == 2;
}
@Override
public Item setUnlocalizedName(String name) {
GameRegistry.registerItem(this, name);
@@ -3,6 +3,7 @@ package noppes.npcs.scripted;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.EventBus;
import foxz.command.ScriptedCommand;
import kamkeel.npcs.controllers.AttributeController;
import kamkeel.npcs.controllers.ProfileController;
import net.minecraft.block.Block;
import net.minecraft.command.CommandHandler;
@@ -261,6 +262,10 @@ public class NpcAPI extends AbstractNpcAPI {
return PartyController.Instance();
}
public IAttributeHandler getAttributeHandler() {
return AttributeController.Instance;
}
public ITransportHandler getLocations() {
return TransportController.getInstance();
}
@@ -493,17 +493,24 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
}
public IItemStack[] getInventory() {
// Get the base inventory from the super class
IItemStack[] baseInventory = super.getInventory();
// Load extra items from the NBT data
NBTTagCompound compound = new NBTTagCompound();
this.player.writeToNBT(compound);
NBTTagList list = compound.getCompoundTag("JRMCEP").getTagList("dbcExtraInvTag", 10);
IItemStack[] itemList = new IItemStack[list.tagCount()];
for (int i = 0; i < list.tagCount(); i++) {
ItemStack itemStack = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(i));
itemList[i] = NpcAPI.Instance().getIItemStack(itemStack);
NBTTagList extraList = compound.getCompoundTag("JRMCEP").getTagList("dbcExtraInvTag", 10);
IItemStack[] extraInventory = new IItemStack[extraList.tagCount()];
for (int i = 0; i < extraList.tagCount(); i++) {
ItemStack itemStack = ItemStack.loadItemStackFromNBT(extraList.getCompoundTagAt(i));
extraInventory[i] = NpcAPI.Instance().getIItemStack(itemStack);
}
return itemList;
// Combine base and extra inventories
IItemStack[] fullInventory = new IItemStack[baseInventory.length + extraInventory.length];
System.arraycopy(baseInventory, 0, fullInventory, 0, baseInventory.length);
System.arraycopy(extraInventory, 0, fullInventory, baseInventory.length, extraInventory.length);
return fullInventory;
}
public void setForm(byte form) {
@@ -1,5 +1,6 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.controllers.AttributeController;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
@@ -836,4 +837,6 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
public IMagicData getMagicData() {
return this.getData().magicData;
}
public IPlayerAttributes getAttributes(){ return AttributeController.getTracker(this.player); }
}
@@ -1,6 +1,9 @@
package noppes.npcs.scripted.item;
import com.google.common.collect.Multimap;
import kamkeel.npcs.controllers.data.attribute.requirement.IRequirementChecker;
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
import kamkeel.npcs.util.AttributeItemUtil;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.ai.attributes.AttributeModifier;
@@ -22,10 +25,7 @@ import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptNbt;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ScriptItemStack implements IItemStack {
public ItemStack item;
@@ -454,4 +454,131 @@ public class ScriptItemStack implements IItemStack {
public boolean compare(IItemStack item, boolean ignoreDamage, boolean ignoreNBT) {
return NoppesUtilPlayer.compareItems(getMCItemStack(), item.getMCItemStack(), ignoreDamage, ignoreNBT);
}
@Override
public void setCustomAttribute(String key, double value) {
AttributeItemUtil.applyAttribute(item, key, (float) value);
}
@Override
public boolean hasCustomAttribute(String key) {
return AttributeItemUtil.readAttributes(item).containsKey(key);
}
@Override
public float getCustomAttribute(String key) {
return hasCustomAttribute(key) ? AttributeItemUtil.readAttributes(item).get(key) : 0.0f;
}
@Override
public void removeCustomAttribute(String key) {
AttributeItemUtil.removeAttribute(item, key);
}
@Override
public void setMagicAttribute(String key, int magicId, double value) {
AttributeItemUtil.writeMagicAttribute(item, key, magicId, (float) value);
}
@Override
public float getMagicAttribute(String key, int magicId) {
Map<Integer, Float> magicMap = AttributeItemUtil.readMagicAttributeMap(item, key);
return magicMap.getOrDefault(magicId, 0.0f);
}
@Override
public boolean hasMagicAttribute(String key, int magicId) {
Map<Integer, Float> magicMap = AttributeItemUtil.readMagicAttributeMap(item, key);
return magicMap.containsKey(magicId);
}
@Override
public void removeMagicAttribute(String key, int magicId) {
AttributeItemUtil.removeMagicAttribute(item, key, magicId);
}
@Override
public void setRequirement(String reqKey, Object value) {
// Delegate to the utility method that applies the requirement into the item's NBT.
AttributeItemUtil.applyRequirement(item, reqKey, value);
}
@Override
public boolean hasRequirement(String reqKey) {
if (item == null || item.stackTagCompound == null)
return false;
NBTTagCompound root = item.stackTagCompound;
if (!root.hasKey(AttributeItemUtil.TAG_RPGCORE))
return false;
NBTTagCompound rpgCore = root.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
if (!rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS))
return false;
NBTTagCompound reqTag = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
return reqTag.hasKey(reqKey);
}
@Override
public Object getRequirement(String reqKey) {
if (item == null || item.stackTagCompound == null)
return null;
NBTTagCompound root = item.stackTagCompound;
if (!root.hasKey(AttributeItemUtil.TAG_RPGCORE))
return null;
NBTTagCompound rpgCore = root.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
if (!rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS))
return null;
NBTTagCompound reqTag = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
if (reqTag.hasKey(reqKey)) {
IRequirementChecker checker = RequirementCheckerRegistry.getChecker(reqKey);
if (checker != null) {
return checker.getValue(reqTag);
}
// If no checker exists, fall back to returning the raw stored value.
NBTBase tag = reqTag.getTag(reqKey);
if (tag instanceof NBTPrimitive)
return ((NBTPrimitive) tag).func_150286_g();
if (tag instanceof NBTTagString)
return ((NBTTagString) tag).func_150285_a_();
return tag;
}
return null;
}
@Override
public void removeRequirement(String reqKey) {
AttributeItemUtil.removeRequirement(item, reqKey);
}
@Override
public String[] getCustomAttributeKeys() {
Map<String, Float> attrs = AttributeItemUtil.readAttributes(item);
return attrs.keySet().toArray(new String[attrs.size()]);
}
@Override
public String[] getMagicAttributeKeys(String key) {
Map<Integer, Float> magicMap = AttributeItemUtil.readMagicAttributeMap(item, key);
// Convert the integer magic IDs to strings.
String[] keys = new String[magicMap.size()];
int i = 0;
for (Integer magicId : magicMap.keySet()) {
keys[i++] = magicId.toString();
}
return keys;
}
@Override
public String[] getRequirementKeys() {
if (item == null || item.stackTagCompound == null)
return new String[0];
NBTTagCompound root = item.stackTagCompound;
if (!root.hasKey(AttributeItemUtil.TAG_RPGCORE))
return new String[0];
NBTTagCompound rpgCore = root.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
if (!rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS))
return new String[0];
NBTTagCompound reqTag = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
Set<String> keys = reqTag.func_150296_c();
return keys.toArray(new String[keys.size()]);
}
}
@@ -775,6 +775,7 @@ item.scripted_item.name=Scripted Item
item.linked_item.name=Linked Item
item.npcTool.hammer.name=Npc Hammer
item.npcTool.paintbrush.name=Npc Brush
item.npcTool.magic_book.name=Magic Book
item.npcBanjo.name=Banjo
Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

-20
View File
@@ -1,20 +0,0 @@
TODO List
Magic:
- Create MagicData Class -- Done
-- Magic Data: Magic ID, % Split, Bonus Damage
- Store Magic on PlayerData and NPCs -- Done
Profile:
- On Profile Slot Change Event -- WIP
- On Profile Slot Create Event -- WIP
- On Profile Slot Delete Event -- WIP
ScriptPlayer and ScriptNPC
-- Apply, Removing and Checking Magic Types
Interfaces:
- IMagic -- Done
- IProfile -- Need Work
- ISlot -- Done