Search in sources :

Example 1 with JsonItemCallback

use of betterquesting.client.gui.editors.json.callback.JsonItemCallback in project BetterQuesting by Funwayguy.

the class ScrollingJsonEntry method onActionPerformed.

public void onActionPerformed(GuiButtonThemed btn) {
    if (// Delete Entry
    je != null && btn.id == 3) {
        if (json.getId() == 10) {
            ((NBTTagCompound) json).removeTag(key);
            host.getEntryList().remove(this);
            host.refresh();
            return;
        } else if (json.getId() == 9) {
            ((NBTTagList) json).removeTag(idx);
            host.getEntryList().remove(this);
            host.refresh();
            return;
        }
    }
    if (btn.id == 2) {
        if (json.getId() == 9) {
            mc.displayGuiScreen(new GuiJsonAdd(mc.currentScreen, (NBTTagList) json, idx));
            return;
        } else if (json.getId() == 10) {
            mc.displayGuiScreen(new GuiJsonAdd(mc.currentScreen, (NBTTagCompound) json));
            return;
        }
    } else if (je != null && je.getId() == 10) {
        NBTTagCompound jo = (NBTTagCompound) je;
        IJsonDoc childDoc = jDoc == null ? null : jDoc.getChildDoc(key);
        if (// Main
        btn.id == 0) {
            if (!(JsonHelper.isItem(jo) || JsonHelper.isFluid(jo) || JsonHelper.isEntity(jo))) {
                mc.displayGuiScreen(new GuiJsonEditor(mc.currentScreen, jo, childDoc));
            } else if (JsonHelper.isItem(jo)) {
                mc.displayGuiScreen(new GuiJsonItemSelection(mc.currentScreen, new JsonItemCallback(jo), JsonHelper.JsonToItemStack(jo)));
            } else if (JsonHelper.isFluid(jo)) {
                mc.displayGuiScreen(new GuiJsonFluidSelection(mc.currentScreen, new JsonFluidCallback(jo), JsonHelper.JsonToFluidStack(jo)));
            } else if (JsonHelper.isEntity(jo)) {
                mc.displayGuiScreen(new GuiJsonEntitySelection(mc.currentScreen, new JsonEntityCallback(jo), JsonHelper.JsonToEntity(jo, mc.world, true)));
            }
        } else if (// Advanced
        btn.id == 1) {
            mc.displayGuiScreen(new GuiJsonTypeMenu(mc.currentScreen, jo));
        }
    } else if (je != null && je.getId() == 9) {
        mc.displayGuiScreen(new GuiJsonEditor(mc.currentScreen, (NBTTagList) je, jDoc));
    }
/* else if(je != null && je.isJsonPrimitive() && je.getAsJsonPrimitive().isBoolean())
		{
			if(json.isJsonObject())
			{
				json.getAsJsonObject().addProperty(key, !je.getAsBoolean());
				host.refresh();
				return;
			} else if(json.isJsonArray())
			{
				JsonHelper.GetUnderlyingArray(json.getAsJsonArray()).set(idx, new JsonPrimitive(!je.getAsBoolean()));
				host.refresh();
				return;
			}
		}*/
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) GuiJsonAdd(betterquesting.client.gui.editors.json.GuiJsonAdd) JsonEntityCallback(betterquesting.client.gui.editors.json.callback.JsonEntityCallback) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IJsonDoc(betterquesting.api.jdoc.IJsonDoc) JsonFluidCallback(betterquesting.client.gui.editors.json.callback.JsonFluidCallback) GuiJsonItemSelection(betterquesting.client.gui.editors.json.GuiJsonItemSelection) GuiJsonEntitySelection(betterquesting.client.gui.editors.json.GuiJsonEntitySelection) JsonItemCallback(betterquesting.client.gui.editors.json.callback.JsonItemCallback) GuiJsonTypeMenu(betterquesting.client.gui.editors.json.GuiJsonTypeMenu) GuiJsonFluidSelection(betterquesting.client.gui.editors.json.GuiJsonFluidSelection)

Example 2 with JsonItemCallback

use of betterquesting.client.gui.editors.json.callback.JsonItemCallback in project BetterQuesting by Funwayguy.

the class GuiJsonTypeMenu method initGui.

