mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 17:47:32 +00:00
Fix Cloning Systems
This commit is contained in:
1 parent
9d65f3d20b
commit
3859bb70cb
8 files changed
+122
-5
No files matched your search
@@ -405,6 +405,8 @@ public class AbilityController implements IAbilityHandler {
|
||||
Ability original = customAbilities.get(originalName);
|
||||
if (original == null || original.isBuiltIn()) return null;
|
||||
|
||||
int originalCatId = customAbilityCatMap.getOrDefault(originalName, CategoryManager.UNCATEGORIZED_ID);
|
||||
|
||||
NBTTagCompound nbt = original.writeNBT(true);
|
||||
nbt.setString("id", UUID.randomUUID().toString());
|
||||
|
||||
@@ -416,6 +418,11 @@ public class AbilityController implements IAbilityHandler {
|
||||
clone.setName(name);
|
||||
|
||||
saveCustomAbility(clone);
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
customAbilityCatMap.put(clone.getName(), originalCatId);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@@ -770,6 +777,8 @@ public class AbilityController implements IAbilityHandler {
|
||||
ChainedAbility original = chainedAbilities.get(originalName);
|
||||
if (original == null) return null;
|
||||
|
||||
int originalCatId = chainedAbilityCatMap.getOrDefault(originalName, CategoryManager.UNCATEGORIZED_ID);
|
||||
|
||||
NBTTagCompound nbt = original.writeNBT(true);
|
||||
nbt.setString("Id", UUID.randomUUID().toString());
|
||||
|
||||
@@ -781,6 +790,11 @@ public class AbilityController implements IAbilityHandler {
|
||||
clone.setName(name);
|
||||
|
||||
saveChainedAbility(clone);
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
chainedAbilityCatMap.put(clone.getName(), originalCatId);
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ import kamkeel.npcs.network.packets.request.ability.CustomAbilityRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationClonePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.BuiltInAnimationGetPacket;
|
||||
@@ -499,6 +500,7 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new AnimationGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new AnimationRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new AnimationSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new AnimationClonePacket());
|
||||
REQUEST_PACKET.registerPacket(new BuiltInAnimationGetPacket());
|
||||
|
||||
// Moving Path
|
||||
|
||||
@@ -93,6 +93,7 @@ public enum EnumRequestPacket {
|
||||
AnimationGet,
|
||||
AnimationRemove,
|
||||
AnimationSave,
|
||||
AnimationClone,
|
||||
BuiltInAnimationGet,
|
||||
|
||||
RemoteNpcsGet,
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package kamkeel.npcs.network.packets.request.animation;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class AnimationClonePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|AnimationClone";
|
||||
|
||||
private int id;
|
||||
|
||||
public AnimationClonePacket() {
|
||||
}
|
||||
|
||||
public AnimationClonePacket(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.AnimationClone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_ANIMATION;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(packetName, EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
int animationId = in.readInt();
|
||||
Animation clone = AnimationController.getInstance().cloneAnimation(animationId);
|
||||
if (clone != null) {
|
||||
NoppesUtilServer.sendAnimationDataAll((EntityPlayerMP) player);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, clone.writeToNBT());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.global;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationClonePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.BuiltInAnimationGetPacket;
|
||||
@@ -169,11 +170,7 @@ public class GuiAnimationDirectory extends GuiDirectoryCategorized {
|
||||
protected void onCloneItem() {
|
||||
if (showingBuiltIn || currentIsBuiltIn) return;
|
||||
if (animation != null && animation.id >= 0) {
|
||||
Animation clone = new Animation();
|
||||
clone.readFromNBT(animation.writeToNBT());
|
||||
clone.id = -1;
|
||||
while (itemData.containsKey(clone.name)) clone.name += "_";
|
||||
PacketClient.sendClient(new AnimationSavePacket(clone.writeToNBT()));
|
||||
PacketClient.sendClient(new AnimationClonePacket(animation.id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,6 +311,28 @@ public class AnimationController implements IAnimationHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Animation cloneAnimation(int originalId) {
|
||||
Animation original = animations.get(originalId);
|
||||
if (original == null || original instanceof BuiltInAnimation) return null;
|
||||
|
||||
int originalCatId = categoryManager.getItemCategory(originalId);
|
||||
|
||||
Animation clone = new Animation();
|
||||
clone.readFromNBT(original.writeToNBT());
|
||||
clone.id = getUnusedId();
|
||||
|
||||
String name = clone.name;
|
||||
while (hasName(name)) name += "_";
|
||||
clone.name = name;
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
categoryManager.registerItem(clone.id, originalCatId);
|
||||
}
|
||||
|
||||
saveAnimation(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
public void delete(String name) {
|
||||
Animation delete = getAnimationFromName(name);
|
||||
if (delete != null) {
|
||||
|
||||
@@ -712,6 +712,8 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
CustomEffect original = getCustomEffects().get(originalId);
|
||||
if (original == null) return null;
|
||||
|
||||
int originalCatId = categoryManager.getItemCategory(originalId);
|
||||
|
||||
NBTTagCompound nbt = original.writeToNBT(true);
|
||||
int newId = getUnusedId();
|
||||
nbt.setInteger("ID", newId);
|
||||
@@ -723,6 +725,10 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
while (has(name)) name += "_";
|
||||
clone.name = name;
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
categoryManager.registerItem(newId, originalCatId);
|
||||
}
|
||||
|
||||
saveEffect(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
@@ -245,6 +245,8 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
LinkedItem original = linkedItems.get(originalId);
|
||||
if (original == null) return null;
|
||||
|
||||
int originalCatId = categoryManager.getItemCategory(originalId);
|
||||
|
||||
NBTTagCompound nbt = original.writeToNBT(true);
|
||||
int newId = getUnusedId();
|
||||
nbt.setInteger("Id", newId);
|
||||
@@ -256,6 +258,10 @@ public class LinkedItemController implements ILinkedItemHandler {
|
||||
while (hasName(name)) name += "_";
|
||||
clone.name = name;
|
||||
|
||||
if (originalCatId > CategoryManager.UNCATEGORIZED_ID) {
|
||||
categoryManager.registerItem(newId, originalCatId);
|
||||
}
|
||||
|
||||
saveLinkedItem(clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user