mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 08:45:11 +00:00
Semi Functioning Magic Map System
This commit is contained in:
1 parent
d28935ab58
commit
50c6ab644b
7 files changed
+988
-197
No files matched your search
@@ -1,54 +1,134 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.handler.data.IMagic;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Magic implements IMagic {
|
||||
public String name = "";
|
||||
public int color = Integer.parseInt("FF00", 16);
|
||||
public String name = "";
|
||||
public int color = Integer.parseInt("FF00", 16);
|
||||
public int id = -1;
|
||||
|
||||
public int id = -1;
|
||||
// Icon as an ItemStack or as a texture file
|
||||
public ItemStack iconItem = null;
|
||||
public String iconTexture = "";
|
||||
|
||||
public Magic(){}
|
||||
// Weaknesses mapping: key = magic ID this magic is weak against,
|
||||
// value = extra damage percentage (as a fraction, e.g. 0.2 for 20% extra damage)
|
||||
public Map<Integer, Float> weaknesses = new HashMap<Integer, Float>();
|
||||
|
||||
public Magic(int id, String name, int color){
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.id = id;
|
||||
}
|
||||
public static String formatName(String name){
|
||||
name = name.toLowerCase().trim();
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
public void readNBT(NBTTagCompound compound){
|
||||
public Magic() {}
|
||||
|
||||
public Magic(int id, String name, int color) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static String formatName(String name) {
|
||||
name = name.toLowerCase().trim();
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
|
||||
public void readNBT(NBTTagCompound compound) {
|
||||
name = compound.getString("Name");
|
||||
color = compound.getInteger("Color");
|
||||
id = compound.getInteger("Slot");
|
||||
}
|
||||
public void writeNBT(NBTTagCompound compound){
|
||||
compound.setInteger("Slot", id);
|
||||
compound.setString("Name", name);
|
||||
compound.setInteger("Color", color);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
if(compound.hasKey("IconItem")){
|
||||
NBTTagCompound itemTag = compound.getCompoundTag("IconItem");
|
||||
iconItem = ItemStack.loadItemStackFromNBT(itemTag);
|
||||
}
|
||||
iconTexture = compound.getString("IconTexture");
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
// Read the weaknesses mapping from NBT.
|
||||
weaknesses.clear();
|
||||
if(compound.hasKey("Weaknesses")) {
|
||||
NBTTagList weaknessList = compound.getTagList("Weaknesses", 10); // compound tags
|
||||
for(int i = 0; i < weaknessList.tagCount(); i++){
|
||||
NBTTagCompound weaknessTag = weaknessList.getCompoundTagAt(i);
|
||||
int weakMagicId = weaknessTag.getInteger("MagicID");
|
||||
float percentage = weaknessTag.getFloat("Percentage");
|
||||
weaknesses.put(weakMagicId, percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setName(String name) { this.name = name; }
|
||||
public void writeNBT(NBTTagCompound compound) {
|
||||
compound.setInteger("Slot", id);
|
||||
compound.setString("Name", name);
|
||||
compound.setInteger("Color", color);
|
||||
|
||||
public void setColor(int color) { this.color = color; }
|
||||
if(iconItem != null) {
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
iconItem.writeToNBT(itemTag);
|
||||
compound.setTag("IconItem", itemTag);
|
||||
}
|
||||
if(iconTexture != null && !iconTexture.isEmpty()){
|
||||
compound.setString("IconTexture", iconTexture);
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
// Write the weaknesses mapping.
|
||||
NBTTagList weaknessList = new NBTTagList();
|
||||
for(Map.Entry<Integer, Float> entry : weaknesses.entrySet()){
|
||||
NBTTagCompound weaknessTag = new NBTTagCompound();
|
||||
weaknessTag.setInteger("MagicID", entry.getKey());
|
||||
weaknessTag.setFloat("Percentage", entry.getValue());
|
||||
weaknessList.appendTag(weaknessTag);
|
||||
}
|
||||
compound.setTag("Weaknesses", weaknessList);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
MagicController.getInstance().saveMagic(this);
|
||||
}
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
MagicController.getInstance().saveMagic(this);
|
||||
}
|
||||
|
||||
public void setIconItem(ItemStack item) {
|
||||
this.iconItem = item;
|
||||
}
|
||||
|
||||
public ItemStack getIconItem() {
|
||||
return this.iconItem;
|
||||
}
|
||||
|
||||
public void setIconTexture(String texture) {
|
||||
this.iconTexture = texture;
|
||||
}
|
||||
|
||||
public String getIconTexture() {
|
||||
return this.iconTexture;
|
||||
}
|
||||
|
||||
public void setWeaknesses(Map<Integer, Float> weaknesses) {
|
||||
this.weaknesses = weaknesses;
|
||||
}
|
||||
|
||||
public Map<Integer, Float> getWeaknesses() {
|
||||
return this.weaknesses;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user