@Override
public void initGui() {
    super.initGui();
    fluid = null;
    stack = null;
    entity = null;
    if (json != null) {
        if (// Must have at least these 3 to be considered a valid 'item'
        JsonHelper.isItem(json)) {
            stack = JsonHelper.JsonToItemStack(json);
        }
        if (stack == null && JsonHelper.isEntity(json)) {
            entity = EntityList.createEntityFromNBT(json, Minecraft.getMinecraft().world);
        }
        if (stack == null && entity == null && JsonHelper.isFluid(json)) {
            fluid = JsonHelper.JsonToFluidStack(json);
        }
    } else // JSON cannot be null!
    {
        this.mc.displayGuiScreen(parent);
        return;
    }
    if (stack == null) {
        stack = new BigItemStack(Blocks.STONE);
    }
    if (entity == null) {
        entity = new EntityPig(Minecraft.getMinecraft().world);
    }
    if (fluid == null) {
        fluid = new FluidStack(FluidRegistry.WATER, 1000);
    }
    if (lastType == EditType.ITEM) {
        JsonHelper.ClearCompoundTag(json);
        JsonHelper.ItemStackToJson(stack, json);
    } else if (lastType == EditType.FLUID) {
        JsonHelper.ClearCompoundTag(json);
        JsonHelper.FluidStackToJson(fluid, json);
    } else if (lastType == EditType.ENTITY) {
        JsonHelper.ClearCompoundTag(json);
        JsonHelper.EntityToJson(entity, json);
    }
    if (lastType != EditType.NONE) {
        mc.displayGuiScreen(parent);
    }
    // JSON Editor
    GuiButtonThemed editButton = new GuiButtonThemed(3, this.width / 2 - 100, this.height / 2 - 40, 200, 20, I18n.format("betterquesting.btn.raw_nbt"), true);
    // Item Selector
    GuiButtonThemed itemButton = new GuiButtonThemed(1, this.width / 2 - 100, this.height / 2 - 20, 200, 20, I18n.format("betterquesting.btn.item"), true);
    // Fluid Editor
    GuiButtonThemed fluidButton = new GuiButtonThemed(4, this.width / 2 - 100, this.height / 2 + 00, 200, 20, I18n.format("betterquesting.btn.fluid"), true);
    // Entity Selector
    GuiButtonThemed entityButton = new GuiButtonThemed(2, this.width / 2 - 100, this.height / 2 + 20, 200, 20, I18n.format("betterquesting.btn.entity"), true);
    this.buttonList.add(itemButton);
    this.buttonList.add(entityButton);
    this.buttonList.add(editButton);
    this.buttonList.add(fluidButton);
    itemCallback = new JsonItemCallback(json, stack);
    fluidCallback = new JsonFluidCallback(json, fluid);
    entityCallback = new JsonEntityCallback(json, entity);
}
Also used : EntityPig(net.minecraft.entity.passive.EntityPig) FluidStack(net.minecraftforge.fluids.FluidStack) JsonEntityCallback(betterquesting.client.gui.editors.json.callback.JsonEntityCallback) GuiButtonThemed(betterquesting.api.client.gui.controls.GuiButtonThemed) BigItemStack(betterquesting.api.utils.BigItemStack) JsonFluidCallback(betterquesting.client.gui.editors.json.callback.JsonFluidCallback) JsonItemCallback(betterquesting.client.gui.editors.json.callback.JsonItemCallback)

Aggregations

JsonEntityCallback (betterquesting.client.gui.editors.json.callback.JsonEntityCallback)2 JsonFluidCallback (betterquesting.client.gui.editors.json.callback.JsonFluidCallback)2 JsonItemCallback (betterquesting.client.gui.editors.json.callback.JsonItemCallback)2 GuiButtonThemed (betterquesting.api.client.gui.controls.GuiButtonThemed)1 IJsonDoc (betterquesting.api.jdoc.IJsonDoc)1 BigItemStack (betterquesting.api.utils.BigItemStack)1 GuiJsonAdd (betterquesting.client.gui.editors.json.GuiJsonAdd)1 GuiJsonEntitySelection (betterquesting.client.gui.editors.json.GuiJsonEntitySelection)1 GuiJsonFluidSelection (betterquesting.client.gui.editors.json.GuiJsonFluidSelection)1 GuiJsonItemSelection (betterquesting.client.gui.editors.json.GuiJsonItemSelection)1 GuiJsonTypeMenu (betterquesting.client.gui.editors.json.GuiJsonTypeMenu)1 EntityPig (net.minecraft.entity.passive.EntityPig)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 FluidStack (net.minecraftforge.fluids.FluidStack)1