mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 19:43:07 +00:00
Merge remote-tracking branch 'refs/remotes/origin/packet' into animation-events-2
# Conflicts: # src/api # src/main/java/noppes/npcs/CommonProxy.java # src/main/java/noppes/npcs/ServerEventsHandler.java # src/main/java/noppes/npcs/client/PacketHandlerClient.java # src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java # src/main/java/noppes/npcs/controllers/data/AnimationData.java
This commit is contained in:
commit
00af353e65
602 files changed
+29702
-6562
No files matched your search
@@ -0,0 +1,579 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.ICustomEffectHandler;
|
||||
import noppes.npcs.api.handler.data.ICustomEffect;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.controllers.data.EffectKey;
|
||||
import noppes.npcs.controllers.data.EffectScript;
|
||||
import noppes.npcs.controllers.data.PlayerEffect;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static noppes.npcs.scripted.event.PlayerEvent.EffectEvent.ExpirationType;
|
||||
|
||||
public class CustomEffectController implements ICustomEffectHandler {
|
||||
|
||||
public static CustomEffectController Instance = new CustomEffectController();
|
||||
public HashMap<Integer, HashMap<Integer, CustomEffect>> indexMapper = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, CustomEffect> customEffectsSync = new HashMap<>();
|
||||
public HashMap<Integer, CustomEffect> customEffects = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, EffectScript> customEffectScriptHandlers = new HashMap<>();
|
||||
private HashMap<Integer, String> bootOrder;
|
||||
|
||||
private int lastUsedID = 0;
|
||||
public ConcurrentHashMap<UUID, ConcurrentHashMap<EffectKey, PlayerEffect>> playerEffects = new ConcurrentHashMap<>();
|
||||
|
||||
public CustomEffectController() {}
|
||||
|
||||
public static CustomEffectController getInstance() {
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public <T extends CustomEffect> void registerEffectMap(int index, HashMap<Integer, T> effectHashMap) {
|
||||
HashMap<Integer, CustomEffect> map = new HashMap<>(effectHashMap);
|
||||
indexMapper.put(index, map);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
lastUsedID = 0;
|
||||
playerEffects.clear();
|
||||
bootOrder = new HashMap<>();
|
||||
LogWriter.info("Loading custom effects...");
|
||||
readCustomEffectMap();
|
||||
loadCustomEffects();
|
||||
LogWriter.info("Done loading custom effects.");
|
||||
}
|
||||
|
||||
public void runEffects(EntityPlayer player) {
|
||||
Map<EffectKey, PlayerEffect> current = getPlayerEffects(player);
|
||||
for (Map.Entry<EffectKey, PlayerEffect> entry : current.entrySet()) {
|
||||
int id = entry.getKey().getId();
|
||||
int index = entry.getKey().getIndex();
|
||||
CustomEffect effect = get(id, index);
|
||||
if (effect != null) {
|
||||
effect.runEffect(player, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void killEffects(EntityPlayer player) {
|
||||
Map<EffectKey, PlayerEffect> current = getPlayerEffects(player);
|
||||
Iterator<Map.Entry<EffectKey, PlayerEffect>> iterator = current.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<EffectKey, PlayerEffect> entry = iterator.next();
|
||||
int id = entry.getKey().getId();
|
||||
int index = entry.getKey().getIndex();
|
||||
CustomEffect effect = get(id, index);
|
||||
if (effect != null) {
|
||||
if (effect.lossOnDeath) {
|
||||
effect.onRemoved(player, entry.getValue(), ExpirationType.DEATH);
|
||||
iterator.remove();
|
||||
}
|
||||
} else {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomEffect createEffect(String name) {
|
||||
if (has(name))
|
||||
return get(name);
|
||||
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.name = name;
|
||||
|
||||
if (effect.id == -1) {
|
||||
int id = getUnusedId();
|
||||
while (customEffects.containsKey(id)) {
|
||||
id = getUnusedId();
|
||||
}
|
||||
effect.id = id;
|
||||
}
|
||||
customEffects.put(effect.id, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomEffect getEffect(String name) {
|
||||
return get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteEffect(String name) {
|
||||
ICustomEffect effect = getEffect(name);
|
||||
if (effect != null) {
|
||||
CustomEffect foundEffect = customEffects.remove(effect.getID());
|
||||
customEffectScriptHandlers.remove(effect.getID());
|
||||
if (foundEffect != null && foundEffect.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundEffect.name + ".json")) {
|
||||
file.delete();
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
ICustomEffect effect = get(id);
|
||||
if (effect != null) {
|
||||
CustomEffect foundEffect = customEffects.remove(effect.getID());
|
||||
customEffectScriptHandlers.remove(effect.getID());
|
||||
if (foundEffect != null && foundEffect.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equals(foundEffect.name + ".json")) {
|
||||
file.delete();
|
||||
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
for (int catid : customEffects.keySet()) {
|
||||
if (catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
|
||||
|
||||
public CustomEffect get(int id, int index) {
|
||||
HashMap<Integer, CustomEffect> effectMap = indexMapper.get(index);
|
||||
return effectMap != null ? effectMap.get(id) : null;
|
||||
}
|
||||
|
||||
public CustomEffect get(int id) {
|
||||
return get(id, 0);
|
||||
}
|
||||
|
||||
public boolean has(int id, int index) {
|
||||
HashMap<Integer, CustomEffect> effectMap = indexMapper.get(index);
|
||||
return effectMap != null && effectMap.containsKey(id);
|
||||
}
|
||||
|
||||
public boolean has(int id) {
|
||||
return has(id, 0);
|
||||
}
|
||||
|
||||
public CustomEffect get(String name, int index) {
|
||||
HashMap<Integer, CustomEffect> effectMap = indexMapper.get(index);
|
||||
if (effectMap != null) {
|
||||
for (CustomEffect effect : effectMap.values()) {
|
||||
if (effect.getName().equalsIgnoreCase(name)) {
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CustomEffect get(String name) {
|
||||
return get(name, 0);
|
||||
}
|
||||
|
||||
public boolean has(String name, int index) {
|
||||
return get(name, index) != null;
|
||||
}
|
||||
|
||||
public boolean has(String name) {
|
||||
return has(name, 0);
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<EffectKey, PlayerEffect> getPlayerEffects(EntityPlayer player) {
|
||||
UUID playerId = NoppesUtilServer.getUUID(player);
|
||||
ConcurrentHashMap<EffectKey, PlayerEffect> effects = playerEffects.get(playerId);
|
||||
if (effects == null) {
|
||||
effects = new ConcurrentHashMap<>();
|
||||
playerEffects.put(playerId, effects);
|
||||
}
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void removeEffect(EntityPlayer player, PlayerEffect effect, ExpirationType type) {
|
||||
if (effect == null)
|
||||
return;
|
||||
|
||||
Map<EffectKey, PlayerEffect> currentEffects = getPlayerEffects(player);
|
||||
EffectKey key = new EffectKey(effect.id, effect.index);
|
||||
if (currentEffects.containsKey(key)) {
|
||||
CustomEffect parent = get(effect.id, effect.index);
|
||||
if (parent != null) {
|
||||
parent.onRemoved(player, effect, type);
|
||||
}
|
||||
currentEffects.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEffect(IPlayer player, int id) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return false;
|
||||
return hasEffect((EntityPlayer) player.getMCEntity(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEffect(IPlayer player, ICustomEffect effect) {
|
||||
return hasEffect((EntityPlayer) player, effect.getID(), effect.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEffectDuration(IPlayer player, int id) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return -1;
|
||||
return getEffectDuration((EntityPlayer) player.getMCEntity(), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEffectDuration(IPlayer player, ICustomEffect effect) {
|
||||
return getEffectDuration(player, effect.getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEffect(IPlayer player, int id, int duration, byte level) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return;
|
||||
applyEffect((EntityPlayer) player.getMCEntity(), id, duration, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyEffect(IPlayer player, ICustomEffect effect, int duration, byte level) {
|
||||
applyEffect(player, effect.getID(), duration, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEffect(IPlayer player, int id) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return;
|
||||
removeEffect((EntityPlayer) player.getMCEntity(), id, ExpirationType.REMOVED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEffect(IPlayer player, ICustomEffect effect) {
|
||||
removeEffect((EntityPlayer) player.getMCEntity(), (PlayerEffect) effect, ExpirationType.REMOVED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearEffects(IPlayer player) {
|
||||
if (player == null || player.getMCEntity() == null)
|
||||
return;
|
||||
clearEffects((EntityPlayer) player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomEffect saveEffect(ICustomEffect customEffect) {
|
||||
if (customEffect.getID() < 0) {
|
||||
customEffect.setID(getUnusedId());
|
||||
while (has(customEffect.getName()))
|
||||
customEffect.setName(customEffect.getName() + "_");
|
||||
} else {
|
||||
CustomEffect existing = customEffects.get(customEffect.getID());
|
||||
if (existing != null && !existing.name.equals(customEffect.getName()))
|
||||
while (has(customEffect.getName()))
|
||||
customEffect.setName(customEffect.getName() + "_");
|
||||
}
|
||||
|
||||
customEffects.remove(customEffect.getID());
|
||||
customEffects.put(customEffect.getID(), (CustomEffect) customEffect);
|
||||
|
||||
saveEffectLoadMap();
|
||||
|
||||
File dir = this.getDir();
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
File file = new File(dir, customEffect.getName() + ".json_new");
|
||||
File file2 = new File(dir, customEffect.getName() + ".json");
|
||||
|
||||
try {
|
||||
NBTTagCompound nbtTagCompound = ((CustomEffect) customEffect).writeToNBT(true);
|
||||
NBTJsonUtil.SaveFile(file, nbtTagCompound);
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
nbtTagCompound.removeTag("ScriptData");
|
||||
SyncController.syncUpdate(EnumSyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
return customEffects.get(customEffect.getID());
|
||||
}
|
||||
|
||||
public void clearEffects(EntityPlayer player) {
|
||||
Map<EffectKey, PlayerEffect> effects = getPlayerEffects(player);
|
||||
if (effects != null) {
|
||||
effects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearEffect(EntityPlayer player, int id) {
|
||||
clearEffect(player, id, 0);
|
||||
}
|
||||
|
||||
public void clearEffect(EntityPlayer player, int id, int index) {
|
||||
Map<EffectKey, PlayerEffect> effects = getPlayerEffects(player);
|
||||
if (effects != null) {
|
||||
effects.remove(new EffectKey(id, index));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean hasEffect(EntityPlayer player, int id) {
|
||||
return hasEffect(player, id, 0);
|
||||
}
|
||||
|
||||
public boolean hasEffect(EntityPlayer player, int id, int index) {
|
||||
return getPlayerEffects(player).containsKey(new EffectKey(id, index));
|
||||
}
|
||||
|
||||
public int getEffectDuration(EntityPlayer player, int id) {
|
||||
return getEffectDuration(player, id, 0);
|
||||
}
|
||||
|
||||
public int getEffectDuration(EntityPlayer player, int id, int index) {
|
||||
PlayerEffect effect = getPlayerEffects(player).get(new EffectKey(id, index));
|
||||
return effect != null ? effect.duration : -1;
|
||||
}
|
||||
|
||||
public void applyEffect(EntityPlayer player, int id, int duration, byte level) {
|
||||
applyEffect(player, id, duration, level, 0);
|
||||
}
|
||||
|
||||
public void applyEffect(EntityPlayer player, int id, int duration, byte level, int index) {
|
||||
if (player == null || id <= 0) return;
|
||||
Map<EffectKey, PlayerEffect> currentEffects = getPlayerEffects(player);
|
||||
CustomEffect parent = get(id, index);
|
||||
if (parent != null) {
|
||||
PlayerEffect playerEffect = new PlayerEffect(id, duration, level);
|
||||
playerEffect.index = index;
|
||||
currentEffects.put(new EffectKey(id, index), playerEffect);
|
||||
parent.onAdded(player, playerEffect);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEffect(EntityPlayer player, int id) {
|
||||
removeEffect(player, id, 0, ExpirationType.REMOVED);
|
||||
}
|
||||
|
||||
public void removeEffect(EntityPlayer player, int id, ExpirationType type) {
|
||||
removeEffect(player, id, 0, type);
|
||||
}
|
||||
|
||||
public void removeEffect(EntityPlayer player, int id, int index) {
|
||||
removeEffect(player, id, index, ExpirationType.REMOVED);
|
||||
}
|
||||
|
||||
public void removeEffect(EntityPlayer player, int id, int index, ExpirationType type) {
|
||||
if (player == null || id <= 0) return;
|
||||
Map<EffectKey, PlayerEffect> currentEffects = getPlayerEffects(player);
|
||||
EffectKey key = new EffectKey(id, index);
|
||||
PlayerEffect effect = currentEffects.get(key);
|
||||
if (effect != null) {
|
||||
this.removeEffect(player, effect, type);
|
||||
}
|
||||
}
|
||||
|
||||
public void decrementEffects(EntityPlayer player) {
|
||||
Iterator<PlayerEffect> iterator = getPlayerEffects(player).values().iterator();
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
while (iterator.hasNext()) {
|
||||
PlayerEffect effect = iterator.next();
|
||||
if (effect == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (effect.duration == -100)
|
||||
continue;
|
||||
if (effect.duration <= 0) {
|
||||
CustomEffect parent = CustomEffectController.Instance.get(effect.id);
|
||||
if (parent != null) {
|
||||
parent.onRemoved(player, effect, ExpirationType.RUN_OUT);
|
||||
}
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
effect.duration--;
|
||||
}
|
||||
}
|
||||
|
||||
public File getMapDir() {
|
||||
File dir = CustomNpcs.getWorldSaveDirectory();
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return dir;
|
||||
}
|
||||
|
||||
private void loadCustomEffects() {
|
||||
customEffects.clear();
|
||||
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
} else {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
try {
|
||||
CustomEffect effect = new CustomEffect();
|
||||
effect.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
effect.name = file.getName().substring(0, file.getName().length() - 5);
|
||||
if (effect.id == -1) {
|
||||
effect.id = getUnusedId();
|
||||
}
|
||||
int originalID = effect.id;
|
||||
int setID = effect.id;
|
||||
while (bootOrder.containsKey(setID) || customEffects.containsKey(setID)) {
|
||||
if (bootOrder.containsKey(setID))
|
||||
if (bootOrder.get(setID).equals(effect.name))
|
||||
break;
|
||||
setID++;
|
||||
}
|
||||
effect.id = setID;
|
||||
if (originalID != setID) {
|
||||
LogWriter.info("Found Custom Effect ID Mismatch: " + effect.name + ", New ID: " + setID);
|
||||
effect.save();
|
||||
}
|
||||
customEffects.put(effect.id, effect);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
registerEffectMap(0, customEffects);
|
||||
saveEffectLoadMap();
|
||||
}
|
||||
|
||||
public HashMap<Integer, CustomEffect> getEffectMap(int index){
|
||||
if(indexMapper.containsKey(index)){
|
||||
return getEffectMap(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private File getDir() {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "customeffects");
|
||||
}
|
||||
|
||||
private void saveEffectLoadMap() {
|
||||
try {
|
||||
File saveDir = getMapDir();
|
||||
File file = new File(saveDir, "customeffects.dat_new");
|
||||
File file1 = new File(saveDir, "customeffects.dat_old");
|
||||
File file2 = new File(saveDir, "customeffects.dat");
|
||||
CompressedStreamTools.writeCompressed(this.writeMapNBT(), new FileOutputStream(file));
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
|
||||
private NBTTagCompound writeMapNBT() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
NBTTagList customEffectsList = new NBTTagList();
|
||||
for (Integer key : this.customEffects.keySet()) {
|
||||
CustomEffect customEffect = this.customEffects.get(key);
|
||||
if (!customEffect.getName().isEmpty()) {
|
||||
NBTTagCompound effectCompound = new NBTTagCompound();
|
||||
effectCompound.setString("Name", customEffect.getName());
|
||||
effectCompound.setInteger("ID", key);
|
||||
customEffectsList.appendTag(effectCompound);
|
||||
}
|
||||
}
|
||||
nbt.setTag("CustomEffects", customEffectsList);
|
||||
nbt.setInteger("lastID", lastUsedID);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
private void readCustomEffectMap() {
|
||||
bootOrder.clear();
|
||||
try {
|
||||
File file = new File(getMapDir(), "customeffects.dat");
|
||||
if (file.exists()) {
|
||||
loadCustomEffectMap(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(getMapDir(), "customeffects.dat_old");
|
||||
if (file.exists()) {
|
||||
loadCustomEffectMap(file);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCustomEffectMap(File file) throws IOException {
|
||||
DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
|
||||
readCustomEffectMap(dis);
|
||||
dis.close();
|
||||
}
|
||||
|
||||
private void readCustomEffectMap(DataInputStream stream) throws IOException {
|
||||
NBTTagCompound nbtCompound = CompressedStreamTools.read(stream);
|
||||
this.readMapNBT(nbtCompound);
|
||||
}
|
||||
|
||||
private void readMapNBT(NBTTagCompound compound) {
|
||||
lastUsedID = compound.getInteger("lastID");
|
||||
NBTTagList list = compound.getTagList("CustomEffects", 10);
|
||||
if (list != null) {
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
|
||||
String effectName = nbttagcompound.getString("Name");
|
||||
Integer key = nbttagcompound.getInteger("ID");
|
||||
bootOrder.put(key, effectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteEffectFile(String prevName) {
|
||||
File dir = this.getDir();
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
File file2 = new File(dir, prevName + ".json");
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.script.ScriptOverlayDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
@@ -27,13 +29,13 @@ public class CustomGuiController {
|
||||
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player.getMCEntity();
|
||||
entityPlayerMP.openGui(CustomNpcs.instance, EnumGuiType.CustomGui.ordinal(), player.getWorld().getMCWorld(), gui.getSlots().size(), 0, 0);
|
||||
((ContainerCustomGui)((EntityPlayerMP)player.getMCEntity()).openContainer).setGui(gui, (EntityPlayer)player.getMCEntity());
|
||||
Server.sendDataChecked((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.GUI_DATA, new Object[]{gui.toNBT()});
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP)player.getMCEntity(), gui.toNBT());
|
||||
}
|
||||
|
||||
public static boolean updateGui(IPlayer player, ScriptGui gui) {
|
||||
if (((EntityPlayerMP)player.getMCEntity()).openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui)((EntityPlayerMP)player.getMCEntity()).openContainer).setGui(gui, (EntityPlayer)player.getMCEntity());
|
||||
Server.sendDataChecked((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.GUI_DATA, new Object[]{gui.toNBT()});
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP)player.getMCEntity(), gui.toNBT());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -41,11 +43,11 @@ public class CustomGuiController {
|
||||
}
|
||||
|
||||
public static void openOverlay(IPlayer player, ScriptOverlay gui) {
|
||||
Server.sendDataChecked((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.SCRIPT_OVERLAY_DATA, new Object[]{gui.toNBT()});
|
||||
PacketHandler.Instance.sendToPlayer(new ScriptOverlayDataPacket(gui.toNBT()), (EntityPlayerMP)player.getMCEntity());
|
||||
}
|
||||
|
||||
public static boolean updateOverlay(IPlayer player, ScriptOverlay gui) {
|
||||
Server.sendDataChecked((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.SCRIPT_OVERLAY_DATA, new Object[]{gui.toNBT()});
|
||||
PacketHandler.Instance.sendToPlayer(new ScriptOverlayDataPacket(gui.toNBT()), (EntityPlayerMP)player.getMCEntity());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -130,7 +132,7 @@ public class CustomGuiController {
|
||||
|
||||
public static String[] readScrollSelection(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagList list = Server.readNBT(buffer).getTagList("selection", 8);
|
||||
NBTTagList list = ByteBufUtils.readNBT(buffer).getTagList("selection", 8);
|
||||
String[] selection = new String[list.tagCount()];
|
||||
|
||||
for(int i = 0; i < list.tagCount(); ++i) {
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IDialogHandler;
|
||||
import noppes.npcs.api.handler.data.IDialog;
|
||||
import noppes.npcs.api.handler.data.IDialogCategory;
|
||||
import noppes.npcs.constants.EnumOptionType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogCategory;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
@@ -92,6 +91,7 @@ public class DialogController implements IDialogHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DialogCategory loadCategoryDir(File dir) {
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.title = dir.getName();
|
||||
@@ -104,6 +104,11 @@ public class DialogController implements IDialogHandler {
|
||||
dialog.readNBTPartial(NBTJsonUtil.LoadFile(file));
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
dialog.category = category;
|
||||
|
||||
if (dialog.text != null && dialog.text.length() > 15000) {
|
||||
LogWriter.error("Extremely big dialog loaded: [ID: " + dialog.id + "] Title: "
|
||||
+ dialog.title + " (Length: " + dialog.text.length() + " chars)");
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
|
||||
@@ -230,7 +235,7 @@ public class DialogController implements IDialogHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
SyncController.updateDialogCat(category);
|
||||
SyncController.syncUpdate(EnumSyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category));
|
||||
}
|
||||
|
||||
public void removeCategory(int category){
|
||||
@@ -243,8 +248,8 @@ public class DialogController implements IDialogHandler {
|
||||
for(int dia : cat.dialogs.keySet())
|
||||
dialogs.remove(dia);
|
||||
categories.remove(category);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG_CATEGORY, category);
|
||||
}
|
||||
SyncController.syncRemove(EnumSyncType.DIALOG_CATEGORY, category);
|
||||
}
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
name = name.toLowerCase();
|
||||
@@ -291,7 +296,7 @@ public class DialogController implements IDialogHandler {
|
||||
if(file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG, dialog.writeToNBT(new NBTTagCompound()), category.id);
|
||||
SyncController.syncUpdate(EnumSyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
@@ -305,7 +310,7 @@ public class DialogController implements IDialogHandler {
|
||||
return;
|
||||
category.dialogs.remove(dialog.id);
|
||||
dialogs.remove(dialog.id);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG, dialog.id);
|
||||
SyncController.syncRemove(EnumSyncType.DIALOG, dialog.id);
|
||||
}
|
||||
|
||||
private File getDir(){
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IFactionHandler;
|
||||
import noppes.npcs.api.handler.data.IFaction;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Faction;
|
||||
|
||||
import java.io.*;
|
||||
@@ -158,7 +157,7 @@ public class FactionController implements IFactionHandler {
|
||||
|
||||
NBTTagCompound facCompound = new NBTTagCompound();
|
||||
faction.writeNBT(facCompound);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.FACTION, facCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.FACTION, -1, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
@@ -193,7 +192,7 @@ public class FactionController implements IFactionHandler {
|
||||
} else {
|
||||
this.saveFactions();
|
||||
faction.id = -1;
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.FACTION, id);
|
||||
SyncController.syncRemove(EnumSyncType.FACTION, id);
|
||||
return faction;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
public class LinkedNpcController {
|
||||
public static LinkedNpcController Instance;
|
||||
public List<LinkedData> list = new ArrayList<LinkedData>();
|
||||
|
||||
|
||||
public LinkedNpcController(){
|
||||
Instance = this;
|
||||
load();
|
||||
@@ -30,14 +30,14 @@ public class LinkedNpcController {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public File getDir(){
|
||||
File dir = new File(CustomNpcs.getWorldSaveDirectory(), "linkednpcs");
|
||||
if(!dir.exists())
|
||||
dir.mkdir();
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
private void loadNpcs(){
|
||||
LogWriter.info("Loading Linked Npcs");
|
||||
File dir = getDir();
|
||||
@@ -56,12 +56,12 @@ public class LinkedNpcController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.list = list;
|
||||
}
|
||||
LogWriter.info("Done loading Linked Npcs");
|
||||
}
|
||||
|
||||
|
||||
public void save(){
|
||||
for(LinkedData npc : list){
|
||||
try {
|
||||
@@ -71,17 +71,17 @@ public class LinkedNpcController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void saveNpc(LinkedData npc) throws IOException {
|
||||
File file = new File(getDir(), npc.name + ".json_new");
|
||||
File file1 = new File(getDir(), npc.name + ".json");
|
||||
File file1 = new File(getDir(), npc.name + ".json");
|
||||
try{
|
||||
NBTJsonUtil.SaveFile(file, npc.getNBT());
|
||||
if(file1.exists()){
|
||||
file1.delete();
|
||||
}
|
||||
file.renameTo(file1);
|
||||
|
||||
|
||||
} catch (JsonException e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
@@ -91,16 +91,16 @@ public class LinkedNpcController {
|
||||
public String name = "LinkedNpc";
|
||||
public long time = 0;
|
||||
public NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
|
||||
public LinkedData(){
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public void setNBT(NBTTagCompound compound){
|
||||
name = compound.getString("LinkedName");
|
||||
data = compound.getCompoundTag("NPCData");
|
||||
}
|
||||
|
||||
|
||||
public NBTTagCompound getNBT(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setString("LinkedName", name);
|
||||
@@ -123,29 +123,29 @@ public class LinkedNpcController {
|
||||
if(npc.posX == 0 && npc.posY == 0 && npc.posX == 0)
|
||||
return;
|
||||
npc.linkedLast = data.time;
|
||||
List<int[]> points = npc.ai.getMovingPath();
|
||||
List<int[]> points = npc.ais.getMovingPath();
|
||||
|
||||
NBTTagCompound compound = NBTTags.NBTMerge(readNpcData(npc), data.data);
|
||||
|
||||
|
||||
npc.display.readToNBT(compound);
|
||||
npc.stats.readToNBT(compound);
|
||||
npc.advanced.readToNBT(compound);
|
||||
npc.inventory.readEntityFromNBT(compound);
|
||||
if(compound.hasKey("ModelData"))
|
||||
((EntityCustomNpc)npc).modelData.readFromNBT(compound.getCompoundTag("ModelData"));
|
||||
|
||||
npc.ai.readToNBT(compound);
|
||||
|
||||
npc.ais.readToNBT(compound);
|
||||
npc.transform.readToNBT(compound);
|
||||
npc.ai.setMovingPath(points);
|
||||
|
||||
npc.ais.setMovingPath(points);
|
||||
|
||||
npc.updateClient = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void cleanTags(NBTTagCompound compound){
|
||||
compound.removeTag("MovingPathNew");
|
||||
}
|
||||
|
||||
|
||||
public LinkedData getData(String name){
|
||||
for(LinkedData data : list){
|
||||
if(data.name.equalsIgnoreCase(name))
|
||||
@@ -153,26 +153,26 @@ public class LinkedNpcController {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private NBTTagCompound readNpcData(EntityNPCInterface npc){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
npc.display.writeToNBT(compound);
|
||||
npc.inventory.writeEntityToNBT(compound);
|
||||
npc.stats.writeToNBT(compound);
|
||||
npc.ai.writeToNBT(compound);
|
||||
npc.ais.writeToNBT(compound);
|
||||
npc.advanced.writeToNBT(compound);
|
||||
npc.transform.writeToNBT(compound);
|
||||
compound.setTag("ModelData", ((EntityCustomNpc)npc).modelData.writeToNBT());
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
public void saveNpcData(EntityNPCInterface npc) {
|
||||
NBTTagCompound compound = readNpcData(npc);
|
||||
cleanTags(compound);
|
||||
|
||||
|
||||
if(npc.linkedData.data.equals(compound))
|
||||
return;
|
||||
|
||||
|
||||
npc.linkedData.data = compound;
|
||||
npc.linkedData.time = System.currentTimeMillis();
|
||||
save();
|
||||
@@ -185,11 +185,11 @@ public class LinkedNpcController {
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
public void addData(String name){
|
||||
if(getData(name) != null || name.isEmpty())
|
||||
return;
|
||||
|
||||
|
||||
LinkedData data = new LinkedData();
|
||||
data.name = name;
|
||||
list.add(data);
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.util.JsonException;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LinkedScriptedItemController {
|
||||
public static LinkedScriptedItemController Instance;
|
||||
public List<LinkedScriptedItemData> list = new ArrayList<>();
|
||||
|
||||
public LinkedScriptedItemController() {
|
||||
Instance = this;
|
||||
load();
|
||||
}
|
||||
|
||||
public File getDir() {
|
||||
File dir = new File(CustomNpcs.getWorldSaveDirectory(), "linkeditems");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
File dir = getDir();
|
||||
File[] files = dir.listFiles((d, name) -> name.endsWith(".json"));
|
||||
if(files == null) return;
|
||||
for (File file : files) {
|
||||
try {
|
||||
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
|
||||
LinkedScriptedItemData data = new LinkedScriptedItemData();
|
||||
data.loadFromNBT(compound);
|
||||
list.add(data);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading linked items: " + file.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
File dir = getDir();
|
||||
for (LinkedScriptedItemData data : list) {
|
||||
try {
|
||||
File file = new File(dir, data.name + ".json_new");
|
||||
NBTJsonUtil.SaveFile(file, data.saveToNBT());
|
||||
} catch (IOException e) {
|
||||
LogWriter.except(e);
|
||||
} catch (JsonException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LinkedScriptedItemData getData(String name) {
|
||||
for (LinkedScriptedItemData data : list) {
|
||||
if (data.name.equalsIgnoreCase(name)) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addData(String name, NBTTagCompound scriptData) {
|
||||
if (name.isEmpty() || getData(name) != null)
|
||||
return;
|
||||
LinkedScriptedItemData data = new LinkedScriptedItemData();
|
||||
data.name = name;
|
||||
data.scriptData = scriptData;
|
||||
data.time = System.currentTimeMillis();
|
||||
list.add(data);
|
||||
save();
|
||||
}
|
||||
|
||||
public void updateData(String name, NBTTagCompound scriptData) {
|
||||
LinkedScriptedItemData data = getData(name);
|
||||
if (data != null) {
|
||||
data.scriptData = scriptData;
|
||||
data.time = System.currentTimeMillis();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public static class LinkedScriptedItemData {
|
||||
public String name = "LinkedScriptedItem";
|
||||
public long time;
|
||||
public NBTTagCompound scriptData = new NBTTagCompound();
|
||||
|
||||
public LinkedScriptedItemData() {
|
||||
time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void loadFromNBT(NBTTagCompound compound) {
|
||||
name = compound.getString("LinkedScriptName");
|
||||
scriptData = compound.getCompoundTag("ScriptData");
|
||||
time = compound.getLong("Time");
|
||||
}
|
||||
|
||||
public NBTTagCompound saveToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setString("LinkedScriptName", name);
|
||||
compound.setTag("ScriptData", scriptData);
|
||||
compound.setLong("Time", time);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,204 +1,598 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.data.IMagic;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class MagicController {
|
||||
public HashMap<Integer, Magic> magicSync = new HashMap<Integer,Magic>();
|
||||
public HashMap<Integer,Magic> magics;
|
||||
public HashMap<Integer, Magic> magicSync = new HashMap<Integer, Magic>();
|
||||
public HashMap<Integer, Magic> magics;
|
||||
|
||||
private static MagicController instance = new MagicController();
|
||||
private static MagicController instance;
|
||||
|
||||
private int lastUsedID = 0;
|
||||
private int lastUsedID = 0;
|
||||
|
||||
public MagicController(){
|
||||
instance = this;
|
||||
magics = new HashMap<Integer, Magic>();
|
||||
}
|
||||
public MagicController() {
|
||||
instance = this;
|
||||
magics = new HashMap<Integer, Magic>();
|
||||
}
|
||||
|
||||
public static MagicController getInstance(){
|
||||
return instance;
|
||||
}
|
||||
public static MagicController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Magic getMagic(int magic) {
|
||||
return magics.get(magic);
|
||||
}
|
||||
public Magic getMagic(int magic) {
|
||||
return magics.get(magic);
|
||||
}
|
||||
|
||||
public void load(){
|
||||
public void load() {
|
||||
magics = new HashMap<Integer, Magic>();
|
||||
lastUsedID = 0;
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
if(saveDir == null){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
File file = new File(saveDir, "magic.dat");
|
||||
if(file.exists()){
|
||||
loadMagicFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "magic.dat_old");
|
||||
if(file.exists()){
|
||||
loadMagicFile(file);
|
||||
}
|
||||
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
|
||||
if(magics.isEmpty()){
|
||||
magics.put(0,new Magic(0,"Nature", 0x00DD00));
|
||||
magics.put(1,new Magic(1,"Arcane", 0xF2DD00));
|
||||
magics.put(2,new Magic(2,"Ice", 0xDD0000));
|
||||
magics.put(3,new Magic(3,"Fire", 0xDD0000));
|
||||
magics.put(4,new Magic(4,"Dark", 0xDD0000));
|
||||
magics.put(5,new Magic(5,"Holy", 0xDD0000));
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
if (saveDir == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
File file = new File(saveDir, "magic.dat");
|
||||
if (file.exists()) {
|
||||
loadMagicFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "magic.dat_old");
|
||||
if (file.exists()) {
|
||||
loadMagicFile(file);
|
||||
}
|
||||
} catch (Exception ee) { }
|
||||
}
|
||||
magics.clear();
|
||||
if (false) {
|
||||
// Create default Pokémon types
|
||||
Magic normal = new Magic(0, "Normal", 0xA8A878);
|
||||
normal.setIconItem(new ItemStack(net.minecraft.init.Items.paper)); // using paper for Normal
|
||||
|
||||
private void loadMagicFile(File file) throws IOException{
|
||||
DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
|
||||
loadMagic(var1);
|
||||
var1.close();
|
||||
}
|
||||
Magic fire = new Magic(1, "Fire", 0xF08030);
|
||||
fire.setIconItem(new ItemStack(net.minecraft.init.Items.flint)); // flint for Fire
|
||||
|
||||
public void loadMagic(DataInputStream stream) throws IOException{
|
||||
HashMap<Integer,Magic> magic = new HashMap<Integer,Magic>();
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.read(stream);
|
||||
lastUsedID = nbttagcompound1.getInteger("lastID");
|
||||
NBTTagList list = nbttagcompound1.getTagList("NPCMagic", 10);
|
||||
Magic water = new Magic(2, "Water", 0x6890F0);
|
||||
water.setIconItem(new ItemStack(net.minecraft.init.Items.water_bucket)); // water bucket
|
||||
|
||||
if(list != null){
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
|
||||
Magic loadMagic = new Magic();
|
||||
loadMagic.readNBT(nbttagcompound);
|
||||
magic.put(loadMagic.id,loadMagic);
|
||||
}
|
||||
}
|
||||
this.magics = magic;
|
||||
}
|
||||
public NBTTagCompound getNBT(){
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(int slot : magics.keySet()){
|
||||
Magic mag = magics.get(slot);
|
||||
NBTTagCompound nbtfactions = new NBTTagCompound();
|
||||
mag.writeNBT(nbtfactions);
|
||||
list.appendTag(nbtfactions);
|
||||
}
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setInteger("lastID", lastUsedID);
|
||||
nbttagcompound.setTag("NPCFactions", list);
|
||||
return nbttagcompound;
|
||||
}
|
||||
public void saveFactions(){
|
||||
try {
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
File file = new File(saveDir, "magic.dat_new");
|
||||
File file1 = new File(saveDir, "magic.dat_old");
|
||||
File file2 = new File(saveDir, "magic.dat");
|
||||
CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file));
|
||||
if(file1.exists())
|
||||
{
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if(file2.exists())
|
||||
{
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if(file.exists())
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
Magic electric = new Magic(3, "Electric", 0xF8D030);
|
||||
electric.setIconItem(new ItemStack(net.minecraft.init.Items.redstone)); // redstone
|
||||
|
||||
public Magic get(int magicID) {
|
||||
return magics.get(magicID);
|
||||
}
|
||||
Magic grass = new Magic(4, "Grass", 0x78C850);
|
||||
grass.setIconItem(new ItemStack(net.minecraft.init.Items.wheat_seeds)); // wheat seeds
|
||||
|
||||
public List<IMagic> list() {
|
||||
return new ArrayList(this.magics.values());
|
||||
}
|
||||
Magic ice = new Magic(5, "Ice", 0x98D8D8);
|
||||
ice.setIconItem(new ItemStack(net.minecraft.init.Items.snowball)); // snowball for Ice
|
||||
|
||||
public void saveMagic(Magic mag) {
|
||||
Magic fighting = new Magic(6, "Fighting", 0xC03028);
|
||||
fighting.setIconItem(new ItemStack(net.minecraft.init.Items.iron_sword)); // sword for Fighting
|
||||
|
||||
if(mag.id < 0){
|
||||
mag.id = getUnusedId();
|
||||
while(hasName(mag.name))
|
||||
mag.name += "_";
|
||||
}
|
||||
else{
|
||||
Magic existing = magics.get(mag.id);
|
||||
if(existing != null && !existing.name.equals(mag.name))
|
||||
while(hasName(mag.name))
|
||||
mag.name += "_";
|
||||
}
|
||||
magics.remove(mag.id);
|
||||
magics.put(mag.id, mag);
|
||||
Magic poison = new Magic(7, "Poison", 0xA040A0);
|
||||
poison.setIconItem(new ItemStack(net.minecraft.init.Items.potionitem)); // potion item for Poison
|
||||
|
||||
Magic ground = new Magic(8, "Ground", 0xE0C068);
|
||||
ground.setIconItem(new ItemStack(Blocks.dirt)); // dirt for Ground
|
||||
|
||||
Magic flying = new Magic(9, "Flying", 0xA890F0);
|
||||
flying.setIconItem(new ItemStack(net.minecraft.init.Items.feather)); // feather for Flying
|
||||
|
||||
Magic psychic = new Magic(10, "Psychic", 0xF85888);
|
||||
psychic.setIconItem(new ItemStack(net.minecraft.init.Items.ender_pearl)); // ender pearl for Psychic
|
||||
|
||||
Magic bug = new Magic(11, "Bug", 0xA8B820);
|
||||
bug.setIconItem(new ItemStack(net.minecraft.init.Items.spider_eye)); // spider eye for Bug
|
||||
|
||||
Magic rock = new Magic(12, "Rock", 0xB8A038);
|
||||
rock.setIconItem(new ItemStack(Blocks.cobblestone)); // cobblestone for Rock
|
||||
|
||||
Magic ghost = new Magic(13, "Ghost", 0x705898);
|
||||
ghost.setIconItem(new ItemStack(net.minecraft.init.Items.skull)); // skull for Ghost
|
||||
|
||||
Magic dragon = new Magic(14, "Dragon", 0x7038F8);
|
||||
dragon.setIconItem(new ItemStack(Blocks.dragon_egg)); // dragon egg
|
||||
|
||||
Magic dark = new Magic(15, "Dark", 0x705848);
|
||||
dark.setIconItem(new ItemStack(net.minecraft.init.Items.coal)); // coal for Dark
|
||||
|
||||
Magic steel = new Magic(16, "Steel", 0xB8B8D0);
|
||||
steel.setIconItem(new ItemStack(net.minecraft.init.Items.iron_ingot)); // iron ingot for Steel
|
||||
|
||||
Magic fairy = new Magic(17, "Fairy", 0xEE99AC);
|
||||
fairy.setIconItem(new ItemStack(net.minecraft.init.Items.sugar)); // sugar for Fairy
|
||||
|
||||
// Now set weaknesses (using a multiplier of 2.0f to indicate “double damage”).
|
||||
// The following is based on a common Pokémon type chart.
|
||||
normal.weaknesses.put(fighting.id, 2.0f);
|
||||
|
||||
fire.weaknesses.put(water.id, 2.0f);
|
||||
fire.weaknesses.put(ground.id, 2.0f);
|
||||
fire.weaknesses.put(rock.id, 2.0f);
|
||||
|
||||
water.weaknesses.put(electric.id, 2.0f);
|
||||
water.weaknesses.put(grass.id, 2.0f);
|
||||
|
||||
electric.weaknesses.put(ground.id, 2.0f);
|
||||
|
||||
grass.weaknesses.put(fire.id, 2.0f);
|
||||
grass.weaknesses.put(ice.id, 2.0f);
|
||||
grass.weaknesses.put(poison.id, 2.0f);
|
||||
grass.weaknesses.put(flying.id, 2.0f);
|
||||
grass.weaknesses.put(bug.id, 2.0f);
|
||||
|
||||
ice.weaknesses.put(fire.id, 2.0f);
|
||||
ice.weaknesses.put(fighting.id, 2.0f);
|
||||
ice.weaknesses.put(rock.id, 2.0f);
|
||||
ice.weaknesses.put(steel.id, 2.0f);
|
||||
|
||||
fighting.weaknesses.put(flying.id, 2.0f);
|
||||
fighting.weaknesses.put(psychic.id, 2.0f);
|
||||
fighting.weaknesses.put(fairy.id, 2.0f);
|
||||
|
||||
poison.weaknesses.put(ground.id, 2.0f);
|
||||
poison.weaknesses.put(psychic.id, 2.0f);
|
||||
|
||||
ground.weaknesses.put(water.id, 2.0f);
|
||||
ground.weaknesses.put(grass.id, 2.0f);
|
||||
ground.weaknesses.put(ice.id, 2.0f);
|
||||
|
||||
flying.weaknesses.put(electric.id, 2.0f);
|
||||
flying.weaknesses.put(ice.id, 2.0f);
|
||||
flying.weaknesses.put(rock.id, 2.0f);
|
||||
|
||||
psychic.weaknesses.put(bug.id, 2.0f);
|
||||
psychic.weaknesses.put(ghost.id, 2.0f);
|
||||
psychic.weaknesses.put(dark.id, 2.0f);
|
||||
|
||||
bug.weaknesses.put(fire.id, 2.0f);
|
||||
bug.weaknesses.put(flying.id, 2.0f);
|
||||
bug.weaknesses.put(rock.id, 2.0f);
|
||||
|
||||
rock.weaknesses.put(water.id, 2.0f);
|
||||
rock.weaknesses.put(grass.id, 2.0f);
|
||||
rock.weaknesses.put(fighting.id, 2.0f);
|
||||
rock.weaknesses.put(ground.id, 2.0f);
|
||||
rock.weaknesses.put(steel.id, 2.0f);
|
||||
|
||||
ghost.weaknesses.put(ghost.id, 2.0f);
|
||||
ghost.weaknesses.put(dark.id, 2.0f);
|
||||
|
||||
dragon.weaknesses.put(ice.id, 2.0f);
|
||||
dragon.weaknesses.put(dragon.id, 2.0f);
|
||||
dragon.weaknesses.put(fairy.id, 2.0f);
|
||||
|
||||
dark.weaknesses.put(fighting.id, 2.0f);
|
||||
dark.weaknesses.put(bug.id, 2.0f);
|
||||
dark.weaknesses.put(fairy.id, 2.0f);
|
||||
|
||||
steel.weaknesses.put(fire.id, 2.0f);
|
||||
steel.weaknesses.put(fighting.id, 2.0f);
|
||||
steel.weaknesses.put(ground.id, 2.0f);
|
||||
|
||||
fairy.weaknesses.put(poison.id, 2.0f);
|
||||
fairy.weaknesses.put(steel.id, 2.0f);
|
||||
|
||||
// Register the types.
|
||||
magics.put(normal.id, normal);
|
||||
magics.put(fire.id, fire);
|
||||
magics.put(water.id, water);
|
||||
magics.put(electric.id, electric);
|
||||
magics.put(grass.id, grass);
|
||||
magics.put(ice.id, ice);
|
||||
magics.put(fighting.id, fighting);
|
||||
magics.put(poison.id, poison);
|
||||
magics.put(ground.id, ground);
|
||||
magics.put(flying.id, flying);
|
||||
magics.put(psychic.id, psychic);
|
||||
magics.put(bug.id, bug);
|
||||
magics.put(rock.id, rock);
|
||||
magics.put(ghost.id, ghost);
|
||||
magics.put(dragon.id, dragon);
|
||||
magics.put(dark.id, dark);
|
||||
magics.put(steel.id, steel);
|
||||
magics.put(fairy.id, fairy);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
// Create default magics
|
||||
Magic earth = new Magic(0, "Earth", 0x00DD00, 1, 1);
|
||||
earth.setIconItem(new ItemStack(CustomItems.earthElement));
|
||||
|
||||
Magic water = new Magic(1, "Water", 0xF2DD00, 1, 2);
|
||||
water.setIconItem(new ItemStack(CustomItems.waterElement));
|
||||
|
||||
Magic fire = new Magic(2, "Fire", 0xDD0000, 1, 3);
|
||||
fire.setIconItem(new ItemStack(CustomItems.spellFire));
|
||||
|
||||
Magic air = new Magic(3, "Air", 0xDD0000, 1, 0);
|
||||
air.setIconItem(new ItemStack(CustomItems.airElement));
|
||||
|
||||
Magic dark = new Magic(4, "Dark", 0xDD0000, 0, 3);
|
||||
dark.setIconItem(new ItemStack(CustomItems.spellDark));
|
||||
|
||||
Magic holy = new Magic(5, "Holy", 0xDD0000, 0, 1);
|
||||
holy.setIconItem(new ItemStack(CustomItems.spellHoly));
|
||||
|
||||
Magic nature = new Magic(6, "Nature", 0xDD0000, 0, 0);
|
||||
nature.setIconItem(new ItemStack(CustomItems.spellNature));
|
||||
|
||||
Magic arcane = new Magic(7, "Arcane", 0xDD0000, 0, 2);
|
||||
arcane.setIconItem(new ItemStack(CustomItems.spellArcane));
|
||||
|
||||
// Insiders
|
||||
earth.weaknesses.put(air.id, 0.60f);
|
||||
water.weaknesses.put(earth.id, 0.60f);
|
||||
fire.weaknesses.put(water.id, 0.60f);
|
||||
air.weaknesses.put(fire.id, 0.60f);
|
||||
|
||||
// Outsiders
|
||||
dark.weaknesses.put(nature.id, 0.60f);
|
||||
nature.weaknesses.put(holy.id, 0.60f);
|
||||
holy.weaknesses.put(arcane.id, 0.60f);
|
||||
arcane.weaknesses.put(dark.id, 0.60f);
|
||||
|
||||
// Cross Interactions
|
||||
earth.weaknesses.put(nature.id, 0.30f);
|
||||
water.weaknesses.put(holy.id, 0.30f);
|
||||
fire.weaknesses.put(arcane.id, 0.30f);
|
||||
air.weaknesses.put(dark.id, 0.30f);
|
||||
dark.weaknesses.put(fire.id, 0.30f);
|
||||
nature.weaknesses.put(air.id, 0.30f);
|
||||
holy.weaknesses.put(earth.id, 0.30f);
|
||||
arcane.weaknesses.put(water.id, 0.30f);
|
||||
|
||||
// Add them to the registry
|
||||
magics.put(earth.id, earth);
|
||||
magics.put(water.id, water);
|
||||
magics.put(fire.id, fire);
|
||||
magics.put(air.id, air);
|
||||
magics.put(dark.id, dark);
|
||||
magics.put(holy.id, holy);
|
||||
magics.put(nature.id, nature);
|
||||
magics.put(arcane.id, arcane);
|
||||
}
|
||||
printAllMagicInteractions();
|
||||
}
|
||||
|
||||
private void loadMagicFile(File file) throws IOException {
|
||||
DataInputStream stream = new DataInputStream(
|
||||
new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))
|
||||
);
|
||||
loadMagic(stream);
|
||||
stream.close();
|
||||
}
|
||||
|
||||
public void loadMagic(DataInputStream stream) throws IOException {
|
||||
HashMap<Integer, Magic> magic = new HashMap<Integer, Magic>();
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.read(stream);
|
||||
lastUsedID = nbttagcompound1.getInteger("lastID");
|
||||
NBTTagList list = nbttagcompound1.getTagList("NPCMagic", 10); // using "NPCMagic" as tag
|
||||
|
||||
if (list != null) {
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
|
||||
Magic loadMagic = new Magic();
|
||||
loadMagic.readNBT(nbttagcompound);
|
||||
magic.put(loadMagic.id, loadMagic);
|
||||
}
|
||||
}
|
||||
this.magics = magic;
|
||||
}
|
||||
|
||||
public NBTTagCompound getNBT() {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (int slot : magics.keySet()) {
|
||||
Magic mag = magics.get(slot);
|
||||
NBTTagCompound nbtMagic = new NBTTagCompound();
|
||||
mag.writeNBT(nbtMagic);
|
||||
list.appendTag(nbtMagic);
|
||||
}
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setInteger("lastID", lastUsedID);
|
||||
nbttagcompound.setTag("NPCMagic", list); // use same tag as loadMagic
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void saveFactions() {
|
||||
try {
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
File file = new File(saveDir, "magic.dat_new");
|
||||
File file1 = new File(saveDir, "magic.dat_old");
|
||||
File file2 = new File(saveDir, "magic.dat");
|
||||
CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file));
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Magic get(int magicID) {
|
||||
return magics.get(magicID);
|
||||
}
|
||||
|
||||
public List<IMagic> list() {
|
||||
return new ArrayList<IMagic>(this.magics.values());
|
||||
}
|
||||
|
||||
public void saveMagic(Magic mag) {
|
||||
if (mag.id < 0) {
|
||||
mag.id = getUnusedId();
|
||||
while (hasName(mag.name))
|
||||
mag.name += "_";
|
||||
} else {
|
||||
Magic existing = magics.get(mag.id);
|
||||
if (existing != null && !existing.name.equals(mag.name))
|
||||
while (hasName(mag.name))
|
||||
mag.name += "_";
|
||||
}
|
||||
magics.remove(mag.id);
|
||||
magics.put(mag.id, mag);
|
||||
|
||||
NBTTagCompound facCompound = new NBTTagCompound();
|
||||
mag.writeNBT(facCompound);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.MAGIC, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
// Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.MAGIC, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
public int getUnusedId(){
|
||||
if(lastUsedID == 0){
|
||||
for(int catid : magics.keySet())
|
||||
if(catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
public int getUnusedId() {
|
||||
if (lastUsedID == 0) {
|
||||
for (int catid : magics.keySet())
|
||||
if (catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
|
||||
public boolean hasName(String newName) {
|
||||
if(newName.trim().isEmpty())
|
||||
return true;
|
||||
for(Magic mag : magics.values())
|
||||
if(mag.name.equals(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public boolean hasName(String newName) {
|
||||
if (newName.trim().isEmpty())
|
||||
return true;
|
||||
for (Magic mag : magics.values())
|
||||
if (mag.name.equals(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Magic getMagicFromName(String magicName){
|
||||
for (Map.Entry<Integer,Magic> entryMag: MagicController.getInstance().magics.entrySet()){
|
||||
if (entryMag.getValue().name.equalsIgnoreCase(magicName)){
|
||||
return entryMag.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Magic getMagicFromName(String magicName) {
|
||||
for (Map.Entry<Integer, Magic> entryMag : MagicController.getInstance().magics.entrySet()) {
|
||||
if (entryMag.getValue().name.equalsIgnoreCase(magicName)) {
|
||||
return entryMag.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
String[] names = new String[magics.size()];
|
||||
int i = 0;
|
||||
for(Magic mag : magics.values()){
|
||||
names[i] = mag.name.toLowerCase();
|
||||
i++;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
public String[] getNames() {
|
||||
String[] names = new String[magics.size()];
|
||||
int i = 0;
|
||||
for (Magic mag : magics.values()) {
|
||||
names[i] = mag.name.toLowerCase();
|
||||
i++;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
// --- New functions for applying magic NBT stats and calculating damage ---
|
||||
|
||||
/**
|
||||
* Applies magic-type damage to an item. A weapon/item can have multiple magic damage values.
|
||||
* The damage is stored under a compound tag "MagicDamage" where each key is the magic ID.
|
||||
*/
|
||||
public static void addMagicDamageToItem(ItemStack item, int magicId, float damage) {
|
||||
if (item == null) return;
|
||||
if (item.stackTagCompound == null)
|
||||
item.stackTagCompound = new NBTTagCompound();
|
||||
NBTTagCompound compound = item.stackTagCompound;
|
||||
NBTTagCompound magicDamage;
|
||||
if (compound.hasKey("MagicDamage")) {
|
||||
magicDamage = compound.getCompoundTag("MagicDamage");
|
||||
} else {
|
||||
magicDamage = new NBTTagCompound();
|
||||
}
|
||||
magicDamage.setFloat(String.valueOf(magicId), damage);
|
||||
compound.setTag("MagicDamage", magicDamage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies magic resistance to an armor piece.
|
||||
* The resistance is stored under a compound tag "MagicResistances" with the magic ID as key.
|
||||
*/
|
||||
public static void addMagicResistanceToArmor(ItemStack armor, int magicId, float resistance) {
|
||||
if (armor == null) return;
|
||||
if (armor.stackTagCompound == null)
|
||||
armor.stackTagCompound = new NBTTagCompound();
|
||||
NBTTagCompound compound = armor.stackTagCompound;
|
||||
NBTTagCompound magicResist;
|
||||
if (compound.hasKey("MagicResistances")) {
|
||||
magicResist = compound.getCompoundTag("MagicResistances");
|
||||
} else {
|
||||
magicResist = new NBTTagCompound();
|
||||
}
|
||||
magicResist.setFloat(String.valueOf(magicId), resistance);
|
||||
compound.setTag("MagicResistances", magicResist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a collection of armor pieces, sums the resistance value for the specified magic ID.
|
||||
*/
|
||||
public static float calculateTotalMagicResistance(int magicId, Iterable<ItemStack> armors) {
|
||||
float totalResistance = 0.0F;
|
||||
for (ItemStack armor : armors) {
|
||||
if (armor != null && armor.hasTagCompound() && armor.stackTagCompound.hasKey("MagicResistances")) {
|
||||
NBTTagCompound magicResist = armor.stackTagCompound.getCompoundTag("MagicResistances");
|
||||
if (magicResist.hasKey(String.valueOf(magicId))) {
|
||||
totalResistance += magicResist.getFloat(String.valueOf(magicId));
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalResistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the final magic damage after applying armor resistances.
|
||||
* For a given magic type, the resistance is applied.
|
||||
*
|
||||
* @param magicId the magic type
|
||||
* @param baseDamage the base damage value
|
||||
* @param armors an Iterable collection of armor ItemStacks
|
||||
* @return the final damage after reduction
|
||||
*/
|
||||
public static float calculateFinalMagicDamage(int magicId, float baseDamage, Iterable<ItemStack> armors) {
|
||||
if (getInstance().getMagic(magicId) == null) {
|
||||
// If the magic type is not defined, treat it as non-magical.
|
||||
return baseDamage;
|
||||
}
|
||||
float resistance = calculateTotalMagicResistance(magicId, armors);
|
||||
// Resistance is assumed to be a fractional reduction (e.g., 0.2 = 20% reduction).
|
||||
return baseDamage * (1.0F - resistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts magic damage values from a weapon ItemStack.
|
||||
* It looks for a compound tag "CNPCMagic" first; if not found, it falls back to "MagicDamage".
|
||||
* Returns a mapping of magic ID to its damage value.
|
||||
*/
|
||||
public static Map<Integer, Float> getMagicDamageFromItem(ItemStack item) {
|
||||
Map<Integer, Float> damageMap = new HashMap<Integer, Float>();
|
||||
if (item == null || item.stackTagCompound == null) return damageMap;
|
||||
NBTTagCompound compound = item.stackTagCompound;
|
||||
NBTTagCompound damageCompound = null;
|
||||
if (compound.hasKey("CNPCMagic")) {
|
||||
NBTTagCompound magicCompound = compound.getCompoundTag("CNPCMagic");
|
||||
if (magicCompound.hasKey("MagicDamage")) {
|
||||
damageCompound = magicCompound.getCompoundTag("MagicDamage");
|
||||
}
|
||||
} else if (compound.hasKey("MagicDamage")) {
|
||||
damageCompound = compound.getCompoundTag("MagicDamage");
|
||||
}
|
||||
if (damageCompound != null) {
|
||||
Set<String> keys = damageCompound.func_150296_c();
|
||||
for (String key : keys) {
|
||||
try {
|
||||
int magicId = Integer.parseInt(key);
|
||||
float dmg = damageCompound.getFloat(key);
|
||||
damageMap.put(magicId, dmg);
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignore non-integer keys.
|
||||
}
|
||||
}
|
||||
}
|
||||
return damageMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts magic resistances from an armor ItemStack.
|
||||
* It checks for a "CNPCMagic" container first; if not present, it falls back to "MagicResistances".
|
||||
* Returns a mapping of magic ID to its resistance value.
|
||||
*/
|
||||
public static Map<Integer, Float> getMagicResistancesFromItem(ItemStack item) {
|
||||
Map<Integer, Float> resistMap = new HashMap<Integer, Float>();
|
||||
if (item == null || item.stackTagCompound == null) return resistMap;
|
||||
NBTTagCompound compound = item.stackTagCompound;
|
||||
NBTTagCompound resistCompound = null;
|
||||
if (compound.hasKey("CNPCMagic")) {
|
||||
NBTTagCompound magicCompound = compound.getCompoundTag("CNPCMagic");
|
||||
if (magicCompound.hasKey("MagicResistances")) {
|
||||
resistCompound = magicCompound.getCompoundTag("MagicResistances");
|
||||
}
|
||||
} else if (compound.hasKey("MagicResistances")) {
|
||||
resistCompound = compound.getCompoundTag("MagicResistances");
|
||||
}
|
||||
if (resistCompound != null) {
|
||||
Set<String> keys = resistCompound.func_150296_c();
|
||||
for (String key : keys) {
|
||||
try {
|
||||
int magicId = Integer.parseInt(key);
|
||||
float res = resistCompound.getFloat(key);
|
||||
resistMap.put(magicId, res);
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignore non-integer keys.
|
||||
}
|
||||
}
|
||||
}
|
||||
return resistMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether an item (weapon or armor) contains any magic-related NBT.
|
||||
*/
|
||||
public static boolean hasMagicStats(ItemStack item) {
|
||||
if (item == null || item.stackTagCompound == null) return false;
|
||||
NBTTagCompound compound = item.stackTagCompound;
|
||||
return compound.hasKey("CNPCMagic") || compound.hasKey("MagicDamage") || compound.hasKey("MagicResistances");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a damage breakdown for each magic type from a weapon when applied against a set of armors.
|
||||
* This function will ignore any magic with ID 0 (neutral), so only magic damage is returned.
|
||||
* Returns a map where keys are magic IDs (non-zero) and values are the final damage for that type.
|
||||
*/
|
||||
public static Map<Integer, Float> calculateDamageBreakdown(ItemStack weapon, Iterable<ItemStack> armors) {
|
||||
Map<Integer, Float> breakdown = new HashMap<Integer, Float>();
|
||||
Map<Integer, Float> weaponDamage = getMagicDamageFromItem(weapon);
|
||||
for (Map.Entry<Integer, Float> entry : weaponDamage.entrySet()) {
|
||||
int magicId = entry.getKey();
|
||||
// Skip magic ID 0 (neutral)
|
||||
if (magicId == 0) continue;
|
||||
float dmg = entry.getValue();
|
||||
float finalDmg = calculateFinalMagicDamage(magicId, dmg, armors);
|
||||
breakdown.put(magicId, finalDmg);
|
||||
}
|
||||
return breakdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total final magic damage of a weapon after applying the resistances of a set of armor pieces.
|
||||
* This sums only the magic interactions (magic IDs other than 0).
|
||||
*/
|
||||
public static float calculateTotalDamage(ItemStack weapon, Iterable<ItemStack> armors) {
|
||||
float totalDamage = 0.0F;
|
||||
Map<Integer, Float> breakdown = calculateDamageBreakdown(weapon, armors);
|
||||
for (Float dmg : breakdown.values()) {
|
||||
totalDamage += dmg;
|
||||
}
|
||||
return totalDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints all magic interactions (weaknesses) in the registry.
|
||||
* For each magic (defender) that has weaknesses, prints the corresponding attacker and the extra damage percentage.
|
||||
* Format: "Magic ID: [attacker id], Name: "[attacker name]" does [percentage*100]% extra damage to Magic ID: [defender id], Name: "[defender name]".
|
||||
*/
|
||||
public static void printAllMagicInteractions() {
|
||||
MagicController mc = getInstance();
|
||||
for (Magic defender : mc.magics.values()) {
|
||||
for (Map.Entry<Integer, Float> entry : defender.weaknesses.entrySet()) {
|
||||
int attackerId = entry.getKey();
|
||||
float percentage = entry.getValue();
|
||||
Magic attacker = mc.getMagic(attackerId);
|
||||
if (attacker != null) {
|
||||
System.out.println("Magic ID: " + attacker.id + ", Name: \"" + attacker.name + "\" does "
|
||||
+ (percentage * 100) + "% extra damage to Magic ID: " + defender.id + ", Name: \"" + defender.name + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -8,8 +11,6 @@ import net.minecraft.nbt.NBTTagString;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.controllers.data.Party;
|
||||
@@ -24,7 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
import static noppes.npcs.PacketHandlerServer.sendInviteData;
|
||||
import static kamkeel.npcs.network.packets.request.party.PartyInvitePacket.sendInviteData;
|
||||
|
||||
public class PartyController {
|
||||
private static PartyController Instance;
|
||||
@@ -68,8 +69,8 @@ public class PartyController {
|
||||
playerData.partyUUID = null;
|
||||
if(player != null){
|
||||
sendInviteData((EntityPlayerMP) player);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.PARTY_MESSAGE, "party.disbandAlert");
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "\u00A7c", "party.disbandMessage", "!");
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) player, true, "party.disbandAlert", "");
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "\u00A7c", "party.disbandMessage", "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,14 +85,14 @@ public class PartyController {
|
||||
for(String name : party.getPlayerNames()){
|
||||
EntityPlayer playerMP = NoppesUtilServer.getPlayerByName(name);
|
||||
if(playerMP != null){
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.PARTY_MESSAGE, "party.kickOtherAlert", kickPlayerName);
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.CHAT, "\u00A7e", kickPlayerName, " \u00A74", "party.kickOtherChat", "!");
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerMP, true, "party.kickOtherAlert", kickPlayerName);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerMP, "\u00A7e", kickPlayerName, " \u00A74", "party.kickOtherChat", "!");
|
||||
}
|
||||
}
|
||||
|
||||
if(kickPlayer != null){
|
||||
Server.sendData((EntityPlayerMP) kickPlayer, EnumPacketClient.PARTY_MESSAGE, "party.kickYouAlert", "");
|
||||
Server.sendData((EntityPlayerMP) kickPlayer, EnumPacketClient.CHAT, "\u00A74", "party.kickYouChat", "!");
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) kickPlayer, true, "party.kickYouAlert", "");
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) kickPlayer, "\u00A74", "party.kickYouChat", "!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,12 +103,12 @@ public class PartyController {
|
||||
for(String name : party.getPlayerNames()){
|
||||
EntityPlayer playerMP = NoppesUtilServer.getPlayerByName(name);
|
||||
if(playerMP != null){
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.PARTY_MESSAGE, "party.leaveOtherAlert", leavingPlayer.getCommandSenderName());
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.CHAT, "\u00A7e", leavingPlayer.getCommandSenderName(), " \u00A7c", "party.leaveOtherChat", "!");
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) playerMP, true, "party.leaveOtherAlert", leavingPlayer.getCommandSenderName());
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerMP, "\u00A7e", leavingPlayer.getCommandSenderName(), " \u00A7c", "party.leaveOtherChat", "!");
|
||||
}
|
||||
}
|
||||
Server.sendData((EntityPlayerMP) leavingPlayer, EnumPacketClient.PARTY_MESSAGE, "party.leaveYouAlert", "");
|
||||
Server.sendData((EntityPlayerMP) leavingPlayer, EnumPacketClient.CHAT, "\u00A7c", "party.leaveYouChat", "!");
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) leavingPlayer, true, "party.leaveYouAlert", "");
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) leavingPlayer, "\u00A7c", "party.leaveYouChat", "!");
|
||||
}
|
||||
|
||||
public void pingPartyUpdate(Party party){
|
||||
@@ -134,7 +135,7 @@ public class PartyController {
|
||||
if(playerMP != null){
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(playerMP);
|
||||
if(playerData != null){
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.PARTY_DATA, compound);
|
||||
PartyDataPacket.sendPartyData((EntityPlayerMP) playerMP, compound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +166,7 @@ public class PartyController {
|
||||
if(playerMP != null){
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(playerMP);
|
||||
if(playerData != null){
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.PARTY_DATA, compound);
|
||||
PartyDataPacket.sendPartyData((EntityPlayerMP) playerMP, compound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,9 +184,7 @@ public class PartyController {
|
||||
|
||||
System.arraycopy(chatAlerts, 0, args, 1, chatAlerts.length);
|
||||
args[args.length - 1] = "!"; // Add "!" at the end
|
||||
|
||||
// Pass args to Server.sendData using spread operator
|
||||
Server.sendData((EntityPlayerMP) playerMP, EnumPacketClient.CHAT, args);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) playerMP, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
@@ -45,8 +45,8 @@ public class PlayerQuestController {
|
||||
|
||||
data.activeQuests.put(questData.quest.id,questData);
|
||||
if (questData.sendAlerts) {
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.newquest", questData.quest.title);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.newquest", ": ", questData.quest.title);
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) player, false, "quest.newquest", questData.quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "quest.newquest", ": ", questData.quest.title);
|
||||
}
|
||||
playerData.updateClient = true;
|
||||
} else {
|
||||
@@ -76,8 +76,8 @@ public class PlayerQuestController {
|
||||
}
|
||||
}
|
||||
if (questData != null && questData.sendAlerts) {
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.completed", questData.quest.title);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.completed", ": ", questData.quest.title);
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) player, false, "quest.completed", questData.quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "quest.completed", ": ", questData.quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
@@ -98,8 +98,8 @@ public class PlayerQuestController {
|
||||
}
|
||||
}
|
||||
if (questData != null && questData.sendAlerts) {
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.completed", questData.quest.title);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.completed", ": ", questData.quest.title);
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) player, false, "quest.completed", questData.quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "quest.completed", ": ", questData.quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IQuestHandler;
|
||||
import noppes.npcs.api.handler.data.IQuest;
|
||||
import noppes.npcs.api.handler.data.IQuestCategory;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
@@ -146,7 +145,7 @@ public class QuestController implements IQuestHandler {
|
||||
for(int dia : cat.quests.keySet())
|
||||
quests.remove(dia);
|
||||
categories.remove(category);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.QUEST_CATEGORY, category);
|
||||
SyncController.syncRemove(EnumSyncType.QUEST_CATEGORY, category);
|
||||
}
|
||||
|
||||
public void saveCategory(QuestCategory category){
|
||||
@@ -177,7 +176,7 @@ public class QuestController implements IQuestHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
SyncController.updateQuestCat(category);
|
||||
SyncController.syncUpdate(EnumSyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category));
|
||||
}
|
||||
private boolean containsCategoryName(String name) {
|
||||
name = name.toLowerCase();
|
||||
@@ -225,7 +224,7 @@ public class QuestController implements IQuestHandler {
|
||||
if(file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST, quest.writeToNBT(new NBTTagCompound()), category.id);
|
||||
SyncController.syncUpdate(EnumSyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
@@ -8,7 +9,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.api.handler.IRecipeHandler;
|
||||
import noppes.npcs.api.handler.data.IAnvilRecipe;
|
||||
import noppes.npcs.api.handler.data.IRecipe;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
import noppes.npcs.controllers.data.RecipesDefault;
|
||||
|
||||
@@ -20,14 +23,19 @@ import java.util.*;
|
||||
|
||||
public class RecipeController implements IRecipeHandler {
|
||||
private static Collection<RecipeCarpentry> prevRecipes;
|
||||
public HashMap<Integer,RecipeCarpentry> globalRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public HashMap<Integer,RecipeCarpentry> anvilRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public static RecipeController Instance;
|
||||
|
||||
public HashMap<Integer, RecipeCarpentry> globalRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public HashMap<Integer, RecipeCarpentry> carpentryRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public HashMap<Integer, RecipeAnvil> anvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
||||
|
||||
public static RecipeController Instance;
|
||||
|
||||
public static final int version = 1;
|
||||
public int nextId = 1;
|
||||
public int nextAnvilId = 1;
|
||||
|
||||
public static HashMap<Integer,RecipeCarpentry> syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public static HashMap<Integer, RecipeCarpentry> syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
public static HashMap<Integer, RecipeAnvil> syncAnvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
||||
|
||||
public RecipeController(){
|
||||
Instance = this;
|
||||
@@ -36,6 +44,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
loadCategories();
|
||||
reloadGlobalRecipes(globalRecipes);
|
||||
}
|
||||
|
||||
public static void reloadGlobalRecipes(HashMap<Integer,RecipeCarpentry> globalRecipes){
|
||||
List list = CraftingManager.getInstance().getRecipeList();
|
||||
if(prevRecipes != null){
|
||||
@@ -59,7 +68,8 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
else{
|
||||
globalRecipes.clear();
|
||||
anvilRecipes.clear();
|
||||
carpentryRecipes.clear();
|
||||
anvilRecipes.clear();
|
||||
loadDefaultRecipes(-1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -84,23 +94,34 @@ public class RecipeController implements IRecipeHandler {
|
||||
private void loadCategories(File file) throws Exception{
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
nextId = nbttagcompound1.getInteger("LastId");
|
||||
nextAnvilId = nbttagcompound1.getInteger("LastAnvilId");
|
||||
NBTTagList list = nbttagcompound1.getTagList("Data", 10);
|
||||
HashMap<Integer,RecipeCarpentry> globalRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
HashMap<Integer,RecipeCarpentry> anvilRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
HashMap<Integer,RecipeCarpentry> carpentryRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
HashMap<Integer,RecipeAnvil> anvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
||||
if(list != null){
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
|
||||
if(recipe.isGlobal)
|
||||
globalRecipes.put(recipe.id,recipe);
|
||||
else
|
||||
anvilRecipes.put(recipe.id,recipe);
|
||||
if(recipe.id > nextId)
|
||||
nextId = recipe.id;
|
||||
NBTTagCompound compound = list.getCompoundTagAt(i);
|
||||
if(compound.hasKey("IsAnvil")){
|
||||
RecipeAnvil anvil = RecipeAnvil.read(compound);
|
||||
anvilRecipes.put(anvil.id, anvil);
|
||||
if(anvil.id > nextAnvilId)
|
||||
nextAnvilId = anvil.id;
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
if(recipe.isGlobal)
|
||||
globalRecipes.put(recipe.id,recipe);
|
||||
else
|
||||
carpentryRecipes.put(recipe.id,recipe);
|
||||
if(recipe.id > nextId)
|
||||
nextId = recipe.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.anvilRecipes = anvilRecipes;
|
||||
this.carpentryRecipes = carpentryRecipes;
|
||||
this.globalRecipes = globalRecipes;
|
||||
this.anvilRecipes = anvilRecipes;
|
||||
loadDefaultRecipes(nbttagcompound1.getInteger("Version"));
|
||||
}
|
||||
private void saveCategories(){
|
||||
@@ -110,12 +131,16 @@ public class RecipeController implements IRecipeHandler {
|
||||
for(RecipeCarpentry recipe : globalRecipes.values()){
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
for(RecipeCarpentry recipe : anvilRecipes.values()){
|
||||
for(RecipeCarpentry recipe : carpentryRecipes.values()){
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
for(RecipeAnvil recipe : anvilRecipes.values()){
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setTag("Data", list);
|
||||
nbttagcompound.setInteger("LastId", nextId);
|
||||
nbttagcompound.setInteger("LastAnvilId", nextAnvilId);
|
||||
nbttagcompound.setInteger("Version", version);
|
||||
File file = new File(saveDir, "recipes.dat_new");
|
||||
File file1 = new File(saveDir, "recipes.dat_old");
|
||||
@@ -141,7 +166,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
|
||||
public RecipeCarpentry findMatchingRecipe(InventoryCrafting par1InventoryCrafting){
|
||||
for(RecipeCarpentry recipe : anvilRecipes.values()){
|
||||
for(RecipeCarpentry recipe : carpentryRecipes.values()){
|
||||
if(recipe.isValid() && recipe.matches(par1InventoryCrafting,null))
|
||||
return recipe;
|
||||
}
|
||||
@@ -151,11 +176,17 @@ public class RecipeController implements IRecipeHandler {
|
||||
public RecipeCarpentry getRecipe(int id) {
|
||||
if(globalRecipes.containsKey(id))
|
||||
return globalRecipes.get(id);
|
||||
if(anvilRecipes.containsKey(id))
|
||||
return anvilRecipes.get(id);
|
||||
if(carpentryRecipes.containsKey(id))
|
||||
return carpentryRecipes.get(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
public RecipeAnvil getAnvilRecipe(int id) {
|
||||
if(anvilRecipes.containsKey(id))
|
||||
return anvilRecipes.get(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
public RecipeCarpentry saveRecipe(NBTTagCompound compound) throws IOException {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
|
||||
@@ -171,61 +202,130 @@ public class RecipeController implements IRecipeHandler {
|
||||
recipe.name += "_";
|
||||
}
|
||||
if(recipe.isGlobal){
|
||||
anvilRecipes.remove(recipe.id);
|
||||
carpentryRecipes.remove(recipe.id);
|
||||
globalRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
else{
|
||||
globalRecipes.remove(recipe.id);
|
||||
anvilRecipes.put(recipe.id, recipe);
|
||||
carpentryRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
saveCategories();
|
||||
reloadGlobalRecipes(globalRecipes);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public RecipeAnvil saveAnvilRecipe(NBTTagCompound compound) throws IOException {
|
||||
RecipeAnvil recipe = RecipeAnvil.read(compound);
|
||||
|
||||
RecipeAnvil current = getAnvilRecipe(recipe.id);
|
||||
if(current != null && !current.name.equals(recipe.name)){
|
||||
while(containsAnvilRecipeName(recipe.name))
|
||||
recipe.name += "_";
|
||||
}
|
||||
|
||||
if(recipe.id == -1){
|
||||
recipe.id = getUniqueAnvilId();
|
||||
while(containsAnvilRecipeName(recipe.name))
|
||||
recipe.name += "_";
|
||||
}
|
||||
|
||||
anvilRecipes.put(recipe.id, recipe);
|
||||
saveCategories();
|
||||
return recipe;
|
||||
}
|
||||
|
||||
private int getUniqueId() {
|
||||
return nextId++;
|
||||
}
|
||||
|
||||
private int getUniqueAnvilId() {
|
||||
return nextAnvilId++;
|
||||
}
|
||||
|
||||
private boolean containsRecipeName(String name) {
|
||||
name = name.toLowerCase();
|
||||
for(RecipeCarpentry recipe : globalRecipes.values()){
|
||||
if(recipe.name.toLowerCase().equals(name))
|
||||
return true;
|
||||
}
|
||||
for(RecipeCarpentry recipe : anvilRecipes.values()){
|
||||
for(RecipeCarpentry recipe : carpentryRecipes.values()){
|
||||
if(recipe.name.toLowerCase().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean containsAnvilRecipeName(String name) {
|
||||
name = name.toLowerCase();
|
||||
for(RecipeAnvil recipe : anvilRecipes.values()){
|
||||
if(recipe.name.toLowerCase().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public RecipeCarpentry delete(int id) {
|
||||
RecipeCarpentry recipe = getRecipe(id);
|
||||
if(recipe == null)
|
||||
return null;
|
||||
globalRecipes.remove(recipe.id);
|
||||
anvilRecipes.remove(recipe.id);
|
||||
RecipeCarpentry globalRecipe = globalRecipes.remove(recipe.id);
|
||||
if(globalRecipe != null)
|
||||
SyncController.syncAllWorkbenchRecipes();
|
||||
|
||||
RecipeCarpentry carpentry = carpentryRecipes.remove(recipe.id);
|
||||
if(carpentry != null)
|
||||
SyncController.syncAllCarpentryRecipes();
|
||||
|
||||
saveCategories();
|
||||
reloadGlobalRecipes(globalRecipes);
|
||||
return recipe;
|
||||
}
|
||||
public void addRecipe(RecipeCarpentry recipeAnvil) {
|
||||
recipeAnvil.id = getUniqueId();
|
||||
if(!recipeAnvil.isGlobal)
|
||||
RecipeController.Instance.anvilRecipes.put(recipeAnvil.id, recipeAnvil);
|
||||
|
||||
public RecipeAnvil deleteAnvil(int id) {
|
||||
RecipeAnvil recipe = getAnvilRecipe(id);
|
||||
if(recipe == null)
|
||||
return null;
|
||||
|
||||
RecipeAnvil anvilRecipe = anvilRecipes.remove(recipe.id);
|
||||
if(anvilRecipe != null)
|
||||
SyncController.syncAllAnvilRecipes();
|
||||
|
||||
saveCategories();
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public void addRecipe(RecipeCarpentry recipeCarpentry) {
|
||||
recipeCarpentry.id = getUniqueId();
|
||||
if(!recipeCarpentry.isGlobal)
|
||||
RecipeController.Instance.carpentryRecipes.put(recipeCarpentry.id, recipeCarpentry);
|
||||
else{
|
||||
RecipeController.Instance.globalRecipes.put(recipeAnvil.id, recipeAnvil);
|
||||
RecipeController.Instance.globalRecipes.put(recipeCarpentry.id, recipeCarpentry);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAnvilRecipe(RecipeAnvil recipeAnvil) {
|
||||
recipeAnvil.id = getUniqueAnvilId();
|
||||
anvilRecipes.put(recipeAnvil.id, recipeAnvil);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IRecipe> getGlobalList() {
|
||||
return new ArrayList(this.globalRecipes.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IRecipe> getCarpentryList() {
|
||||
return new ArrayList(this.anvilRecipes.values());
|
||||
return new ArrayList(this.carpentryRecipes.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IAnvilRecipe> getAnvilList() {
|
||||
List<IAnvilRecipe> list = new ArrayList<>();
|
||||
list.addAll(anvilRecipes.values());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(String name, boolean global, ItemStack result, Object... objects) {
|
||||
RecipeCarpentry recipe = new RecipeCarpentry(name);
|
||||
recipe.isGlobal = global;
|
||||
@@ -238,6 +338,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(String name, boolean global, ItemStack result, int width, int height, ItemStack... objects) {
|
||||
ArrayList<ItemStack> list = new ArrayList<>();
|
||||
int var9 = objects.length;
|
||||
@@ -259,4 +360,14 @@ public class RecipeController implements IRecipeHandler {
|
||||
var12.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnvilRecipe(String name, boolean global, ItemStack itemToRepair, ItemStack repairMaterial, int xpCost, float repairPercentage) {
|
||||
RecipeAnvil recipe = new RecipeAnvil(name, itemToRepair, repairMaterial, xpCost, repairPercentage);
|
||||
try {
|
||||
this.saveAnvilRecipe(recipe.writeNBT());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class ScriptContainer {
|
||||
var14.printStackTrace(pw);
|
||||
} finally {
|
||||
String errorString = sw.getBuffer().toString().trim();
|
||||
this.appandConsole(errorString);
|
||||
this.appendConsole(errorString);
|
||||
pw.close();
|
||||
}
|
||||
}
|
||||
@@ -201,14 +201,14 @@ public class ScriptContainer {
|
||||
e.printStackTrace(pw);
|
||||
}
|
||||
finally {
|
||||
appandConsole(sw.getBuffer().toString().trim());
|
||||
appendConsole(sw.getBuffer().toString().trim());
|
||||
pw.close();
|
||||
Current = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void appandConsole(String message) {
|
||||
public void appendConsole(String message) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (this.console.containsKey(time)) {
|
||||
|
||||
@@ -1,346 +0,0 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.addon.DBCAddon;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SyncController {
|
||||
|
||||
public static void syncPlayer(EntityPlayerMP player){
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Faction Sync
|
||||
for(Faction faction : FactionController.getInstance().factions.values()){
|
||||
NBTTagCompound factioNBT = new NBTTagCompound();
|
||||
faction.writeNBT(factioNBT);
|
||||
list.appendTag(factioNBT);
|
||||
if(list.tagCount() > 10){
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.FACTION, compound);
|
||||
list = new NBTTagList();
|
||||
}
|
||||
}
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.FACTION, compound);
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Quest Sync
|
||||
for(QuestCategory category : QuestController.Instance.categories.values()){
|
||||
NBTTagCompound questCompound;
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for(int questID : category.quests.keySet()){
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
if(questList.tagCount() > 20){
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
|
||||
questList = new NBTTagList();
|
||||
}
|
||||
}
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
|
||||
}
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Dialog Sync
|
||||
for(DialogCategory category : DialogController.Instance.categories.values()){
|
||||
NBTTagCompound dialogCompound;
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for(int dialogID : category.dialogs.keySet()){
|
||||
Dialog dialog = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
if(dialogList.tagCount() > 20){
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
|
||||
dialogList = new NBTTagList();
|
||||
}
|
||||
}
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
|
||||
}
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DBCAddon.instance.syncPlayer(player);
|
||||
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if(data != null){
|
||||
NoppesUtilServer.sendPlayerDataCompound(player, data.getSyncNBTFull(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncAllDialogs() {
|
||||
for(DialogCategory category : DialogController.Instance.categories.values()){
|
||||
NBTTagCompound dialogCompound;
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for(int dialogID : category.dialogs.keySet()){
|
||||
Dialog dialog = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
if(dialogList.tagCount() > 20){
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
|
||||
dialogList = new NBTTagList();
|
||||
}
|
||||
}
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
|
||||
}
|
||||
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
|
||||
}
|
||||
|
||||
public static void syncAllQuests() {
|
||||
for(QuestCategory category : QuestController.Instance.categories.values()){
|
||||
NBTTagCompound questCompound;
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for(int questID : category.quests.keySet()){
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
if(questList.tagCount() > 20){
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
|
||||
questList = new NBTTagList();
|
||||
}
|
||||
}
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
|
||||
}
|
||||
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
|
||||
}
|
||||
|
||||
public static void updateQuestCat(QuestCategory questCategory) {
|
||||
NBTTagCompound questCompound;
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for(int questID : questCategory.quests.keySet()){
|
||||
Quest quest = questCategory.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
if(questList.tagCount() > 20){
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, questCompound);
|
||||
questList = new NBTTagList();
|
||||
}
|
||||
}
|
||||
questCompound = new NBTTagCompound();
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, questCompound);
|
||||
}
|
||||
|
||||
public static void updateDialogCat(DialogCategory dialogCategory) {
|
||||
NBTTagCompound dialogCompound;
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for(int questID : dialogCategory.dialogs.keySet()){
|
||||
Dialog dialog = dialogCategory.dialogs.get(questID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
if(dialogList.tagCount() > 20){
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, dialogCompound);
|
||||
dialogList = new NBTTagList();
|
||||
}
|
||||
}
|
||||
dialogCompound = new NBTTagCompound();
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, dialogCompound);
|
||||
}
|
||||
|
||||
public static void clientSync(int synctype, NBTTagCompound compound, boolean syncEnd) {
|
||||
if(synctype == SyncType.FACTION){
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(list.getCompoundTagAt(i));
|
||||
FactionController.getInstance().factionsSync.put(faction.id, faction);
|
||||
}
|
||||
if(syncEnd){
|
||||
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
|
||||
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.QUEST_CATEGORY){
|
||||
if(!compound.hasNoTags()){
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(list.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
if(syncEnd){
|
||||
HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
|
||||
for(QuestCategory category : QuestController.Instance.categoriesSync.values()){
|
||||
for(Quest quest : category.quests.values()){
|
||||
quests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
|
||||
QuestController.Instance.quests = quests;
|
||||
QuestController.Instance.categoriesSync = new HashMap<Integer, QuestCategory>();
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG_CATEGORY){
|
||||
if(!compound.hasNoTags()){
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(list.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
if(syncEnd){
|
||||
HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
|
||||
for(DialogCategory category : DialogController.Instance.categoriesSync.values()){
|
||||
for(Dialog dialog : category.dialogs.values()){
|
||||
dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
}
|
||||
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
|
||||
DialogController.Instance.dialogs = dialogs;
|
||||
DialogController.Instance.categoriesSync = new HashMap<Integer, DialogCategory>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void clientSyncUpdate(int synctype, NBTTagCompound compound, ByteBuf buffer) {
|
||||
if(synctype == SyncType.FACTION){
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(compound);
|
||||
FactionController.getInstance().factions.put(faction.id, faction);
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG){
|
||||
DialogCategory category = DialogController.Instance.categories.get(buffer.readInt());
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.category = category;
|
||||
dialog.readNBT(compound);
|
||||
DialogController.Instance.dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG_CATEGORY){
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(list.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
else if(synctype == SyncType.QUEST){
|
||||
QuestCategory category = QuestController.Instance.categories.get(buffer.readInt());
|
||||
Quest quest = new Quest();
|
||||
quest.category = category;
|
||||
quest.readNBT(compound);
|
||||
QuestController.Instance.quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
else if(synctype == SyncType.QUEST_CATEGORY){
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(list.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clientSyncRemove(int synctype, int id) {
|
||||
if(synctype == SyncType.FACTION){
|
||||
FactionController.getInstance().factions.remove(id);
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG){
|
||||
Dialog dialog = DialogController.Instance.dialogs.remove(id);
|
||||
if(dialog != null) {
|
||||
dialog.category.dialogs.remove(id);
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG_CATEGORY){
|
||||
DialogCategory category = DialogController.Instance.categories.remove(id);
|
||||
if(category != null) {
|
||||
DialogController.Instance.dialogs.keySet().removeAll(category.dialogs.keySet());
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.QUEST){
|
||||
Quest quest = QuestController.Instance.quests.remove(id);
|
||||
if(quest != null) {
|
||||
quest.category.quests.remove(id);
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.QUEST_CATEGORY){
|
||||
QuestCategory category = QuestController.Instance.categories.remove(id);
|
||||
if(category != null) {
|
||||
QuestController.Instance.quests.keySet().removeAll(category.quests.keySet());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.UpdateAnimationsPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -18,7 +20,6 @@ import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IAnimationData;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
@@ -228,7 +229,7 @@ public class AnimationData implements IAnimationData {
|
||||
data.setInteger("EntityId", entity.getEntityId());
|
||||
}
|
||||
|
||||
Server.sendData((EntityPlayerMP) ((PlayerData) parent).player, EnumPacketClient.UPDATE_ANIMATIONS, data, entity.getCommandSenderName());
|
||||
PacketHandler.Instance.sendToPlayer(new UpdateAnimationsPacket(data, entity.getCommandSenderName()), (EntityPlayerMP) ((PlayerData) parent).player);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.ICompatibilty;
|
||||
import noppes.npcs.VersionCompatibility;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
@@ -13,6 +16,9 @@ import noppes.npcs.controllers.PlayerQuestController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Availability implements ICompatibilty, IAvailability {
|
||||
public int version = VersionCompatibility.ModRev;
|
||||
|
||||
@@ -124,6 +130,31 @@ public class Availability implements ICompatibilty, IAvailability {
|
||||
compound.setInteger("AvailabilityMinPlayerLevel", minPlayerLevel);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return dialogAvailable == EnumAvailabilityDialog.Always &&
|
||||
dialog2Available == EnumAvailabilityDialog.Always &&
|
||||
dialog3Available == EnumAvailabilityDialog.Always &&
|
||||
dialog4Available == EnumAvailabilityDialog.Always &&
|
||||
dialogId == -1 &&
|
||||
|
||||
questAvailable == EnumAvailabilityQuest.Always &&
|
||||
quest2Available == EnumAvailabilityQuest.Always &&
|
||||
quest3Available == EnumAvailabilityQuest.Always &&
|
||||
quest4Available == EnumAvailabilityQuest.Always &&
|
||||
questId == -1 &&
|
||||
|
||||
factionAvailable == EnumAvailabilityFactionType.Always &&
|
||||
faction2Available == EnumAvailabilityFactionType.Always &&
|
||||
factionId == -1 &&
|
||||
faction2Id == -1 &&
|
||||
factionStance == EnumAvailabilityFaction.Friendly &&
|
||||
faction2Stance == EnumAvailabilityFaction.Friendly &&
|
||||
|
||||
daytime == EnumDayTime.Always &&
|
||||
minPlayerLevel == 0;
|
||||
}
|
||||
|
||||
public void setFactionAvailability(int value) {
|
||||
factionAvailable = EnumAvailabilityFactionType.values()[value];
|
||||
}
|
||||
@@ -177,6 +208,64 @@ public class Availability implements ICompatibilty, IAvailability {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<String> isAvailableText(EntityPlayer player) {
|
||||
List<String> errors = new ArrayList<String>();
|
||||
|
||||
// Check daytime conditions.
|
||||
if (daytime == EnumDayTime.Day) {
|
||||
long time = player.worldObj.getWorldTime() % 24000;
|
||||
if (time > 12000) {
|
||||
errors.add(StatCollector.translateToLocal("availability.error.day"));
|
||||
}
|
||||
} else if (daytime == EnumDayTime.Night) {
|
||||
long time = player.worldObj.getWorldTime() % 24000;
|
||||
if (time < 12000) {
|
||||
errors.add(StatCollector.translateToLocal("availability.error.night"));
|
||||
}
|
||||
}
|
||||
|
||||
// Check dialog conditions.
|
||||
if (!dialogAvailable(dialogId, dialogAvailable, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialogAvailable.toString(), dialogId));
|
||||
}
|
||||
if (!dialogAvailable(dialog2Id, dialog2Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog2Available.toString(), dialog2Id));
|
||||
}
|
||||
if (!dialogAvailable(dialog3Id, dialog3Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog3Available.toString(), dialog3Id));
|
||||
}
|
||||
if (!dialogAvailable(dialog4Id, dialog4Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.dialog", dialog4Available.toString(), dialog4Id));
|
||||
}
|
||||
|
||||
// Check quest conditions.
|
||||
if (!questAvailable(questId, questAvailable, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", questAvailable.toString(), questId));
|
||||
}
|
||||
if (!questAvailable(quest2Id, quest2Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest2Available.toString(), quest2Id));
|
||||
}
|
||||
if (!questAvailable(quest3Id, quest3Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest3Available.toString(), quest3Id));
|
||||
}
|
||||
if (!questAvailable(quest4Id, quest4Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.quest", quest4Available.toString(), quest4Id));
|
||||
}
|
||||
|
||||
// Check faction conditions.
|
||||
if (!factionAvailable(factionId, factionStance, factionAvailable, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.faction", factionAvailable.toString(), factionStance.toString(), factionId));
|
||||
}
|
||||
if (!factionAvailable(faction2Id, faction2Stance, faction2Available, player)) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.faction", faction2Available.toString(), faction2Stance.toString(), faction2Id));
|
||||
}
|
||||
if (player.experienceLevel < minPlayerLevel) {
|
||||
errors.add(StatCollector.translateToLocalFormatted("availability.error.xp", minPlayerLevel));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
private boolean factionAvailable(int id, EnumAvailabilityFaction stance, EnumAvailabilityFactionType available, EntityPlayer player) {
|
||||
if(available == EnumAvailabilityFactionType.Always)
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -9,9 +10,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.NpcMiscInventory;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.containers.ContainerNPCBankInterface;
|
||||
import noppes.npcs.controllers.BankController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -108,7 +107,8 @@ public class BankData {
|
||||
if (container != null)
|
||||
container.setCurrency(item);
|
||||
}
|
||||
Server.sendDataChecked((EntityPlayerMP) player, EnumPacketClient.GUI_DATA, compound);
|
||||
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
private ContainerNPCBankInterface getContainer(EntityPlayer player){
|
||||
Container con = player.openContainer;
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
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.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.ICustomEffect;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.scripted.event.PlayerEvent;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CustomEffect implements ICustomEffect {
|
||||
public int id = -1;
|
||||
|
||||
public String name = "";
|
||||
public boolean lossOnDeath = true;
|
||||
public int length = 30;
|
||||
|
||||
// Must be a multiple of 10
|
||||
public int everyXTick = 20;
|
||||
|
||||
public String icon = "";
|
||||
// CustomNpcPlusDBC.ID + ":textures/gui/icons.png";
|
||||
public int iconX = 0, iconY = 0;
|
||||
|
||||
/**
|
||||
* Experimental script stuff.
|
||||
*/
|
||||
public Consumer<PlayerEvent.EffectEvent.Added> onAddedConsumer;
|
||||
public Consumer<PlayerEvent.EffectEvent.Ticked> onTickConsumer;
|
||||
public Consumer<PlayerEvent.EffectEvent.Removed> onRemovedConsumer;
|
||||
public String menuName = "§aNEW EFFECT";
|
||||
public int width = 16, height = 16;
|
||||
|
||||
public int index = 0;
|
||||
|
||||
public CustomEffect() {}
|
||||
|
||||
public CustomEffect(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public CustomEffect(int id, String name) {
|
||||
this(id);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMenuName(String name) {
|
||||
if (name != null && !name.isEmpty())
|
||||
this.menuName = name.replaceAll("&", "§");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMenuName() {
|
||||
return menuName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
if (name != null && !name.isEmpty())
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIcon(String icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEveryXTick() {
|
||||
return everyXTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEveryXTick(int everyXTick) {
|
||||
if (everyXTick < 10)
|
||||
everyXTick = 10;
|
||||
int remainder = everyXTick % 10;
|
||||
if (remainder >= 5)
|
||||
everyXTick += 10 - remainder;
|
||||
else
|
||||
everyXTick -= remainder;
|
||||
this.everyXTick = everyXTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconX() {
|
||||
return iconX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconX(int iconX) {
|
||||
this.iconX = iconX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconY() {
|
||||
return iconY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconY(int iconY) {
|
||||
this.iconY = iconY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLossOnDeath() {
|
||||
return lossOnDeath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLossOnDeath(boolean lossOnDeath) {
|
||||
this.lossOnDeath = lossOnDeath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomEffect save() {
|
||||
return CustomEffectController.getInstance().saveEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
|
||||
public void onAdded(Consumer<PlayerEvent.EffectEvent.Added> function) {
|
||||
onAddedConsumer = function;
|
||||
}
|
||||
|
||||
public void onTick(Consumer<PlayerEvent.EffectEvent.Ticked> function) {
|
||||
onTickConsumer = function;
|
||||
}
|
||||
|
||||
public void onRemoved(Consumer<PlayerEvent.EffectEvent.Removed> function) {
|
||||
onRemovedConsumer = function;
|
||||
}
|
||||
|
||||
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
if (onAddedConsumer != null) onAddedConsumer.accept(event);
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnAdd, event);
|
||||
}
|
||||
|
||||
public void onTick(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnTick, event);
|
||||
}
|
||||
|
||||
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 (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnRemove, event);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(boolean saveScripts) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("ID", id);
|
||||
compound.setString("name", name);
|
||||
compound.setString("menuName", menuName);
|
||||
compound.setInteger("length", length);
|
||||
compound.setInteger("everyXTick", everyXTick);
|
||||
compound.setInteger("iconX", iconX);
|
||||
compound.setInteger("iconY", iconY);
|
||||
compound.setInteger("iconWidth", width);
|
||||
compound.setInteger("iconHeight", height);
|
||||
compound.setString("icon", icon);
|
||||
compound.setBoolean("lossOnDeath", lossOnDeath);
|
||||
|
||||
// if (saveScripts && scriptContainer != null) {
|
||||
if (saveScripts) {
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
EffectScript handler = getScriptHandler();
|
||||
if (handler != null)
|
||||
handler.writeToNBT(scriptData);
|
||||
compound.setTag("ScriptData", scriptData);
|
||||
}
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("ID"))
|
||||
id = compound.getInteger("ID");
|
||||
else
|
||||
id = CustomEffectController.Instance.getUnusedId();
|
||||
name = compound.getString("name");
|
||||
|
||||
if (compound.hasKey("menuName", Constants.NBT.TAG_STRING))
|
||||
menuName = compound.getString("menuName");
|
||||
else
|
||||
menuName = name;
|
||||
|
||||
length = compound.getInteger("length");
|
||||
everyXTick = compound.getInteger("everyXTick");
|
||||
iconX = compound.getInteger("iconX");
|
||||
iconY = compound.getInteger("iconY");
|
||||
|
||||
if (compound.hasKey("iconWidth", Constants.NBT.TAG_INT))
|
||||
width = compound.getInteger("iconWidth");
|
||||
else
|
||||
width = 16;
|
||||
|
||||
if (compound.hasKey("iconHeight", Constants.NBT.TAG_INT))
|
||||
height = compound.getInteger("iconHeight");
|
||||
else
|
||||
height = 16;
|
||||
|
||||
icon = compound.getString("icon");
|
||||
lossOnDeath = compound.getBoolean("lossOnDeath");
|
||||
|
||||
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
|
||||
EffectScript handler = new EffectScript();
|
||||
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
|
||||
setScriptHandler(handler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CustomEffect cloneEffect() {
|
||||
CustomEffect newEffect = new CustomEffect();
|
||||
newEffect.readFromNBT(this.writeToNBT(true));
|
||||
newEffect.id = -1;
|
||||
return newEffect;
|
||||
}
|
||||
|
||||
public EffectScript getScriptHandler() {
|
||||
return CustomEffectController.getInstance().customEffectScriptHandlers.get(this.id);
|
||||
}
|
||||
public void setScriptHandler(EffectScript handler) {
|
||||
CustomEffectController.getInstance().customEffectScriptHandlers.put(this.id, handler);
|
||||
}
|
||||
|
||||
public EffectScript getOrCreateScriptHandler() {
|
||||
EffectScript data = getScriptHandler();
|
||||
if (data == null)
|
||||
setScriptHandler(data =new EffectScript());
|
||||
return data;
|
||||
}
|
||||
|
||||
public void runEffect(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
if (player.ticksExisted % everyXTick == 0) {
|
||||
onTick(player, playerEffect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@ public class DataTransform {
|
||||
public NBTTagCompound stats;
|
||||
public NBTTagCompound role;
|
||||
public NBTTagCompound job;
|
||||
|
||||
|
||||
public boolean hasDisplay, hasAi, hasAdvanced, hasInv, hasStats, hasRole, hasJob, isActive;
|
||||
|
||||
|
||||
private EntityNPCInterface npc;
|
||||
|
||||
|
||||
public boolean editingModus = false;
|
||||
|
||||
|
||||
public DataTransform(EntityNPCInterface npc){
|
||||
this.npc = npc;
|
||||
}
|
||||
@@ -47,11 +47,11 @@ public class DataTransform {
|
||||
compound.setTag("TransformRole", role);
|
||||
if(hasJob)
|
||||
compound.setTag("TransformJob", job);
|
||||
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public Object writeOptions(NBTTagCompound compound) {
|
||||
|
||||
public NBTTagCompound writeOptions(NBTTagCompound compound) {
|
||||
compound.setBoolean("TransformHasDisplay", hasDisplay);
|
||||
compound.setBoolean("TransformHasAI", hasAi);
|
||||
compound.setBoolean("TransformHasAdvanced", hasAdvanced);
|
||||
@@ -62,20 +62,20 @@ public class DataTransform {
|
||||
compound.setBoolean("TransformEditingModus", editingModus);
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void readToNBT(NBTTagCompound compound) {
|
||||
isActive = compound.getBoolean("TransformIsActive");
|
||||
readOptions(compound);
|
||||
display = hasDisplay?compound.getCompoundTag("TransformDisplay"): getDisplay();
|
||||
ai = hasAi?compound.getCompoundTag("TransformAI"): npc.ai.writeToNBT(new NBTTagCompound());
|
||||
ai = hasAi?compound.getCompoundTag("TransformAI"): npc.ais.writeToNBT(new NBTTagCompound());
|
||||
advanced = hasAdvanced?compound.getCompoundTag("TransformAdvanced"): getAdvanced();
|
||||
inv = hasInv?compound.getCompoundTag("TransformInv"): npc.inventory.writeEntityToNBT(new NBTTagCompound());
|
||||
stats = hasStats?compound.getCompoundTag("TransformStats"): npc.stats.writeToNBT(new NBTTagCompound());
|
||||
job = hasJob?compound.getCompoundTag("TransformJob"): getJob();
|
||||
role = hasRole?compound.getCompoundTag("TransformRole"): getRole();
|
||||
}
|
||||
|
||||
|
||||
public NBTTagCompound getJob() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
||||
@@ -83,17 +83,17 @@ public class DataTransform {
|
||||
if (npc.advanced.job != EnumJobType.None && npc.jobInterface != null) {
|
||||
npc.jobInterface.writeToNBT(compound);
|
||||
}
|
||||
|
||||
|
||||
return compound;
|
||||
}
|
||||
public NBTTagCompound getRole() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
||||
compound.setInteger("Role", npc.advanced.role.ordinal());
|
||||
compound.setInteger("Role", npc.advanced.role.ordinal());
|
||||
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null) {
|
||||
npc.roleInterface.writeToNBT(compound);
|
||||
}
|
||||
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class DataTransform {
|
||||
if(npc instanceof EntityCustomNpc){
|
||||
compound.setTag("ModelData", ((EntityCustomNpc)npc).modelData.writeToNBT());
|
||||
}
|
||||
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class DataTransform {
|
||||
|
||||
npc.advanced.job = jopType;
|
||||
npc.advanced.role = roleType;
|
||||
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class DataTransform {
|
||||
boolean hadStats = hasStats;
|
||||
boolean hadRole = hasRole;
|
||||
boolean hadJob = hasJob;
|
||||
|
||||
|
||||
hasDisplay = compound.getBoolean("TransformHasDisplay");
|
||||
hasAi = compound.getBoolean("TransformHasAI");
|
||||
hasAdvanced = compound.getBoolean("TransformHasAdvanced");
|
||||
@@ -146,7 +146,7 @@ public class DataTransform {
|
||||
display = getDisplay();
|
||||
}
|
||||
if(hasAi && !hadAI)
|
||||
ai = npc.ai.writeToNBT(new NBTTagCompound());
|
||||
ai = npc.ais.writeToNBT(new NBTTagCompound());
|
||||
if(hasStats && !hadStats)
|
||||
stats = npc.stats.writeToNBT(new NBTTagCompound());
|
||||
if(hasInv && !hadInv)
|
||||
@@ -158,7 +158,7 @@ public class DataTransform {
|
||||
if(hasRole && !hadRole)
|
||||
role = getRole();
|
||||
}
|
||||
|
||||
|
||||
public boolean isValid(){
|
||||
return hasAdvanced || hasAi || hasDisplay || hasInv || hasStats || hasJob || hasRole;
|
||||
}
|
||||
@@ -166,14 +166,14 @@ public class DataTransform {
|
||||
|
||||
public NBTTagCompound processAdvanced(NBTTagCompound compoundAdv,
|
||||
NBTTagCompound compoundRole, NBTTagCompound compoundJob) {
|
||||
|
||||
|
||||
if(hasAdvanced)
|
||||
compoundAdv = advanced;
|
||||
if(hasRole)
|
||||
compoundRole = role;
|
||||
if(hasJob)
|
||||
compoundJob = job;
|
||||
|
||||
|
||||
Set<String> names = compoundRole.func_150296_c();
|
||||
for(String name : names)
|
||||
compoundAdv.setTag(name, compoundRole.getTag(name));
|
||||
@@ -181,10 +181,10 @@ public class DataTransform {
|
||||
names = compoundJob.func_150296_c();
|
||||
for(String name : names)
|
||||
compoundAdv.setTag(name, compoundJob.getTag(name));
|
||||
|
||||
|
||||
return compoundAdv;
|
||||
}
|
||||
|
||||
|
||||
public void transform(boolean isActive){
|
||||
if(this.isActive == isActive)
|
||||
return;
|
||||
@@ -205,14 +205,14 @@ public class DataTransform {
|
||||
NBTTagCompound compoundAdv = getAdvanced();
|
||||
NBTTagCompound compoundRole = getRole();
|
||||
NBTTagCompound compoundJob = getJob();
|
||||
|
||||
|
||||
NBTTagCompound compound = processAdvanced(compoundAdv, compoundRole, compoundJob);
|
||||
npc.advanced.readToNBT(compound);
|
||||
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null)
|
||||
if (npc.advanced.role != EnumRoleType.None && npc.roleInterface != null)
|
||||
npc.roleInterface.readFromNBT(NBTTags.NBTMerge(compoundRole, compound));
|
||||
if (npc.advanced.job != EnumJobType.None && npc.jobInterface != null)
|
||||
npc.jobInterface.readFromNBT(NBTTags.NBTMerge(compoundJob, compound));
|
||||
|
||||
npc.jobInterface.readFromNBT(NBTTags.NBTMerge(compoundJob, compound));
|
||||
|
||||
if(hasAdvanced)
|
||||
advanced = compoundAdv;
|
||||
if(hasRole)
|
||||
@@ -221,8 +221,8 @@ public class DataTransform {
|
||||
job = compoundJob;
|
||||
}
|
||||
if(hasAi){
|
||||
NBTTagCompound compound = npc.ai.writeToNBT(new NBTTagCompound());
|
||||
npc.ai.readToNBT(NBTTags.NBTMerge(compound, ai));
|
||||
NBTTagCompound compound = npc.ais.writeToNBT(new NBTTagCompound());
|
||||
npc.ais.readToNBT(NBTTags.NBTMerge(compound, ai));
|
||||
ai = compound;
|
||||
npc.setCurrentAnimation(EnumAnimation.NONE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
public class EffectKey {
|
||||
private final int id;
|
||||
private final int index;
|
||||
|
||||
public EffectKey(int key1, int key2) {
|
||||
this.id = key1;
|
||||
this.index = key2;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof EffectKey)) return false;
|
||||
EffectKey that = (EffectKey) o;
|
||||
return id == that.id && index == that.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * id + index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EffectKey{" + "key1=" + id + ", key2=" + index + '}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.PlayerEvent;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class EffectScript implements IScriptHandler {
|
||||
public ScriptContainer container;
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
public boolean enabled = false;
|
||||
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ScriptLanguage", scriptLanguage);
|
||||
compound.setBoolean("ScriptEnabled", enabled);
|
||||
|
||||
if (container != null)
|
||||
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public EffectScript readFromNBT(NBTTagCompound compound) {
|
||||
scriptLanguage = compound.getString("ScriptLanguage");
|
||||
enabled = compound.getBoolean("ScriptEnabled");
|
||||
|
||||
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
|
||||
container = new ScriptContainer(this);
|
||||
container.readFromNBT(compound.getCompoundTag("ScriptContent"));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void callScript(ScriptType type, PlayerEvent.EffectEvent event) {
|
||||
callScript(type.function, event);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String s, Event event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptEngine engine = container.engine;
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
|
||||
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
|
||||
engine.put(engineObjects.getKey(), engineObjects.getValue());
|
||||
}
|
||||
|
||||
container.run(s, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClient() {
|
||||
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean b) {
|
||||
this.enabled = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return this.scriptLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String s) {
|
||||
this.scriptLanguage = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScripts(List<ScriptContainer> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
container = null;
|
||||
return;
|
||||
}
|
||||
container = list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ScriptContainer> getScripts() {
|
||||
if (container == null)
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getConsoleText() {
|
||||
TreeMap<Long, String> map = new TreeMap();
|
||||
int tab = 0;
|
||||
Iterator var3 = this.getScripts().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var3.next();
|
||||
++tab;
|
||||
Iterator var5 = script.console.entrySet().iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<Long, String> longStringEntry = (Map.Entry)var5.next();
|
||||
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + (String)longStringEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
Iterator var1 = this.getScripts().iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var1.next();
|
||||
script.console.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveScript(ByteBuf buffer) throws IOException {
|
||||
int tab = buffer.readInt();
|
||||
int totalScripts = buffer.readInt();
|
||||
if (totalScripts == 0) {
|
||||
this.container = null;
|
||||
}
|
||||
|
||||
if (tab == 0) {
|
||||
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
|
||||
ScriptContainer script = new ScriptContainer(this);
|
||||
script.readFromNBT(tabCompound);
|
||||
this.container = script;
|
||||
} else {
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
|
||||
this.setLanguage(compound.getString("ScriptLanguage"));
|
||||
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
|
||||
if (!ScriptController.Instance.languages.isEmpty()) {
|
||||
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
|
||||
} else {
|
||||
this.setLanguage("ECMAScript");
|
||||
}
|
||||
}
|
||||
this.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
}
|
||||
}
|
||||
|
||||
public enum ScriptType {
|
||||
OnAdd("onAdded"),
|
||||
OnTick("onTick"),
|
||||
OnRemove("onRemove");
|
||||
|
||||
public final String function;
|
||||
ScriptType(String functionName) {
|
||||
this.function = functionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
public class LinkedItemData {
|
||||
|
||||
// Utilitzed within a Scripted Item
|
||||
//
|
||||
public int version = 1;
|
||||
|
||||
public boolean durabilityShow = false;
|
||||
public double durabilityValue = 1.0D;
|
||||
public int durabilityColor = -1;
|
||||
public int itemColor = 0x8B4513;
|
||||
public int stackSize = 64;
|
||||
|
||||
public int maxItemUseDuration = 20;
|
||||
public int itemUseAction = 0;
|
||||
|
||||
public boolean isNormalItem = false;
|
||||
public boolean isTool = false;
|
||||
public int digSpeed = 1;
|
||||
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
|
||||
public int enchantability;
|
||||
|
||||
public String texture = "minecraft:textures/items/iron_pickaxe.png";
|
||||
|
||||
public float translateX, translateY, translateZ;
|
||||
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
|
||||
public float rotationX, rotationY, rotationZ;
|
||||
public float rotationXRate, rotationYRate, rotationZRate;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class LinkedItemScript implements IScriptHandler {
|
||||
public ScriptContainer container;
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
public boolean enabled = false;
|
||||
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ScriptLanguage", scriptLanguage);
|
||||
compound.setBoolean("ScriptEnabled", enabled);
|
||||
|
||||
if (container != null)
|
||||
compound.setTag("ScriptContent", container.writeToNBT(new NBTTagCompound()));
|
||||
return compound;
|
||||
}
|
||||
|
||||
public LinkedItemScript readFromNBT(NBTTagCompound compound) {
|
||||
scriptLanguage = compound.getString("ScriptLanguage");
|
||||
enabled = compound.getBoolean("ScriptEnabled");
|
||||
|
||||
if (compound.hasKey("ScriptContent", Constants.NBT.TAG_COMPOUND)) {
|
||||
container = new ScriptContainer(this);
|
||||
container.readFromNBT(compound.getCompoundTag("ScriptContent"));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String s, Event event) {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptEngine engine = container.engine;
|
||||
engine.put("API", NpcAPI.Instance());
|
||||
|
||||
for (Map.Entry<String, Object> engineObjects : NpcAPI.engineObjects.entrySet()) {
|
||||
engine.put(engineObjects.getKey(), engineObjects.getValue());
|
||||
}
|
||||
|
||||
container.run(s, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClient() {
|
||||
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean b) {
|
||||
this.enabled = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return this.scriptLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String s) {
|
||||
this.scriptLanguage = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScripts(List<ScriptContainer> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
container = null;
|
||||
return;
|
||||
}
|
||||
container = list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ScriptContainer> getScripts() {
|
||||
if (container == null)
|
||||
return new ArrayList<>();
|
||||
return Collections.singletonList(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getConsoleText() {
|
||||
TreeMap<Long, String> map = new TreeMap();
|
||||
int tab = 0;
|
||||
Iterator var3 = this.getScripts().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var3.next();
|
||||
++tab;
|
||||
Iterator var5 = script.console.entrySet().iterator();
|
||||
|
||||
while(var5.hasNext()) {
|
||||
Map.Entry<Long, String> longStringEntry = (Map.Entry)var5.next();
|
||||
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + (String)longStringEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
Iterator var1 = this.getScripts().iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
ScriptContainer script = (ScriptContainer)var1.next();
|
||||
script.console.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveScript(ByteBuf buffer) throws IOException {
|
||||
int tab = buffer.readInt();
|
||||
int totalScripts = buffer.readInt();
|
||||
if (totalScripts == 0) {
|
||||
this.container = null;
|
||||
}
|
||||
|
||||
if (tab == 0) {
|
||||
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
|
||||
ScriptContainer script = new ScriptContainer(this);
|
||||
script.readFromNBT(tabCompound);
|
||||
this.container = script;
|
||||
} else {
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
|
||||
this.setLanguage(compound.getString("ScriptLanguage"));
|
||||
if (!ScriptController.Instance.languages.containsKey(this.getLanguage())) {
|
||||
if (!ScriptController.Instance.languages.isEmpty()) {
|
||||
this.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
|
||||
} else {
|
||||
this.setLanguage("ECMAScript");
|
||||
}
|
||||
}
|
||||
this.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +1,165 @@
|
||||
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;
|
||||
public int index;
|
||||
public int priority;
|
||||
|
||||
public Magic(){}
|
||||
// Icon as an ItemStack or as a texture file
|
||||
public ItemStack iconItem = null;
|
||||
public String iconTexture = "";
|
||||
|
||||
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){
|
||||
// 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() {}
|
||||
|
||||
public Magic(int id, String name, int color) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Magic(int id, String name, int color, int index, int priority) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.id = id;
|
||||
this.index = index;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
index = compound.getInteger("Index");
|
||||
priority = compound.getInteger("Priority");
|
||||
|
||||
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);
|
||||
compound.setInteger("Index", index);
|
||||
compound.setInteger("Priority", priority);
|
||||
|
||||
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 int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.MarkDataPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.entity.data.IMark;
|
||||
import noppes.npcs.api.handler.data.IAvailability;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.MarkType;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
@@ -102,7 +102,7 @@ public class MarkData implements IExtendedEntityProperties {
|
||||
public void init(Entity entity, World world) {}
|
||||
|
||||
public void syncClients() {
|
||||
Server.sendToAll(EnumPacketClient.MARK_DATA, entity.getEntityId(), getNBT());
|
||||
PacketHandler.Instance.sendToAll(new MarkDataPacket(entity.getEntityId(), getNBT()));
|
||||
}
|
||||
|
||||
public class Mark implements IMark {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.addon.DBCAddon;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import kamkeel.npcs.network.packets.request.party.PartyInvitePacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -10,12 +13,9 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.PacketHandlerServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.*;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.PartyController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
@@ -43,7 +43,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this);
|
||||
public PlayerMailData mailData = new PlayerMailData(this);
|
||||
public AnimationData animationData = new AnimationData(this);
|
||||
|
||||
public PlayerEffectData effectData = new PlayerEffectData(this);
|
||||
public DataTimers timers = new DataTimers(this);
|
||||
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
|
||||
|
||||
@@ -96,6 +96,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
timers.readFromNBT(data);
|
||||
skinOverlays.readFromNBT(data);
|
||||
animationData.readFromNBT(data);
|
||||
effectData.readFromNBT(data);
|
||||
|
||||
if(player != null){
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -135,6 +136,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
timers.writeToNBT(compound);
|
||||
skinOverlays.writeToNBT(compound);
|
||||
animationData.writeToNBT(compound);
|
||||
effectData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
@@ -164,6 +166,16 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
factionData.loadNBTData(data);
|
||||
}
|
||||
|
||||
public NBTTagCompound getPlayerEffects(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
effectData.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void setPlayerEffects(NBTTagCompound data){
|
||||
effectData.readFromNBT(data);
|
||||
}
|
||||
|
||||
public NBTTagCompound getSyncNBTFull() {
|
||||
if(player != null){
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -265,15 +277,16 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public void inviteToParty(Party party) {
|
||||
if (party != null && this.partyUUID == null && !this.partyInvites.contains(party.getPartyUUID())) {
|
||||
this.partyInvites.add(party.getPartyUUID());
|
||||
Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.PARTY_MESSAGE, "party.inviteAlert", party.getPartyLeader().getCommandSenderName());
|
||||
Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.CHAT, "\u00A7a", "party.inviteChat", " ", party.getPartyLeader().getCommandSenderName(), "!");
|
||||
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) player, true, "party.inviteAlert", party.getPartyLeader().getCommandSenderName());
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "\u00A7a", "party.inviteChat", " ", party.getPartyLeader().getCommandSenderName(), "!");
|
||||
}
|
||||
}
|
||||
|
||||
public void ignoreInvite(UUID uuid) {
|
||||
if (uuid != null) {
|
||||
this.partyInvites.remove(uuid);
|
||||
PacketHandlerServer.sendInviteData((EntityPlayerMP) player);
|
||||
PartyInvitePacket.sendInviteData((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.IPlayerEffect;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
|
||||
public class PlayerEffect implements IPlayerEffect {
|
||||
public int id;
|
||||
public int duration;
|
||||
public byte level;
|
||||
public int index;
|
||||
|
||||
public PlayerEffect(int id, int duration, byte level) {
|
||||
this.id = id;
|
||||
this.duration = duration;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public static PlayerEffect readEffectData(NBTTagCompound nbt) {
|
||||
int id = nbt.getInteger("Id");
|
||||
int index = nbt.getInteger("Index");
|
||||
if (id > 0) {
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
boolean found = controller.has(id);
|
||||
// StatusEffectController.getInstance().customEffects.containsKey(id);
|
||||
if (found) {
|
||||
byte level = nbt.getByte("Level");
|
||||
int dur = nbt.getInteger("Dur");
|
||||
return new PlayerEffect(id, dur, level);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeEffectData(NBTTagCompound nbt) {
|
||||
nbt.setInteger("Id", this.id);
|
||||
nbt.setByte("Level", this.level);
|
||||
nbt.setInteger("Dur", this.duration);
|
||||
nbt.setInteger("Index", this.index);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kill() {
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(byte level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(this.id);
|
||||
if(effect != null)
|
||||
return effect.getName();
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performEffect(IPlayer player) {
|
||||
if (player != null && player.getMCEntity() != null && player.getMCEntity() instanceof EntityPlayer) {
|
||||
CustomEffect effect = CustomEffectController.getInstance().get(this.id);
|
||||
if(effect != null)
|
||||
effect.onTick((EntityPlayer) player.getMCEntity(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerEffectData {
|
||||
private final PlayerData parent;
|
||||
private ConcurrentHashMap<EffectKey, PlayerEffect> effects = new ConcurrentHashMap<>();
|
||||
|
||||
public PlayerEffectData(PlayerData playerData){
|
||||
this.parent = playerData;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (Map.Entry<EffectKey, PlayerEffect> entry : effects.entrySet()) {
|
||||
NBTTagCompound effectCompound = new NBTTagCompound();
|
||||
effectCompound.setInteger("id", entry.getKey().getId());
|
||||
effectCompound.setInteger("index", entry.getKey().getIndex());
|
||||
effectCompound.setInteger("duration", entry.getValue().duration);
|
||||
effectCompound.setByte("level", entry.getValue().level);
|
||||
list.appendTag(effectCompound);
|
||||
}
|
||||
compound.setTag("Effects", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
HashSet<EffectKey> newKeys = new HashSet<>();
|
||||
if (compound.hasKey("Effects")) {
|
||||
NBTTagList list = compound.getTagList("Effects", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound effectCompound = list.getCompoundTagAt(i);
|
||||
int id = effectCompound.getInteger("id");
|
||||
int index = effectCompound.getInteger("index");
|
||||
int duration = effectCompound.getInteger("duration");
|
||||
byte level = effectCompound.getByte("level");
|
||||
EffectKey key = new EffectKey(id, index);
|
||||
newKeys.add(key);
|
||||
PlayerEffect effect = effects.get(key);
|
||||
if (effect != null) {
|
||||
effect.duration = duration;
|
||||
effect.level = level;
|
||||
} else {
|
||||
effect = new PlayerEffect(id, duration, level);
|
||||
effect.index = index;
|
||||
effects.put(key, effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
Iterator<EffectKey> it = effects.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
EffectKey key = it.next();
|
||||
if (!newKeys.contains(key)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<EffectKey, PlayerEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void setEffects(ConcurrentHashMap<EffectKey, PlayerEffect> effects) {
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public PlayerEffect getPlayerEffect(int id, int index) {
|
||||
return effects.get(new EffectKey(id, index));
|
||||
}
|
||||
|
||||
public PlayerEffect getPlayerEffect(int id) {
|
||||
return getPlayerEffect(id, 0);
|
||||
}
|
||||
|
||||
public boolean hasPlayerEffect(int id, int index) {
|
||||
return effects.containsKey(new EffectKey(id, index));
|
||||
}
|
||||
|
||||
public boolean hasPlayerEffect(int id) {
|
||||
return hasPlayerEffect(id, 0);
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@ public class PlayerMail implements IInventory, IPlayerMail {
|
||||
public int questId = -1;
|
||||
public String questTitle = "";
|
||||
public ItemStack[] items = new ItemStack[4];
|
||||
|
||||
|
||||
public long timePast;
|
||||
|
||||
|
||||
public void readNBT(NBTTagCompound compound) {
|
||||
subject = compound.getString("Subject");
|
||||
sender = compound.getString("Sender");
|
||||
@@ -81,7 +81,7 @@ public class PlayerMail implements IInventory, IPlayerMail {
|
||||
compound.setTag("MailItems", nbttaglist);
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
public boolean isValid(){
|
||||
return !subject.isEmpty() && !message.hasNoTags() && !sender.isEmpty();
|
||||
}
|
||||
@@ -168,20 +168,20 @@ public class PlayerMail implements IInventory, IPlayerMail {
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,7 +191,7 @@ public class PlayerMail implements IInventory, IPlayerMail {
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import kamkeel.npcs.network.packets.data.OverlayQuestTrackingPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IPlayerQuestData;
|
||||
import noppes.npcs.api.handler.data.IParty;
|
||||
import noppes.npcs.api.handler.data.IQuest;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
@@ -201,8 +203,8 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
public void untrackQuest() {
|
||||
if (this.trackedQuest != null) {
|
||||
this.trackedQuest = null;
|
||||
Server.sendData((EntityPlayerMP) this.parent.player, EnumPacketClient.OVERLAY_QUEST_TRACKING);
|
||||
}
|
||||
PacketHandler.Instance.sendToPlayer(new OverlayQuestTrackingPacket(new NBTTagCompound()), (EntityPlayerMP) this.parent.player);
|
||||
}
|
||||
}
|
||||
|
||||
public IQuest getTrackedQuest() {
|
||||
@@ -217,9 +219,9 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
return;
|
||||
QuestData questdata = new QuestData(quest);
|
||||
activeQuests.put(id, questdata);
|
||||
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
|
||||
AchievementPacket.sendAchievement((EntityPlayerMP) parent.player, false, "quest.newquest", quest.title);
|
||||
ChatAlertPacket.sendChatAlert((EntityPlayerMP) parent.player, "quest.newquest", ": ", quest.title);
|
||||
parent.updateClient = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.QuestCompletionPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -7,7 +8,6 @@ import noppes.npcs.*;
|
||||
import noppes.npcs.api.IContainer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.*;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
@@ -139,7 +139,7 @@ public class Quest implements ICompatibilty, IQuest {
|
||||
|
||||
public boolean instantComplete(EntityPlayer player, QuestData data) {
|
||||
if(completion == EnumQuestCompletion.Instant && NoppesUtilPlayer.questCompletion((EntityPlayerMP) player, data.quest.id)){
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.QUEST_COMPLETION, data.quest.writeToNBT(new NBTTagCompound()));
|
||||
QuestCompletionPacket.sendQuestComplete((EntityPlayerMP)player, data.quest.writeToNBT(new NBTTagCompound()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.handler.data.IAnvilRecipe;
|
||||
import noppes.npcs.controllers.data.Availability;
|
||||
|
||||
public class RecipeAnvil implements IAnvilRecipe {
|
||||
public int id = -1;
|
||||
public String name = "";
|
||||
public Availability availability = new Availability();
|
||||
|
||||
public boolean ignoreRepairItemNBT = false;
|
||||
public boolean ignoreRepairMaterialNBT = false;
|
||||
public boolean ignoreRepairMaterialDamage = false;
|
||||
|
||||
public ItemStack itemToRepair;
|
||||
public ItemStack repairMaterial;
|
||||
|
||||
public int xpCost;
|
||||
public float repairPercentage;
|
||||
|
||||
private boolean isAnvil = true;
|
||||
|
||||
public RecipeAnvil() { }
|
||||
|
||||
public RecipeAnvil(String name, ItemStack itemToRepair, ItemStack repairMaterial, int xpCost, float repairPercentage) {
|
||||
this.name = name;
|
||||
this.itemToRepair = itemToRepair;
|
||||
this.repairMaterial = repairMaterial;
|
||||
this.xpCost = xpCost;
|
||||
this.repairPercentage = repairPercentage;
|
||||
}
|
||||
|
||||
public static RecipeAnvil read(NBTTagCompound compound) {
|
||||
RecipeAnvil recipe = new RecipeAnvil();
|
||||
recipe.id = compound.getInteger("ID");
|
||||
recipe.name = compound.getString("Name");
|
||||
recipe.availability.readFromNBT(compound.getCompoundTag("Availability"));
|
||||
recipe.xpCost = compound.getInteger("XPCost");
|
||||
recipe.repairPercentage = compound.getFloat("RepairPercentage");
|
||||
recipe.itemToRepair = NoppesUtilServer.readItem(compound.getCompoundTag("ItemToRepair"));
|
||||
recipe.repairMaterial = NoppesUtilServer.readItem(compound.getCompoundTag("RepairMaterial"));
|
||||
recipe.ignoreRepairMaterialNBT = compound.getBoolean("IgnoreRepairMatNBT");
|
||||
recipe.ignoreRepairItemNBT = compound.getBoolean("IgnoreRepairItemNBT");
|
||||
recipe.ignoreRepairMaterialDamage = compound.getBoolean("IgnoreRepairMatDamage");
|
||||
recipe.isAnvil = true;
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("ID", id);
|
||||
compound.setString("Name", name);
|
||||
compound.setTag("Availability", availability.writeToNBT(new NBTTagCompound()));
|
||||
compound.setInteger("XPCost", xpCost);
|
||||
compound.setFloat("RepairPercentage", repairPercentage);
|
||||
if(itemToRepair != null){
|
||||
compound.setTag("ItemToRepair", NoppesUtilServer.writeItem(itemToRepair, new NBTTagCompound()));
|
||||
}
|
||||
if(repairMaterial != null){
|
||||
compound.setTag("RepairMaterial", NoppesUtilServer.writeItem(repairMaterial, new NBTTagCompound()));
|
||||
}
|
||||
compound.setBoolean("IgnoreRepairMatNBT", ignoreRepairMaterialNBT);
|
||||
compound.setBoolean("IgnoreRepairItemNBT", ignoreRepairItemNBT);
|
||||
compound.setBoolean("IgnoreRepairMatDamage", ignoreRepairMaterialDamage);
|
||||
compound.setBoolean("IsAnvil", true);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXpCost() {
|
||||
return xpCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRepairPercentage() {
|
||||
return repairPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack inputItem, ItemStack inputRepairMaterial) {
|
||||
if (inputItem == null || inputRepairMaterial == null) return false;
|
||||
if (!NoppesUtilPlayer.compareItems(this.itemToRepair, inputItem, true, this.ignoreRepairItemNBT)) {
|
||||
return false;
|
||||
}
|
||||
if (!NoppesUtilPlayer.compareItems(this.repairMaterial, inputRepairMaterial, this.ignoreRepairMaterialDamage, this.ignoreRepairMaterialNBT)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResult(ItemStack inputItem) {
|
||||
if (inputItem == null)
|
||||
return null;
|
||||
ItemStack result = inputItem.copy();
|
||||
if (!result.isItemStackDamageable())
|
||||
return result;
|
||||
int maxDamage = result.getMaxDamage();
|
||||
int repairAmount = (int) (maxDamage * repairPercentage);
|
||||
int currentDamage = result.getItemDamage();
|
||||
int newDamage = currentDamage - repairAmount;
|
||||
if (newDamage < 0) newDamage = 0;
|
||||
result.setItemDamage(newDamage);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public static RecipeAnvil saveRecipe(RecipeAnvil recipe, ItemStack output, ItemStack repairMaterial) {
|
||||
if (output != null) {
|
||||
recipe.itemToRepair = output.copy();
|
||||
if (recipe.itemToRepair.isItemStackDamageable()) {
|
||||
recipe.itemToRepair.setItemDamage(0);
|
||||
}
|
||||
} else {
|
||||
recipe.itemToRepair = null;
|
||||
}
|
||||
recipe.repairMaterial = (repairMaterial == null ? null : repairMaterial.copy());
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return itemToRepair != null && repairMaterial != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a deep copy of this RecipeAnvil.
|
||||
*/
|
||||
public void copy(RecipeAnvil recipe) {
|
||||
this.id = recipe.id;
|
||||
this.name = recipe.name;
|
||||
this.availability = recipe.availability;
|
||||
this.ignoreRepairMaterialDamage = recipe.ignoreRepairMaterialDamage;
|
||||
this.ignoreRepairItemNBT = recipe.ignoreRepairItemNBT;
|
||||
this.ignoreRepairMaterialNBT = recipe.ignoreRepairMaterialNBT;
|
||||
this.repairPercentage = recipe.repairPercentage;;
|
||||
this.xpCost = recipe.xpCost;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
|
||||
public boolean isGlobal = false;
|
||||
public boolean ignoreDamage = false;
|
||||
public boolean ignoreNBT = false;
|
||||
|
||||
|
||||
|
||||
public RecipeCarpentry(int width, int height, ItemStack[] recipe, ItemStack result){
|
||||
super(width, height, recipe, result);
|
||||
@@ -32,9 +32,9 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
|
||||
super(0, 0, new ItemStack[0], null);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public static RecipeCarpentry read(NBTTagCompound compound){
|
||||
RecipeCarpentry recipe = new RecipeCarpentry(compound.getInteger("Width"), compound.getInteger("Height"),
|
||||
RecipeCarpentry recipe = new RecipeCarpentry(compound.getInteger("Width"), compound.getInteger("Height"),
|
||||
NBTTags.getItemStackArray(compound.getTagList("Materials", 10)), NoppesUtilServer.readItem(compound.getCompoundTag("Item")));
|
||||
recipe.name = compound.getString("Name");
|
||||
recipe.id = compound.getInteger("ID");
|
||||
@@ -42,7 +42,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
|
||||
recipe.ignoreDamage = compound.getBoolean("IgnoreDamage");
|
||||
recipe.ignoreNBT = compound.getBoolean("IgnoreNBT");
|
||||
recipe.isGlobal = compound.getBoolean("Global");
|
||||
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@@ -188,15 +188,14 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
|
||||
var15[var9] = null;
|
||||
}
|
||||
}
|
||||
RecipeCarpentry newrecipe = new RecipeCarpentry(var5, var6, var15, par1ItemStack);
|
||||
RecipeCarpentry newrecipe = new RecipeCarpentry(var5, var6, var15, par1ItemStack);
|
||||
newrecipe.copy(recipe);
|
||||
if(var5 == 4 || var6 == 4)
|
||||
newrecipe.isGlobal = false;
|
||||
|
||||
|
||||
|
||||
|
||||
return newrecipe;
|
||||
}
|
||||
|
||||
public void copy(RecipeCarpentry recipe) {
|
||||
this.id = recipe.id;
|
||||
this.name = recipe.name;
|
||||
@@ -205,7 +204,7 @@ public class RecipeCarpentry extends ShapedRecipes implements IRecipe {
|
||||
this.ignoreDamage = recipe.ignoreDamage;
|
||||
this.ignoreNBT = recipe.ignoreNBT;
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getCraftingItem(int i){
|
||||
if(recipeItems == null || i >= recipeItems.length)
|
||||
return null;
|
||||
|
||||
@@ -18,18 +18,18 @@ public class RecipesDefault {
|
||||
item = new ItemStack((Block)ob);
|
||||
else
|
||||
item = (ItemStack) ob;
|
||||
|
||||
RecipeCarpentry recipeAnvil = new RecipeCarpentry(name);
|
||||
recipeAnvil.isGlobal = isGlobal;
|
||||
recipeAnvil = RecipeCarpentry.saveRecipe(recipeAnvil, item, recipe);
|
||||
RecipeController.Instance.addRecipe(recipeAnvil);
|
||||
|
||||
RecipeCarpentry recipeCarpentry = new RecipeCarpentry(name);
|
||||
recipeCarpentry.isGlobal = isGlobal;
|
||||
recipeCarpentry = RecipeCarpentry.saveRecipe(recipeCarpentry, item, recipe);
|
||||
RecipeController.Instance.addRecipe(recipeCarpentry);
|
||||
}
|
||||
public static void loadDefaultRecipes(int i) {
|
||||
if(i < 0){
|
||||
addRecipe("Npc Wand", CustomItems.wand, true, "XX"," Y"," Y",'X', Items.bread,'Y', Items.stick);
|
||||
addRecipe("Mob Cloner", CustomItems.cloner, true, "XX","XY"," Y",'X', Items.bread,'Y', Items.stick);
|
||||
addRecipe("Carpentry Bench", CustomItems.carpentyBench, true, "XYX","Z Z","Z Z", 'X', Blocks.planks, 'Z', Items.stick, 'Y', Blocks.crafting_table);
|
||||
|
||||
|
||||
if(!ConfigMain.DisableExtraItems){
|
||||
addRecipe("Mana", CustomItems.mana, true, "XY",'X',Items.redstone,'Y',Items.glowstone_dust);
|
||||
addRecipe("Gun Wooden", CustomItems.gunWood, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Blocks.planks);
|
||||
@@ -39,7 +39,7 @@ public class RecipesDefault {
|
||||
addRecipe("Gun Diamond", CustomItems.gunDiamond, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Items.diamond);
|
||||
addRecipe("Gun Emerald", CustomItems.gunEmerald, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Items.emerald);
|
||||
addRecipe("Gun Bronze", CustomItems.gunBronze, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', CustomItems.bronze_ingot);
|
||||
|
||||
|
||||
addRecipe("Bullet Wooden", CustomItems.bulletWood, true, "X",'X', Blocks.planks);
|
||||
addRecipe("Bullet Stone", CustomItems.bulletStone, true, "X",'X', Blocks.cobblestone);
|
||||
addRecipe("Bullet Iron", CustomItems.bulletIron, true, "X",'X', Items.iron_ingot);
|
||||
@@ -56,96 +56,96 @@ public class RecipesDefault {
|
||||
addRecipe("WallBanner Iron", new ItemStack(CustomItems.wallBanner, 1, 2), false, "XXX","ZZZ","ZZZ","Z Z",'Z', Blocks.wool, 'X', Items.iron_ingot);
|
||||
addRecipe("WallBanner Gold", new ItemStack(CustomItems.wallBanner, 1, 3), false, "XXX","ZZZ","ZZZ","Z Z",'Z', Blocks.wool, 'X', Items.gold_ingot);
|
||||
addRecipe("WallBanner Diamond", new ItemStack(CustomItems.wallBanner, 1, 4), false, "XXX","ZZZ","ZZZ","Z Z",'Z', Blocks.wool, 'X', Items.diamond);
|
||||
|
||||
|
||||
addRecipe("Banner Wooden", new ItemStack(CustomItems.banner, 1, 0), false, " X "," Z "," Z ","ZZZ", 'X', new ItemStack(CustomItems.wallBanner,1,0), 'Z', Blocks.planks);
|
||||
addRecipe("Banner Stone", new ItemStack(CustomItems.banner, 1, 1), false, " X "," Z "," Z ","ZZZ", 'X', new ItemStack(CustomItems.wallBanner,1,1), 'Z', Blocks.cobblestone);
|
||||
addRecipe("Banner Iron", new ItemStack(CustomItems.banner, 1, 2), false, " X "," Z "," Z ","ZZZ", 'X', new ItemStack(CustomItems.wallBanner,1,2), 'Z', Items.iron_ingot);
|
||||
addRecipe("Banner Gold", new ItemStack(CustomItems.banner, 1, 3), false, " X "," Z "," Z ","ZZZ", 'X', new ItemStack(CustomItems.wallBanner,1,3), 'Z', Items.gold_ingot);
|
||||
addRecipe("Banner Diamond", new ItemStack(CustomItems.banner, 1, 4), false, " X "," Z "," Z ","ZZZ", 'X', new ItemStack(CustomItems.wallBanner,1,4), 'Z', Items.diamond);
|
||||
|
||||
|
||||
addRecipe("Lamp Wooden", new ItemStack(CustomItems.tallLamp, 1, 0), false, "YXY"," Z "," Z ","ZZZ", 'X', Blocks.torch, 'Y', Blocks.wool, 'Z', Blocks.planks);
|
||||
addRecipe("Lamp Stone", new ItemStack(CustomItems.tallLamp, 1, 1), false, "YXY"," Z "," Z ","ZZZ", 'X', Blocks.torch, 'Y', Blocks.wool, 'Z', Blocks.cobblestone);
|
||||
addRecipe("Lamp Iron", new ItemStack(CustomItems.tallLamp, 1, 2), false, "YXY"," Z "," Z ","ZZZ", 'X', Blocks.torch, 'Y', Blocks.wool, 'Z', Items.iron_ingot);
|
||||
addRecipe("Lamp Gold", new ItemStack(CustomItems.tallLamp, 1, 3), false, "YXY"," Z "," Z ","ZZZ", 'X', Blocks.torch, 'Y', Blocks.wool, 'Z', Items.gold_ingot);
|
||||
addRecipe("Lamp Diamond", new ItemStack(CustomItems.tallLamp, 1, 4), false, "YXY"," Z "," Z ","ZZZ", 'X', Blocks.torch, 'Y', Blocks.wool, 'Z', Items.diamond);
|
||||
|
||||
|
||||
addRecipe("Chair Wooden1", new ItemStack(CustomItems.chair, 1, 0), false, " X", " X","XXX","X X", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Chair Wooden2", new ItemStack(CustomItems.chair, 1, 1), false, " X", " X","XXX","X X", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Chair Wooden3", new ItemStack(CustomItems.chair, 1, 2), false, " X", " X","XXX","X X", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Chair Wooden4", new ItemStack(CustomItems.chair, 1, 3), false, " X", " X","XXX","X X", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Chair Wooden5", new ItemStack(CustomItems.chair, 1, 4), false, " X", " X","XXX","X X", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Chair Wooden6", new ItemStack(CustomItems.chair, 1, 5), false, " X", " X","XXX","X X", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("Crate Wooden1", new ItemStack(CustomItems.crate, 1, 0), false, "XXXX","X X","X X","XXXX", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Crate Wooden2", new ItemStack(CustomItems.crate, 1, 1), false, "XXXX","X X","X X","XXXX", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Crate Wooden3", new ItemStack(CustomItems.crate, 1, 2), false, "XXXX","X X","X X","XXXX", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Crate Wooden4", new ItemStack(CustomItems.crate, 1, 3), false, "XXXX","X X","X X","XXXX", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Crate Wooden5", new ItemStack(CustomItems.crate, 1, 4), false, "XXXX","X X","X X","XXXX", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Crate Wooden6", new ItemStack(CustomItems.crate, 1, 5), false, "XXXX","X X","X X","XXXX", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("WeaponRack Wooden1", new ItemStack(CustomItems.weaponsRack, 1, 0), false, "XXX","XYX","XYX","XXX", 'X', new ItemStack(Blocks.planks,1,0),'Y', Items.stick);
|
||||
addRecipe("WeaponRack Wooden2", new ItemStack(CustomItems.weaponsRack, 1, 1), false, "XXX","XYX","XYX","XXX", 'X', new ItemStack(Blocks.planks,1,1),'Y', Items.stick);
|
||||
addRecipe("WeaponRack Wooden3", new ItemStack(CustomItems.weaponsRack, 1, 2), false, "XXX","XYX","XYX","XXX", 'X', new ItemStack(Blocks.planks,1,2),'Y', Items.stick);
|
||||
addRecipe("WeaponRack Wooden4", new ItemStack(CustomItems.weaponsRack, 1, 3), false, "XXX","XYX","XYX","XXX", 'X', new ItemStack(Blocks.planks,1,3),'Y', Items.stick);
|
||||
addRecipe("WeaponRack Wooden5", new ItemStack(CustomItems.weaponsRack, 1, 4), false, "XXX","XYX","XYX","XXX", 'X', new ItemStack(Blocks.planks,1,4),'Y', Items.stick);
|
||||
addRecipe("WeaponRack Wooden6", new ItemStack(CustomItems.weaponsRack, 1, 5), false, "XXX","XYX","XYX","XXX", 'X', new ItemStack(Blocks.planks,1,5),'Y', Items.stick);
|
||||
|
||||
|
||||
addRecipe("Couch Wooden1", new ItemStack(CustomItems.couchWood, 1, 0), false, " X"," X","XXXX","X X", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Couch Wooden2", new ItemStack(CustomItems.couchWood, 1, 1), false, " X"," X","XXXX","X X", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Couch Wooden3", new ItemStack(CustomItems.couchWood, 1, 2), false, " X"," X","XXXX","X X", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Couch Wooden4", new ItemStack(CustomItems.couchWood, 1, 3), false, " X"," X","XXXX","X X", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Couch Wooden5", new ItemStack(CustomItems.couchWood, 1, 4), false, " X"," X","XXXX","X X", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Couch Wooden6", new ItemStack(CustomItems.couchWood, 1, 5), false, " X"," X","XXXX","X X", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("Couch Wool1", new ItemStack(CustomItems.couchWool, 1, 0), false, " Z", " Z","ZZZZ","X X", 'X', new ItemStack(Blocks.planks,1,0), 'Z', Blocks.wool);
|
||||
addRecipe("Couch Wool2", new ItemStack(CustomItems.couchWool, 1, 1), false, " Z", " Z","ZZZZ","X X", 'X', new ItemStack(Blocks.planks,1,1), 'Z', Blocks.wool);
|
||||
addRecipe("Couch Wool3", new ItemStack(CustomItems.couchWool, 1, 2), false, " Z", " Z","ZZZZ","X X", 'X', new ItemStack(Blocks.planks,1,2), 'Z', Blocks.wool);
|
||||
addRecipe("Couch Wool4", new ItemStack(CustomItems.couchWool, 1, 3), false, " Z", " Z","ZZZZ","X X", 'X', new ItemStack(Blocks.planks,1,3), 'Z', Blocks.wool);
|
||||
addRecipe("Couch Wool5", new ItemStack(CustomItems.couchWool, 1, 4), false, " Z", " Z","ZZZZ","X X", 'X', new ItemStack(Blocks.planks,1,4), 'Z', Blocks.wool);
|
||||
addRecipe("Couch Wool6", new ItemStack(CustomItems.couchWool, 1, 5), false, " Z", " Z","ZZZZ","X X", 'X', new ItemStack(Blocks.planks,1,5), 'Z', Blocks.wool);
|
||||
|
||||
|
||||
addRecipe("Table Wood1", new ItemStack(CustomItems.table, 1, 0), false, "XXXX","X X","X X", 'X', new ItemStack(Blocks.planks,1,0), 'Z', Blocks.wool);
|
||||
addRecipe("Table Wood2", new ItemStack(CustomItems.table, 1, 1), false, "XXXX","X X","X X", 'X', new ItemStack(Blocks.planks,1,1), 'Z', Blocks.wool);
|
||||
addRecipe("Table Wood3", new ItemStack(CustomItems.table, 1, 2), false, "XXXX","X X","X X", 'X', new ItemStack(Blocks.planks,1,2), 'Z', Blocks.wool);
|
||||
addRecipe("Table Wood4", new ItemStack(CustomItems.table, 1, 3), false, "XXXX","X X","X X", 'X', new ItemStack(Blocks.planks,1,3), 'Z', Blocks.wool);
|
||||
addRecipe("Table Wood5", new ItemStack(CustomItems.table, 1, 4), false, "XXXX","X X","X X", 'X', new ItemStack(Blocks.planks,1,4), 'Z', Blocks.wool);
|
||||
addRecipe("Table Wood6", new ItemStack(CustomItems.table, 1, 5), false, "XXXX","X X","X X", 'X', new ItemStack(Blocks.planks,1,5), 'Z', Blocks.wool);
|
||||
|
||||
addRecipe("Stool Wood1", new ItemStack(CustomItems.stool, 1, 0), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Stool Wood2", new ItemStack(CustomItems.stool, 1, 1), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Stool Wood3", new ItemStack(CustomItems.stool, 1, 2), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Stool Wood4", new ItemStack(CustomItems.stool, 1, 3), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Stool Wood5", new ItemStack(CustomItems.stool, 1, 4), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Stool Wood6", new ItemStack(CustomItems.stool, 1, 5), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("noppes.npcs.client.model.blocks.Stool Wood1", new ItemStack(CustomItems.stool, 1, 0), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("noppes.npcs.client.model.blocks.Stool Wood2", new ItemStack(CustomItems.stool, 1, 1), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("noppes.npcs.client.model.blocks.Stool Wood3", new ItemStack(CustomItems.stool, 1, 2), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("noppes.npcs.client.model.blocks.Stool Wood4", new ItemStack(CustomItems.stool, 1, 3), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("noppes.npcs.client.model.blocks.Stool Wood5", new ItemStack(CustomItems.stool, 1, 4), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("noppes.npcs.client.model.blocks.Stool Wood6", new ItemStack(CustomItems.stool, 1, 5), false, "XXX"," X ","X X", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
addRecipe("Barrel Wood1", new ItemStack(CustomItems.barrel, 1, 0), false, "XXX","X X","X X", "XXX", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Barrel Wood2", new ItemStack(CustomItems.barrel, 1, 1), false, "XXX","X X","X X", "XXX", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Barrel Wood3", new ItemStack(CustomItems.barrel, 1, 2), false, "XXX","X X","X X", "XXX", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Barrel Wood4", new ItemStack(CustomItems.barrel, 1, 3), false, "XXX","X X","X X", "XXX", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Barrel Wood5", new ItemStack(CustomItems.barrel, 1, 4), false, "XXX","X X","X X", "XXX", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Barrel Wood6", new ItemStack(CustomItems.barrel, 1, 5), false, "XXX","X X","X X", "XXX", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("Shelf Wood1", new ItemStack(CustomItems.shelf, 2, 0), false, "XXX","XY ","X ", 'Y', Items.stick, 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Shelf Wood2", new ItemStack(CustomItems.shelf, 2, 1), false, "XXX","XY ","X ", 'Y', Items.stick, 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Shelf Wood3", new ItemStack(CustomItems.shelf, 2, 2), false, "XXX","XY ","X ", 'Y', Items.stick, 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Shelf Wood4", new ItemStack(CustomItems.shelf, 2, 3), false, "XXX","XY ","X ", 'Y', Items.stick, 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Shelf Wood5", new ItemStack(CustomItems.shelf, 2, 4), false, "XXX","XY ","X ", 'Y', Items.stick, 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Shelf Wood6", new ItemStack(CustomItems.shelf, 2, 5), false, "XXX","XY ","X ", 'Y', Items.stick, 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("Beam Wood1", new ItemStack(CustomItems.beam, 2, 0), false, "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,0));
|
||||
addRecipe("Beam Wood2", new ItemStack(CustomItems.beam, 2, 1), false, "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,1));
|
||||
addRecipe("Beam Wood3", new ItemStack(CustomItems.beam, 2, 2), false, "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,2));
|
||||
addRecipe("Beam Wood4", new ItemStack(CustomItems.beam, 2, 3), false, "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,3));
|
||||
addRecipe("Beam Wood5", new ItemStack(CustomItems.beam, 2, 4), false, "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,4));
|
||||
addRecipe("Beam Wood6", new ItemStack(CustomItems.beam, 2, 5), false, "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,5));
|
||||
|
||||
|
||||
addRecipe("Sign Wood1", new ItemStack(CustomItems.sign, 1, 0), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,0), 'Y', Items.iron_ingot);
|
||||
addRecipe("Sign Wood2", new ItemStack(CustomItems.sign, 1, 1), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,1), 'Y', Items.iron_ingot);
|
||||
addRecipe("Sign Wood3", new ItemStack(CustomItems.sign, 1, 2), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,2), 'Y', Items.iron_ingot);
|
||||
addRecipe("Sign Wood4", new ItemStack(CustomItems.sign, 1, 3), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,3), 'Y', Items.iron_ingot);
|
||||
addRecipe("Sign Wood5", new ItemStack(CustomItems.sign, 1, 4), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,4), 'Y', Items.iron_ingot);
|
||||
addRecipe("Sign Wood6", new ItemStack(CustomItems.sign, 1, 5), false, "YYY", "XXX", "XXX", 'X', new ItemStack(Blocks.planks,1,5), 'Y', Items.iron_ingot);
|
||||
|
||||
|
||||
addRecipe("Lamp", new ItemStack(CustomItems.lamp), false, "XXX","YZY","XXX", 'X', Items.iron_ingot, 'Y', Blocks.glass, 'Z', Blocks.torch);
|
||||
addRecipe("Candle", new ItemStack(CustomItems.candle), false, "XZX"," X ", 'X', Items.iron_ingot, 'Z', Blocks.torch);
|
||||
addRecipe("BigSign", new ItemStack(CustomItems.bigsign, 2), false, "XXX","XXX","XXX", 'X', Blocks.planks);
|
||||
@@ -159,7 +159,7 @@ public class RecipesDefault {
|
||||
addRecipe("Battle Axe5", CustomItems.battleAxeDiamond, false, "XX","XY"," Y", " Y", 'Y', Items.stick, 'X', Items.diamond);
|
||||
addRecipe("Battle Axe6", CustomItems.battleAxeBronze, false, "XX","XY"," Y", " Y", 'Y', Items.stick, 'X', CustomItems.bronze_ingot);
|
||||
addRecipe("Battle Axe7", CustomItems.battleAxeEmerald, false, "XX","XY"," Y", " Y", 'Y', Items.stick, 'X', Items.emerald);
|
||||
|
||||
|
||||
addRecipe("Halberd1", CustomItems.halberdWood, false, " X ","XYX"," Y ", " Y ", 'Y', Items.stick, 'X', Blocks.planks);
|
||||
addRecipe("Halberd2", CustomItems.halberdStone, false, " X ","XYX"," Y ", " Y ", 'Y', Items.stick, 'X', Blocks.cobblestone);
|
||||
addRecipe("Halberd3", CustomItems.halberdIron, false, " X ","XYX"," Y ", " Y ", 'Y', Items.stick, 'X', Items.iron_ingot);
|
||||
@@ -167,7 +167,7 @@ public class RecipesDefault {
|
||||
addRecipe("Halberd5", CustomItems.halberdDiamond, false, " X ","XYX"," Y ", " Y ", 'Y', Items.stick, 'X', Items.diamond);
|
||||
addRecipe("Halberd6", CustomItems.halberdBronze, false, " X ","XYX"," Y ", " Y ", 'Y', Items.stick, 'X', CustomItems.bronze_ingot);
|
||||
addRecipe("Halberd7", CustomItems.halberdEmerald, false, " X ","XYX"," Y ", " Y ", 'Y', Items.stick, 'X', Items.emerald);
|
||||
|
||||
|
||||
addRecipe("Glaive1", CustomItems.glaiveWood, false, "X "," Y "," Y ", " X", 'Y', Items.stick, 'X', Blocks.planks);
|
||||
addRecipe("Glaive2", CustomItems.glaiveStone, false, "X "," Y "," Y ", " X", 'Y', Items.stick, 'X', Blocks.cobblestone);
|
||||
addRecipe("Glaive3", CustomItems.glaiveIron, false, "X "," Y "," Y ", " X", 'Y', Items.stick, 'X', Items.iron_ingot);
|
||||
@@ -175,7 +175,7 @@ public class RecipesDefault {
|
||||
addRecipe("Glaive5", CustomItems.glaiveDiamond, false, "X "," Y "," Y ", " X", 'Y', Items.stick, 'X', Items.diamond);
|
||||
addRecipe("Glaive6", CustomItems.glaiveBronze, false, "X "," Y "," Y ", " X", 'Y', Items.stick, 'X', CustomItems.bronze_ingot);
|
||||
addRecipe("Glaive7", CustomItems.glaiveEmerald, false, "X "," Y "," Y ", " X", 'Y', Items.stick, 'X', Items.emerald);
|
||||
|
||||
|
||||
addRecipe("Trident1", CustomItems.tridentWood, false, "X X"," X "," Y ", " Y ", 'Y', Items.stick, 'X', Blocks.planks);
|
||||
addRecipe("Trident2", CustomItems.tridentStone, false, "X X"," X "," Y ", " Y ", 'Y', Items.stick, 'X', Blocks.cobblestone);
|
||||
addRecipe("Trident3", CustomItems.tridentIron, false, "X X"," X "," Y ", " Y ", 'Y', Items.stick, 'X', Items.iron_ingot);
|
||||
@@ -183,7 +183,7 @@ public class RecipesDefault {
|
||||
addRecipe("Trident5", CustomItems.tridentDiamond, false, "X X"," X "," Y ", " Y ", 'Y', Items.stick, 'X', Items.diamond);
|
||||
addRecipe("Trident6", CustomItems.tridentBronze, false, "X X"," X "," Y ", " Y ", 'Y', Items.stick, 'X', CustomItems.bronze_ingot);
|
||||
addRecipe("Trident7", CustomItems.tridentEmerald, false, "X X"," X "," Y ", " Y ", 'Y', Items.stick, 'X', Items.emerald);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user