Skip to content

Instantly share code, notes, and snippets.

@Frago9876543210
Created September 7, 2017 12:59
Show Gist options
  • Save Frago9876543210/0f6c467481754aaf811f51e31db3d4a3 to your computer and use it in GitHub Desktop.
Save Frago9876543210/0f6c467481754aaf811f51e31db3d4a3 to your computer and use it in GitHub Desktop.
inv menu
using MiNET.Items;
using MiNET.Net;
using MiNET.Plugins;
using MiNET.Plugins.Attributes;
using MiNET.Utils;
using TestPlugin.Player;
namespace GuiPlugin
{
[Plugin]
public class Gui : Plugin
{
[PacketHandler, Receive]
public Package HandleUseItem(McpeUseItem packet, CustomPlayer player)
{
var pos = new PlayerLocation(player.KnownPosition.X, player.KnownPosition.Y + 2, player.KnownPosition.Z).GetCoordinates3D();
var updateBlock = McpeUpdateBlock.CreateObject();
updateBlock.blockId = 54;
updateBlock.coordinates = pos;
updateBlock.blockMetaAndPriority = 0xb << 4 | (0 & 0xf);
player.SendPackage(updateBlock);
var containerOpen = McpeContainerOpen.CreateObject();
containerOpen.windowId = 10;
containerOpen.type = 0;
containerOpen.coordinates = pos;
containerOpen.unknownRuntimeEntityId = 1;
player.SendPackage(containerOpen);
var items = new ItemStacks {ItemFactory.GetItem(267)};
var containerSetContent = McpeContainerSetContent.CreateObject();
containerSetContent.windowId = 10;
containerSetContent.slotData = items;
player.SendPackage(containerSetContent);
return packet;
}
[PacketHandler, Receive]
public Package HandleContainerSetSlot(McpeContainerSetSlot package, CustomPlayer player)
{
//System.Console.WriteLine("McpeContainerSetSlot[\nwindowId={0},\nslot={1},\nhotbarslot={2},\nitem={3},\nselectedSlot={4}\n]", package.windowId, package.slot, package.hotbarslot, package.item.ToString(), package.selectedSlot);
if (package.windowId == 10)
{
if (package.selectedSlot == 0 && package.slot == 0 && package.item.Id == 0)
{
McpeContainerClose containerClose = McpeContainerClose.CreateObject();
containerClose.windowId = 10;
player.SendPackage(containerClose);
player.SendMessage("You selected item");
}
}
return package;
}
[PacketHandler, Receive]
public Package HandleContainerClose(McpeContainerClose package, CustomPlayer player)
{
var pos = new PlayerLocation(player.KnownPosition.X, player.KnownPosition.Y + 2, player.KnownPosition.Z);
var updateBlock = McpeUpdateBlock.CreateObject();
updateBlock.blockId = player.Level.GetBlock(pos).Id;
updateBlock.coordinates = pos.GetCoordinates3D();
updateBlock.blockMetaAndPriority = 0xb << 4 | (0 & 0xf);
player.SendPackage(updateBlock);
return package;
}
[PacketHandler, Receive]
public Package HandleDrop(McpeDropItem package, CustomPlayer player)
{
//todo: maybe add check with tmp array
return player.Level == Core.DefaultLevel ? null : package;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment