mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 14:39:43 +00:00
Telegraph Scripting System
This commit is contained in:
1 parent
3e57b837aa
commit
bd7cafa482
34 files changed
+839
-51
No files matched your search
@@ -1,10 +1,10 @@
|
||||
package kamkeel.npcs.client.renderer;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@@ -0,0 +1,392 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ITelegraph;
|
||||
import noppes.npcs.api.ITelegraphInstance;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.handler.ITelegraphHandler;
|
||||
import noppes.npcs.scripted.ScriptTelegraph;
|
||||
import noppes.npcs.scripted.ScriptTelegraphInstance;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Server-side controller for managing telegraphs.
|
||||
* Provides factory methods for creating telegraphs and spawn methods for sending to clients.
|
||||
* Also manages saved telegraph presets.
|
||||
*/
|
||||
public class TelegraphController implements ITelegraphHandler {
|
||||
|
||||
public static TelegraphController Instance;
|
||||
|
||||
// Saved telegraph presets (name -> Telegraph)
|
||||
private HashMap<String, Telegraph> savedTelegraphs = new HashMap<>();
|
||||
|
||||
// Active server-side telegraph instances (for removal tracking)
|
||||
private ConcurrentHashMap<String, TelegraphInstance> activeInstances = new ConcurrentHashMap<>();
|
||||
|
||||
public TelegraphController() {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
Instance = new TelegraphController();
|
||||
Instance.load();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// INTERNAL SPAWN METHODS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Spawn a telegraph at a fixed position.
|
||||
*
|
||||
* @param telegraph The telegraph configuration
|
||||
* @param world The world
|
||||
* @param x X position
|
||||
* @param y Y position
|
||||
* @param z Z position
|
||||
* @param yaw Rotation yaw (for directional telegraphs like LINE/CONE)
|
||||
* @return The spawned telegraph instance
|
||||
*/
|
||||
public TelegraphInstance spawn(Telegraph telegraph, World world, double x, double y, double z, float yaw) {
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||
instance.setWorld(world);
|
||||
activeInstances.put(instance.getInstanceId(), instance);
|
||||
TelegraphSpawnPacket.sendToDimension(instance, world.provider.dimensionId);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a telegraph at a position with default yaw.
|
||||
*/
|
||||
public TelegraphInstance spawn(Telegraph telegraph, World world, double x, double y, double z) {
|
||||
return spawn(telegraph, world, x, y, z, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a telegraph that follows an entity.
|
||||
*
|
||||
* @param telegraph The telegraph configuration
|
||||
* @param entity The entity to follow
|
||||
* @return The spawned telegraph instance
|
||||
*/
|
||||
public TelegraphInstance spawn(Telegraph telegraph, Entity entity) {
|
||||
return spawn(telegraph, entity, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a telegraph that follows an entity with yaw.
|
||||
*/
|
||||
public TelegraphInstance spawn(Telegraph telegraph, Entity entity, float yaw) {
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, entity.posX, entity.posY, entity.posZ, yaw);
|
||||
instance.setWorld(entity.worldObj);
|
||||
instance.setEntityIdToFollow(entity.getEntityId());
|
||||
activeInstances.put(instance.getInstanceId(), instance);
|
||||
TelegraphSpawnPacket.sendToTracking(instance, entity);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a telegraph to a specific player only.
|
||||
*/
|
||||
public TelegraphInstance spawnToPlayer(Telegraph telegraph, EntityPlayerMP player, double x, double y, double z, float yaw) {
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||
instance.setWorld(player.worldObj);
|
||||
activeInstances.put(instance.getInstanceId(), instance);
|
||||
TelegraphSpawnPacket.send(instance, player);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a telegraph to all players on the server.
|
||||
*/
|
||||
public TelegraphInstance spawnToAll(Telegraph telegraph, World world, double x, double y, double z, float yaw) {
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||
instance.setWorld(world);
|
||||
activeInstances.put(instance.getInstanceId(), instance);
|
||||
TelegraphSpawnPacket.sendToAll(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a telegraph to all players tracking an entity.
|
||||
*/
|
||||
public TelegraphInstance spawnToTracking(Telegraph telegraph, Entity entity, double x, double y, double z, float yaw) {
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||
instance.setWorld(entity.worldObj);
|
||||
activeInstances.put(instance.getInstanceId(), instance);
|
||||
TelegraphSpawnPacket.sendToTracking(instance, entity);
|
||||
return instance;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// REMOVAL METHODS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Remove a telegraph by instance ID.
|
||||
*/
|
||||
public void remove(String instanceId) {
|
||||
TelegraphInstance instance = activeInstances.remove(instanceId);
|
||||
if (instance != null && instance.getWorld() != null) {
|
||||
TelegraphRemovePacket.sendToDimension(instanceId, instance.getDimensionId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a telegraph instance.
|
||||
*/
|
||||
public void remove(TelegraphInstance instance) {
|
||||
if (instance != null) {
|
||||
remove(instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a telegraph for a specific player only.
|
||||
*/
|
||||
public void removeFromPlayer(String instanceId, EntityPlayerMP player) {
|
||||
activeInstances.remove(instanceId);
|
||||
TelegraphRemovePacket.send(instanceId, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an active telegraph instance by ID.
|
||||
*/
|
||||
public TelegraphInstance getActiveInstance(String instanceId) {
|
||||
return activeInstances.get(instanceId);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// PRESET MANAGEMENT
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Save a telegraph preset (internal use).
|
||||
*
|
||||
* @param name The name for the preset
|
||||
* @param telegraph The telegraph configuration to save
|
||||
*/
|
||||
public void saveInternal(String name, Telegraph telegraph) {
|
||||
if (name == null || name.isEmpty() || telegraph == null) return;
|
||||
|
||||
telegraph.setId(name);
|
||||
savedTelegraphs.put(name, telegraph);
|
||||
saveTelegraphFile(name, telegraph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a saved telegraph preset by name (internal use).
|
||||
*
|
||||
* @param name The preset name
|
||||
* @return The telegraph configuration, or null if not found
|
||||
*/
|
||||
public Telegraph getInternal(String name) {
|
||||
return savedTelegraphs.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a saved telegraph preset.
|
||||
*
|
||||
* @param name The preset name
|
||||
*/
|
||||
public void delete(String name) {
|
||||
Telegraph removed = savedTelegraphs.remove(name);
|
||||
if (removed != null) {
|
||||
File file = new File(getDir(), name + ".json");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a preset exists.
|
||||
*/
|
||||
public boolean has(String name) {
|
||||
return savedTelegraphs.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all saved preset names.
|
||||
*/
|
||||
public String[] getSavedNames() {
|
||||
return savedTelegraphs.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// PERSISTENCE
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
private File getDir() {
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "telegraphs");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
savedTelegraphs.clear();
|
||||
LogWriter.info("Loading telegraph presets...");
|
||||
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) return;
|
||||
|
||||
for (File file : files) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json")) continue;
|
||||
try {
|
||||
Telegraph telegraph = new Telegraph();
|
||||
telegraph.readNBT(NBTJsonUtil.LoadFile(file));
|
||||
String name = file.getName().substring(0, file.getName().length() - 5);
|
||||
telegraph.setId(name);
|
||||
savedTelegraphs.put(name, telegraph);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error loading telegraph preset: " + file.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
LogWriter.info("Loaded " + savedTelegraphs.size() + " telegraph presets.");
|
||||
}
|
||||
|
||||
private void saveTelegraphFile(String name, Telegraph telegraph) {
|
||||
try {
|
||||
File dir = getDir();
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(dir, name + ".json_new");
|
||||
File file2 = new File(dir, name + ".json");
|
||||
|
||||
NBTJsonUtil.SaveFile(file, telegraph.writeNBT());
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error saving telegraph preset: " + name, e);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// ITelegraphHandler INTERFACE IMPLEMENTATION
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public ITelegraph createCircle(float radius) {
|
||||
return new ScriptTelegraph(Telegraph.circle(radius));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph createRing(float outerRadius, float innerRadius) {
|
||||
return new ScriptTelegraph(Telegraph.ring(outerRadius, innerRadius));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph createLine(float length, float width) {
|
||||
return new ScriptTelegraph(Telegraph.line(length, width));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph createCone(float length, float angle) {
|
||||
return new ScriptTelegraph(Telegraph.cone(length, angle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph createPoint() {
|
||||
return new ScriptTelegraph(Telegraph.point());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph create(String type) {
|
||||
if (type == null) return null;
|
||||
try {
|
||||
TelegraphType telegraphType = TelegraphType.valueOf(type.toUpperCase());
|
||||
Telegraph telegraph;
|
||||
switch (telegraphType) {
|
||||
case CIRCLE:
|
||||
telegraph = Telegraph.circle(3.0f);
|
||||
break;
|
||||
case RING:
|
||||
telegraph = Telegraph.ring(5.0f, 2.0f);
|
||||
break;
|
||||
case LINE:
|
||||
telegraph = Telegraph.line(5.0f, 2.0f);
|
||||
break;
|
||||
case CONE:
|
||||
telegraph = Telegraph.cone(5.0f, 45.0f);
|
||||
break;
|
||||
case POINT:
|
||||
telegraph = Telegraph.point();
|
||||
break;
|
||||
default:
|
||||
telegraph = Telegraph.circle(3.0f);
|
||||
}
|
||||
return new ScriptTelegraph(telegraph);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(ITelegraph telegraph, IWorld world, double x, double y, double z) {
|
||||
return spawn(telegraph, world, x, y, z, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(ITelegraph telegraph, IWorld world, double x, double y, double z, float yaw) {
|
||||
if (telegraph == null || world == null) return null;
|
||||
Telegraph internal = ((ScriptTelegraph) telegraph).getMCTelegraph();
|
||||
TelegraphInstance instance = spawn(internal, (World) world.getMCWorld(), x, y, z, yaw);
|
||||
return new ScriptTelegraphInstance(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(ITelegraph telegraph, IEntity entity) {
|
||||
return spawn(telegraph, entity, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(ITelegraph telegraph, IEntity entity, float yaw) {
|
||||
if (telegraph == null || entity == null) return null;
|
||||
Telegraph internal = ((ScriptTelegraph) telegraph).getMCTelegraph();
|
||||
TelegraphInstance instance = spawn(internal, (Entity) entity.getMCEntity(), yaw);
|
||||
return new ScriptTelegraphInstance(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph get(String name) {
|
||||
Telegraph telegraph = savedTelegraphs.get(name);
|
||||
return telegraph != null ? new ScriptTelegraph(new Telegraph(telegraph)) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String name, ITelegraph telegraph) {
|
||||
if (name == null || name.isEmpty() || telegraph == null) return;
|
||||
Telegraph internal = ((ScriptTelegraph) telegraph).getMCTelegraph();
|
||||
saveInternal(name, internal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ITelegraphInstance instance) {
|
||||
if (instance != null) {
|
||||
remove(instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package kamkeel.npcs.controllers.data.ability;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -4,9 +4,9 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
||||
@@ -4,8 +4,8 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -4,9 +4,9 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
@@ -4,8 +4,8 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
+6
-2
@@ -1,10 +1,10 @@
|
||||
package kamkeel.npcs.controllers.data.ability.telegraph;
|
||||
package kamkeel.npcs.controllers.data.telegraph;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Telegraph configuration - defines a visual warning shape.
|
||||
* Telegraphs warn players about incoming attacks.
|
||||
* Telegraphs warn players about incoming attacks or mark areas of effect.
|
||||
*/
|
||||
public class Telegraph {
|
||||
|
||||
@@ -146,6 +146,10 @@ public class Telegraph {
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph point() {
|
||||
return new Telegraph("", TelegraphType.POINT);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// GETTERS & SETTERS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
+24
-1
@@ -1,4 +1,4 @@
|
||||
package kamkeel.npcs.controllers.data.ability.telegraph;
|
||||
package kamkeel.npcs.controllers.data.telegraph;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -34,6 +34,10 @@ public class TelegraphInstance {
|
||||
// State
|
||||
private boolean isWarning = false;
|
||||
|
||||
// Server-side tracking (for removal)
|
||||
private transient World world;
|
||||
private transient int dimensionId;
|
||||
|
||||
public TelegraphInstance() {
|
||||
this.instanceId = UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
@@ -303,4 +307,23 @@ public class TelegraphInstance {
|
||||
public void setWarning(boolean warning) {
|
||||
isWarning = warning;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
if (world != null) {
|
||||
this.dimensionId = world.provider.dimensionId;
|
||||
}
|
||||
}
|
||||
|
||||
public int getDimensionId() {
|
||||
return dimensionId;
|
||||
}
|
||||
|
||||
public void setDimensionId(int dimensionId) {
|
||||
this.dimensionId = dimensionId;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package kamkeel.npcs.controllers.data.ability.telegraph;
|
||||
package kamkeel.npcs.controllers.data.telegraph;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class TelegraphManager {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// HELPER METHODS FOR ABILITIES
|
||||
// HELPER METHODS FOR SPAWNING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package kamkeel.npcs.controllers.data.ability.telegraph;
|
||||
package kamkeel.npcs.controllers.data.telegraph;
|
||||
|
||||
/**
|
||||
* Types of telegraph shapes for visual attack warnings.
|
||||
@@ -26,8 +26,8 @@ import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
||||
import kamkeel.npcs.network.packets.data.SwingPlayerArmPacket;
|
||||
import kamkeel.npcs.network.packets.data.UpdateAnimationsPacket;
|
||||
import kamkeel.npcs.network.packets.data.VillagerListPacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.TelegraphSpawnPacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiClosePacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiErrorPacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.GuiOpenBookPacket;
|
||||
|
||||
+17
-3
@@ -1,9 +1,9 @@
|
||||
package kamkeel.npcs.network.packets.data.ability;
|
||||
package kamkeel.npcs.network.packets.data.telegraph;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
@@ -16,7 +16,7 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Packet to remove a telegraph on the client.
|
||||
* Sent from server to client when an ability's telegraph should be removed early.
|
||||
* Sent from server to client when a telegraph should be removed early.
|
||||
*/
|
||||
public final class TelegraphRemovePacket extends AbstractPacket {
|
||||
public static final String packetName = "Data|TelegraphRemove";
|
||||
@@ -67,4 +67,18 @@ public final class TelegraphRemovePacket extends AbstractPacket {
|
||||
public static void sendToTracking(String instanceId, net.minecraft.entity.Entity entity) {
|
||||
PacketHandler.Instance.sendTracking(new TelegraphRemovePacket(instanceId), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send remove to all players in a dimension.
|
||||
*/
|
||||
public static void sendToDimension(String instanceId, int dimensionId) {
|
||||
PacketHandler.Instance.sendToDimension(new TelegraphRemovePacket(instanceId), dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send remove to all players on the server.
|
||||
*/
|
||||
public static void sendToAll(String instanceId) {
|
||||
PacketHandler.Instance.sendToAll(new TelegraphRemovePacket(instanceId));
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -1,10 +1,10 @@
|
||||
package kamkeel.npcs.network.packets.data.ability;
|
||||
package kamkeel.npcs.network.packets.data.telegraph;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
@@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Packet to spawn a telegraph on the client.
|
||||
* Sent from server to client when an ability creates a telegraph.
|
||||
* Sent from server to client when a telegraph is created.
|
||||
*/
|
||||
public final class TelegraphSpawnPacket extends AbstractPacket {
|
||||
public static final String packetName = "Data|TelegraphSpawn";
|
||||
@@ -78,4 +78,11 @@ public final class TelegraphSpawnPacket extends AbstractPacket {
|
||||
public static void sendToDimension(TelegraphInstance instance, int dimensionId) {
|
||||
PacketHandler.Instance.sendToDimension(new TelegraphSpawnPacket(instance), dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send telegraph to all players on the server.
|
||||
*/
|
||||
public static void sendToAll(TelegraphInstance instance) {
|
||||
PacketHandler.Instance.sendToAll(new TelegraphSpawnPacket(instance));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user