Sync Recipes

This commit is contained in:
Kam committed 2025-01-30 09:22:43 -05:00
1 parent 90605ee808
commit 5d308b1f56
20 files changed
+174 -190

No files matched your search

+4 -1
View File
@@ -5,6 +5,9 @@ import foxz.commandhelper.annotations.Command;
import foxz.commandhelper.annotations.SubCommand;
import foxz.commandhelper.permissions.OpOnly;
import foxz.commandhelper.permissions.PlayerOnly;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumConfigOperation;
import kamkeel.npcs.network.packets.client.ConfigCommandPacket;
import net.minecraft.block.Block;
import net.minecraft.block.BlockIce;
import net.minecraft.block.BlockLeavesBase;
@@ -207,6 +210,6 @@ public class CmdConfig extends ChMcLogger {
for(int i = 0; i < args.length; i++){
font += " " + args[i];
}
Server.sendData((EntityPlayerMP)this.pcParam, EnumPacketClient.CONFIG, 0, font.trim(), size);
PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP)this.pcParam);
}
}
@@ -11,7 +11,6 @@ import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.client.EntityUtil;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogOption;
import noppes.npcs.controllers.data.PlayerData;
@@ -1,6 +1,9 @@
package kamkeel.npcs.command;
import foxz.utils.Market;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumConfigOperation;
import kamkeel.npcs.network.packets.client.ConfigCommandPacket;
import net.minecraft.block.Block;
import net.minecraft.block.BlockIce;
import net.minecraft.block.BlockLeavesBase;
@@ -291,8 +294,7 @@ public class ConfigCommand extends CommandKamkeelBase {
for(int i = 0; i < args.length; i++){
font += " " + args[i];
}
Server.sendData((EntityPlayerMP)sender, EnumPacketClient.CONFIG, 0, font.trim(), size);
PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP)sender);
}
}
@@ -11,7 +11,6 @@ import noppes.npcs.constants.EnumAvailabilityDialog;
import noppes.npcs.constants.EnumAvailabilityQuest;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Availability;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogOption;
@@ -10,10 +10,13 @@ import kamkeel.npcs.network.enums.EnumSyncType;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.Server;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.FactionController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.data.*;
import java.util.HashMap;
@@ -45,10 +48,48 @@ public class SyncMaster {
questCategoriesNBT()
), player);
// 4) Workbench Recipes
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
workbenchNBT()
), player);
// 5) Carpentry Recipes
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
carpentryNBT()
), player);
DBCAddon.instance.syncPlayer(player);
syncPlayerData(player, false);
}
public static NBTTagCompound workbenchNBT(){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(RecipeCarpentry recipe : controller.globalRecipes.values()){
list.appendTag(recipe.writeNBT());
}
compound.setTag("recipes", list);
return compound;
}
public static NBTTagCompound carpentryNBT(){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(RecipeCarpentry recipe : controller.carpentryRecipes.values()){
list.appendTag(recipe.writeNBT());
}
compound.setTag("recipes", list);
return compound;
}
public static NBTTagCompound factionsNBT(){
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
@@ -144,6 +185,24 @@ public class SyncMaster {
));
}
public static void syncAllWorkbenchRecipes() {
PacketHandler.Instance.sendToAll(new LargeSyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
workbenchNBT()
));
}
public static void syncAllCarpentryRecipes() {
PacketHandler.Instance.sendToAll(new LargeSyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
carpentryNBT()
));
}
@SideOnly(Side.CLIENT)
public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) {
switch (enumSyncType){
@@ -238,6 +297,36 @@ public class SyncMaster {
ClientCacheHandler.playerData.setSyncNBTFull(fullCompound);
break;
}
case WORKBENCH_RECIPES: {
NBTTagList list = fullCompound.getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
RecipeController.syncRecipes.put(recipe.id,recipe);
}
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
break;
}
case CARPENTRY_RECIPES: {
NBTTagList list = fullCompound.getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
RecipeController.syncRecipes.put(recipe.id,recipe);
}
RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
break;
}
}
}
@@ -60,6 +60,9 @@ public final class PacketHandler {
CLIENT_PACKET.registerPacket(new RolePacket());
CLIENT_PACKET.registerPacket(new GuiTeleporterPacket());
CLIENT_PACKET.registerPacket(new SoundManagementPacket());
CLIENT_PACKET.registerPacket(new ParticlePacket());
CLIENT_PACKET.registerPacket(new ScriptedParticlePacket());
CLIENT_PACKET.registerPacket(new ConfigCommandPacket());
// Client | GUI Packets
CLIENT_PACKET.registerPacket(new GuiClosePacket());
@@ -70,10 +73,6 @@ public final class PacketHandler {
// Client | NPC Packets
CLIENT_PACKET.registerPacket(new DeleteNpcPacket());
// Client | Other
CLIENT_PACKET.registerPacket(new ParticlePacket());
CLIENT_PACKET.registerPacket(new ScriptedParticlePacket());
}
private void registerChannels() {
@@ -0,0 +1,5 @@
package kamkeel.npcs.network.enums;
public enum EnumConfigOperation {
FONT,
}
@@ -7,5 +7,7 @@ public enum EnumSyncType {
QUEST,
QUEST_CATEGORY,
PLAYERDATA,
MAGIC
MAGIC,
WORKBENCH_RECIPES,
CARPENTRY_RECIPES
}
@@ -7,6 +7,8 @@ import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumClientPacket;
import kamkeel.npcs.network.enums.EnumConfigOperation;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
@@ -20,8 +22,16 @@ import java.io.IOException;
public final class ConfigCommandPacket extends AbstractPacket {
public static final String packetName = "Client|ConfigCommand";
private EnumConfigOperation configOperation;
private Object[] objects;
public ConfigCommandPacket() {}
public ConfigCommandPacket(EnumConfigOperation operation, Object... obs) {
this.configOperation = operation;
this.objects = obs;
}
@Override
public Enum getType() {
return EnumClientPacket.CONFIG;
@@ -34,15 +44,16 @@ public final class ConfigCommandPacket extends AbstractPacket {
@Override
public void sendData(ByteBuf out) throws IOException {
// TODO: Send Packet
out.writeInt(this.configOperation.ordinal());
ByteBufUtils.fillBuffer(out, objects);
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
int configType = in.readInt();
if (configType == 0) { // Font Configuration
String font = Server.readString(in);
EnumConfigOperation configType = EnumConfigOperation.values()[in.readInt()];
if (configType == EnumConfigOperation.FONT) { // Font Configuration
String font = ByteBufUtils.readString(in);
int size = in.readInt();
if (!font.isEmpty()) {
ConfigClient.FontType = font;
@@ -9,9 +9,7 @@ import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumClientPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.controllers.SyncController;
import java.io.IOException;
@@ -8,7 +8,6 @@ import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumClientPacket;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.controllers.RecipeController;
import java.io.IOException;
@@ -36,7 +35,7 @@ public final class SyncRecipesCarpentryBenchPacket extends AbstractPacket {
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes.clear();
}
}
@@ -591,7 +591,7 @@ public class NoppesUtilServer {
}
}
else{
for(RecipeCarpentry recipe : RecipeController.Instance.anvilRecipes.values()){
for(RecipeCarpentry recipe : RecipeController.Instance.carpentryRecipes.values()){
map.put(recipe.name, recipe.id);
}
}
@@ -3,9 +3,13 @@ package noppes.npcs;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import kamkeel.npcs.controllers.SyncMaster;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumSoundOperation;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.packets.client.SoundManagementPacket;
import kamkeel.npcs.network.packets.client.large.LargeSyncPacket;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@@ -24,13 +28,11 @@ import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
@@ -48,7 +50,6 @@ import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.items.ItemExcalibur;
import noppes.npcs.items.ItemShield;
import noppes.npcs.items.ItemSoulstoneEmpty;
import noppes.npcs.quests.QuestItem;
import noppes.npcs.quests.QuestKill;
import noppes.npcs.roles.RoleFollower;
@@ -197,48 +198,20 @@ public class ServerEventsHandler {
}
if(block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
int i = 0;
for(RecipeCarpentry recipe : controller.globalRecipes.values()){
list.appendTag(recipe.writeNBT());
i++;
if(i % 10 == 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
list = new NBTTagList();
}
}
if(i % 10 != 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
}
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_WORKBENCH);
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
SyncMaster.workbenchNBT()
), (EntityPlayerMP) player);
}
if(block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
int i = 0;
for(RecipeCarpentry recipe : controller.anvilRecipes.values()){
list.appendTag(recipe.writeNBT());
i++;
if(i % 10 == 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
list = new NBTTagList();
}
}
if(i % 10 != 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
}
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_CARPENTRYBENCH);
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
SyncMaster.carpentryNBT()
), (EntityPlayerMP) player);
}
if((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK){
ItemStack item = player.inventory.getCurrentItem();
@@ -11,7 +11,6 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import noppes.npcs.client.AnalyticsTracking;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.PlayerData;
import java.net.InetAddress;
@@ -9,35 +9,23 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.village.MerchantRecipeList;
import noppes.npcs.*;
import noppes.npcs.client.ClientProxy.FontContainer;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.controllers.ScriptClientSound;
import noppes.npcs.client.controllers.ScriptSoundController;
import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.player.GuiBook;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.controllers.data.RecipeCarpentry;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
import java.util.HashMap;
public class PacketHandlerClient extends PacketHandlerServer{
@@ -53,30 +41,7 @@ public class PacketHandlerClient extends PacketHandlerServer{
}
private void client(ByteBuf buffer, final EntityPlayer player, EnumPacketClient type) throws IOException{
if(type == EnumPacketClient.SYNCRECIPES_ADD){
NBTTagList list = Server.readNBT(buffer).getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
RecipeController.syncRecipes.put(recipe.id,recipe);
}
}
else if(type == EnumPacketClient.SYNCRECIPES_WORKBENCH){
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.SYNCRECIPES_CARPENTRYBENCH){
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.SYNC_CONFIG){
NBTTagCompound configNBT = Server.readNBT(buffer);
SyncController.receiveConfigs(configNBT);
}
else if(type == EnumPacketClient.MARK_DATA){
if(type == EnumPacketClient.MARK_DATA){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(!(entity instanceof EntityNPCInterface))
return;
@@ -92,12 +57,6 @@ public class PacketHandlerClient extends PacketHandlerServer{
else if(type == EnumPacketClient.QUEST_COMPLETION){
NoppesUtil.guiQuestCompletion(player, Server.readNBT(buffer));
}
else if(type == EnumPacketClient.EDIT_NPC){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
NoppesUtil.setLastNpc((EntityNPCInterface) entity);
}
else if(type == EnumPacketClient.UPDATE_NPC){
NBTTagCompound compound = Server.readNBT(buffer);
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId"));
@@ -118,12 +77,6 @@ public class PacketHandlerClient extends PacketHandlerServer{
EnumGuiType gui = EnumGuiType.values()[buffer.readInt()];
CustomNpcs.proxy.openGui(NoppesUtil.getLastNpc(), gui, buffer.readInt(), buffer.readInt(), buffer.readInt());
}
else if(type == EnumPacketClient.DELETE_NPC){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
((EntityNPCInterface)entity).delete();
}
else if(type == EnumPacketClient.SCROLL_SELECTED){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null || !(gui instanceof IScrollData))
@@ -193,28 +146,6 @@ public class PacketHandlerClient extends PacketHandlerServer{
NoppesUtil.openGUI(player, new GuiBook(player, ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)), x, y, z));
}
else if(type == EnumPacketClient.CONFIG){
int config = buffer.readInt();
if(config == 0){//Font
String font = Server.readString(buffer);
int size = buffer.readInt();
if(!font.isEmpty()){
ConfigClient.FontType = font;
ConfigClient.FontSize = size;
ClientProxy.Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize);
ConfigClient.FontTypeProperty.set(ConfigClient.FontType);
ConfigClient.FontSizeProperty.set(ConfigClient.FontSize);
if(ConfigClient.config.hasChanged()){
ConfigClient.config.save();
}
player.addChatMessage(new ChatComponentTranslation("Font set to %s", ClientProxy.Font.getName()));
}
else
player.addChatMessage(new ChatComponentTranslation("Current font is %s", ClientProxy.Font.getName()));
}
}
else if(type == EnumPacketClient.ISGUIOPEN){
boolean isGUIOpen = Minecraft.getMinecraft().currentScreen != null;
@@ -15,7 +15,7 @@ public class GuiNpcCarpentryBench extends GuiContainerNPCInterface
private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/carpentry.png");
private ContainerCarpentryBench container;
private GuiNpcButton button;
public GuiNpcCarpentryBench(ContainerCarpentryBench container)
{
super(null,container);
@@ -38,7 +38,7 @@ public class GuiNpcCarpentryBench extends GuiContainerNPCInterface
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
button.enabled = RecipeController.Instance != null && !RecipeController.Instance.anvilRecipes.isEmpty();
button.enabled = RecipeController.Instance != null && !RecipeController.Instance.carpentryRecipes.isEmpty();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(resource);
int l = (width - xSize) / 2;
@@ -33,7 +33,7 @@ public class GuiRecipes extends GuiNPCInterface
this.xSize = 256;
setBackground("recipes.png");
this.closeOnEsc = true;
recipes.addAll(RecipeController.Instance.anvilRecipes.values());
recipes.addAll(RecipeController.Instance.carpentryRecipes.values());
}
@Override
public void initGui(){
@@ -47,7 +47,7 @@ public class GuiRecipes extends GuiNPCInterface
addButton(this.left = new GuiButtonNextPage(1, guiLeft + 150, guiTop + 164, true));
addButton(this.right = new GuiButtonNextPage(2, guiLeft + 80, guiTop + 164, false));
updateButton();
}
private void updateButton(){
@@ -67,10 +67,10 @@ public class GuiRecipes extends GuiNPCInterface
private List<IRecipe> getSearchList(){
if(search.isEmpty()){
return new ArrayList<IRecipe>(RecipeController.Instance.anvilRecipes.values());
return new ArrayList<IRecipe>(RecipeController.Instance.carpentryRecipes.values());
}
List<IRecipe> list = new ArrayList<IRecipe>();
for(IRecipe recipe : RecipeController.Instance.anvilRecipes.values()){
for(IRecipe recipe : RecipeController.Instance.carpentryRecipes.values()){
if(recipe.getRecipeOutput() == null)
continue;
@@ -96,12 +96,12 @@ public class GuiRecipes extends GuiNPCInterface
page++;
updateButton();
}
@Override
public void drawScreen(int xMouse, int yMouse, float f){
super.drawScreen(xMouse, yMouse, f);
mc.renderEngine.bindTexture(resource);
label.label = page + 1 + "/" + MathHelper.ceiling_float_int(recipes.size() / 4f);
label.x = guiLeft + (256 - Minecraft.getMinecraft().fontRenderer.getStringWidth(label.label)) / 2;
for(int i = 0; i < 4; i++){
@@ -165,11 +165,11 @@ public class GuiRecipes extends GuiNPCInterface
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, item, x, y);
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, item, x, y);
itemRender.zLevel = 0.0F;
RenderHelper.disableStandardItemLighting();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
private void drawOverlay(ItemStack item, int x, int y, int xMouse, int yMouse){
if (this.func_146978_c(x - guiLeft, y - guiTop, 16, 16, xMouse, yMouse)){
this.renderToolTip(item, xMouse, yMouse);
@@ -187,4 +187,4 @@ public class GuiRecipes extends GuiNPCInterface
@Override
public void save() {
}
}
}
@@ -2,15 +2,11 @@ package
noppes.npcs.constants;
public enum EnumPacketClient {
SYNCRECIPES_ADD,
SYNCRECIPES_WORKBENCH,
DIALOG,
QUEST_COMPLETION,
EDIT_NPC,
UPDATE_NPC,
ROLE,
GUI,
DELETE_NPC,
SCROLL_SELECTED,
GUI_REDSTONE,
GUI_WAYPOINT,
@@ -18,11 +14,9 @@ public enum EnumPacketClient {
GUI_ERROR,
GUI_CLOSE,
VILLAGER_LIST,
SYNCRECIPES_CARPENTRYBENCH,
CLONE,
TELEPORTER,
OPEN_BOOK,
CONFIG,
ISGUIOPEN,
SCRIPT_OVERLAY_DATA,
SCRIPT_OVERLAY_CLOSE,
@@ -34,6 +28,5 @@ public enum EnumPacketClient {
DISABLE_MOUSE_INPUT,
SYNC_WEAPON,
MARK_DATA,
SYNC_CONFIG,
PARTY_DATA
}
@@ -1,5 +1,6 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncMaster;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
@@ -21,7 +22,7 @@ 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 HashMap<Integer,RecipeCarpentry> carpentryRecipes = new HashMap<Integer, RecipeCarpentry>();
public static RecipeController Instance;
public static final int version = 1;
@@ -59,7 +60,7 @@ public class RecipeController implements IRecipeHandler {
}
else{
globalRecipes.clear();
anvilRecipes.clear();
carpentryRecipes.clear();
loadDefaultRecipes(-1);
}
} catch (Exception e) {
@@ -99,7 +100,7 @@ public class RecipeController implements IRecipeHandler {
nextId = recipe.id;
}
}
this.anvilRecipes = anvilRecipes;
this.carpentryRecipes = anvilRecipes;
this.globalRecipes = globalRecipes;
loadDefaultRecipes(nbttagcompound1.getInteger("Version"));
}
@@ -110,7 +111,7 @@ 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());
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
@@ -141,7 +142,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,8 +152,8 @@ 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;
}
@@ -171,12 +172,12 @@ 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);
@@ -192,7 +193,7 @@ public class RecipeController implements IRecipeHandler {
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;
}
@@ -203,8 +204,14 @@ public class RecipeController implements IRecipeHandler {
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)
SyncMaster.syncAllWorkbenchRecipes();
RecipeCarpentry carpentry = carpentryRecipes.remove(recipe.id);
if(carpentry != null)
SyncMaster.syncAllWorkbenchRecipes();
saveCategories();
reloadGlobalRecipes(globalRecipes);
return recipe;
@@ -212,7 +219,7 @@ public class RecipeController implements IRecipeHandler {
public void addRecipe(RecipeCarpentry recipeAnvil) {
recipeAnvil.id = getUniqueId();
if(!recipeAnvil.isGlobal)
RecipeController.Instance.anvilRecipes.put(recipeAnvil.id, recipeAnvil);
RecipeController.Instance.carpentryRecipes.put(recipeAnvil.id, recipeAnvil);
else{
RecipeController.Instance.globalRecipes.put(recipeAnvil.id, recipeAnvil);
}
@@ -223,7 +230,7 @@ public class RecipeController implements IRecipeHandler {
}
public List<IRecipe> getCarpentryList() {
return new ArrayList(this.anvilRecipes.values());
return new ArrayList(this.carpentryRecipes.values());
}
public void addRecipe(String name, boolean global, ItemStack result, Object... objects) {
@@ -1,25 +0,0 @@
package noppes.npcs.controllers;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.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.config.ConfigMain;
import noppes.npcs.constants.EnumPacketClient;
public class SyncController {
public static void syncConfigs(EntityPlayerMP player){
NBTTagCompound nbtTagCompound = new NBTTagCompound();
nbtTagCompound.setBoolean("Profiles", true);
Server.sendData(player, EnumPacketClient.SYNC_CONFIG, nbtTagCompound);
}
public static void receiveConfigs(NBTTagCompound compound){
ConfigMain.EnableProfiles = compound.getBoolean("Profiles");
}
}