mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 15:29:54 +00:00
New Anvil Recipe System
This commit is contained in:
1 parent
9cda5503ed
commit
48dd7bedea
15 files changed
+592
-221
No files matched your search
@@ -62,6 +62,13 @@ public class SyncController {
|
||||
carpentryNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.ANVIL_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
anvilNBT()
|
||||
), player);
|
||||
|
||||
DBCAddon.instance.syncPlayer(player);
|
||||
syncPlayerData(player, false);
|
||||
}
|
||||
@@ -88,6 +95,17 @@ public class SyncController {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound anvilNBT(){
|
||||
RecipeController controller = RecipeController.Instance;
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for(RecipeAnvil recipe : controller.anvilRecipes.values()){
|
||||
list.appendTag(recipe.writeNBT());
|
||||
}
|
||||
compound.setTag("recipes", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound factionsNBT(){
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
@@ -201,6 +219,15 @@ public class SyncController {
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllAnvilRecipes() {
|
||||
PacketHandler.Instance.sendToAll(new SyncPacket(
|
||||
EnumSyncType.ANVIL_RECIPES,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
anvilNBT()
|
||||
));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) {
|
||||
switch (enumSyncType){
|
||||
@@ -325,6 +352,21 @@ public class SyncController {
|
||||
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
break;
|
||||
}
|
||||
case ANVIL_RECIPES: {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if(list == null)
|
||||
return;
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
RecipeAnvil recipe = RecipeAnvil.read(list.getCompoundTagAt(i));
|
||||
RecipeController.syncAnvilRecipes.put(recipe.id, recipe);
|
||||
}
|
||||
|
||||
RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes;
|
||||
RecipeController.syncAnvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,5 +9,6 @@ public enum EnumSyncType {
|
||||
PLAYERDATA,
|
||||
MAGIC,
|
||||
WORKBENCH_RECIPES,
|
||||
CARPENTRY_RECIPES
|
||||
CARPENTRY_RECIPES,
|
||||
ANVIL_RECIPES,
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -21,9 +22,11 @@ public final class RecipeGetPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|RecipeGet";
|
||||
|
||||
private int recipeId;
|
||||
private boolean isAnvil = false;
|
||||
|
||||
public RecipeGetPacket(int recipeId) {
|
||||
public RecipeGetPacket(int recipeId, boolean anvil) {
|
||||
this.recipeId = recipeId;
|
||||
this.isAnvil = anvil;
|
||||
}
|
||||
|
||||
public RecipeGetPacket() {}
|
||||
@@ -43,6 +46,7 @@ public final class RecipeGetPacket extends AbstractPacket {
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(recipeId);
|
||||
out.writeBoolean(this.isAnvil);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,7 +56,13 @@ public final class RecipeGetPacket extends AbstractPacket {
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
int id = in.readInt();
|
||||
RecipeCarpentry recipe = RecipeController.Instance.getRecipe(id);
|
||||
NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe);
|
||||
boolean anvil = in.readBoolean();
|
||||
if(anvil){
|
||||
RecipeAnvil recipe = RecipeController.Instance.getAnvilRecipe(id);
|
||||
NoppesUtilServer.setRecipeAnvilGui((EntityPlayerMP) player, recipe);
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeController.Instance.getRecipe(id);
|
||||
NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -22,13 +23,14 @@ public final class RecipeRemovePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|RecipeRemove";
|
||||
|
||||
private int recipeId;
|
||||
private boolean isAnvil;
|
||||
|
||||
public RecipeRemovePacket(int recipeId) {
|
||||
public RecipeRemovePacket(int recipeId, boolean isAnvil) {
|
||||
this.recipeId = recipeId;
|
||||
this.isAnvil = isAnvil;
|
||||
}
|
||||
|
||||
public RecipeRemovePacket() {
|
||||
}
|
||||
public RecipeRemovePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
@@ -49,6 +51,7 @@ public final class RecipeRemovePacket extends AbstractPacket {
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(recipeId);
|
||||
out.writeBoolean(isAnvil);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,8 +61,15 @@ public final class RecipeRemovePacket extends AbstractPacket {
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
int id = in.readInt();
|
||||
RecipeCarpentry recipe = RecipeController.Instance.delete(id);
|
||||
NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4);
|
||||
NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, new RecipeCarpentry(""));
|
||||
boolean anvil = in.readBoolean();
|
||||
if(anvil){
|
||||
RecipeAnvil recipe = RecipeController.Instance.deleteAnvil(id);
|
||||
NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, 1);
|
||||
NoppesUtilServer.setRecipeAnvilGui((EntityPlayerMP) player, new RecipeAnvil());
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeController.Instance.delete(id);
|
||||
NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4);
|
||||
NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, new RecipeCarpentry(""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.data.RecipeAnvil;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -58,9 +59,16 @@ public final class RecipeSavePacket extends AbstractPacket {
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(in);
|
||||
RecipeCarpentry recipe = RecipeController.Instance.saveRecipe(compound);
|
||||
NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4);
|
||||
NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe);
|
||||
if(compound.hasKey("IsAnvil")){
|
||||
RecipeAnvil recipe = RecipeController.Instance.saveAnvilRecipe(compound);
|
||||
NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, 1);
|
||||
NoppesUtilServer.setRecipeAnvilGui((EntityPlayerMP) player, recipe);
|
||||
} else {
|
||||
RecipeCarpentry recipe = RecipeController.Instance.saveRecipe(compound);
|
||||
NoppesUtilServer.sendRecipeData((EntityPlayerMP) player, recipe.isGlobal ? 3 : 4);
|
||||
NoppesUtilServer.setRecipeGui((EntityPlayerMP) player, recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user