Skip to content

Commit

Permalink
first changes for enchanting (not finished)
Browse files Browse the repository at this point in the history
- added enchanting table block handler and added it to the blockhandler
- added enchanting window
- drop item in the slot 0 when the player close the window
- added enchanting packet (1.7 only)
- some more...
  • Loading branch information
daniel0916 committed Jan 20, 2014
1 parent 2407a67 commit 0c2b307
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Blocks/BlockEnchantmentTable.h
@@ -0,0 +1,37 @@

#pragma once

#include "BlockHandler.h"
#include "../UI/Window.h"
#include "../Entities/Player.h"





class cBlockEnchantmentTableHandler :
public cBlockHandler
{
public:
cBlockEnchantmentTableHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}


virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
cWindow * Window = new cEnchantingWindow(a_BlockX, a_BlockY, a_BlockZ);
a_Player->OpenWindow(Window);
}


virtual bool IsUseable(void) override
{
return true;
}
};




2 changes: 2 additions & 0 deletions src/Blocks/BlockHandler.cpp
Expand Up @@ -21,6 +21,7 @@
#include "BlockDirt.h"
#include "BlockDoor.h"
#include "BlockDropSpenser.h"
#include "BlockEnchantmentTable.h"
#include "BlockEnderchest.h"
#include "BlockEntity.h"
#include "BlockFarmland.h"
Expand Down Expand Up @@ -132,6 +133,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_DOUBLE_WOODEN_SLAB: return new cBlockDoubleSlabHandler (a_BlockType);
case E_BLOCK_DROPPER: return new cBlockDropSpenserHandler (a_BlockType);
case E_BLOCK_EMERALD_ORE: return new cBlockOreHandler (a_BlockType);
case E_BLOCK_ENCHANTMENT_TABLE: return new cBlockEnchantmentTableHandler(a_BlockType);
case E_BLOCK_ENDER_CHEST: return new cBlockEnderchestHandler (a_BlockType);
case E_BLOCK_FARMLAND: return new cBlockFarmlandHandler ( );
case E_BLOCK_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType);
Expand Down
17 changes: 17 additions & 0 deletions src/Protocol/Protocol17x.cpp
Expand Up @@ -1143,6 +1143,7 @@ bool cProtocol172::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType)
case 0x0e: HandlePacketWindowClick (a_ByteBuffer); return true;
case 0x0f: // Confirm transaction - not used in MCS
case 0x10: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true;
case 0x11: HandlePacketEnchanting (a_ByteBuffer); return true;

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 22, 2014

Are you using tabs instead of spaces inside lines?

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 22, 2014

Author Owner

Maybe. I don't know if i used there tabs. But when i make more spaces i use tab.

case 0x12: HandlePacketUpdateSign (a_ByteBuffer); return true;
case 0x13: HandlePacketPlayerAbilities (a_ByteBuffer); return true;
case 0x14: HandlePacketTabComplete (a_ByteBuffer); return true;
Expand Down Expand Up @@ -1545,6 +1546,22 @@ void cProtocol172::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)



void cProtocol172::HandlePacketEnchanting(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, WindowID);
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Enchantment);

//TODO: EnchantItem (getWindow, getItem, Enchant)

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 23, 2014

Just noticed this: add a space in front of TODO

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 24, 2014

Author Owner

Thanks, but in the new commit i removed this.




LOG("Enchantment Paket empfangen!");
}





void cProtocol172::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
{
HANDLE_READ(a_ByteBuffer, ReadChar, char, WindowID);
Expand Down
1 change: 1 addition & 0 deletions src/Protocol/Protocol17x.h
Expand Up @@ -258,6 +258,7 @@ class cProtocol172 :
void HandlePacketTabComplete (cByteBuffer & a_ByteBuffer);
void HandlePacketUpdateSign (cByteBuffer & a_ByteBuffer);
void HandlePacketUseEntity (cByteBuffer & a_ByteBuffer);
void HandlePacketEnchanting (cByteBuffer & a_ByteBuffer);

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 22, 2014

Alignment error again, tabs vs spaces.

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 22, 2014

Author Owner

But for me it was working. So i should only use spaces?

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 22, 2014

We use tabs at the start of the line, and spaces everywhere else. Therefore anyone can choose their indentation by setting their tab size and it doesn't break any alignment. There should be a note of this in the CONTRIBUTING file.

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 23, 2014

Author Owner

Okay, thanks. I will fix this in the next commit..

void HandlePacketWindowClick (cByteBuffer & a_ByteBuffer);
void HandlePacketWindowClose (cByteBuffer & a_ByteBuffer);

Expand Down
86 changes: 86 additions & 0 deletions src/UI/SlotArea.cpp
Expand Up @@ -562,6 +562,92 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player)



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnchanting:

cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) :
cSlotAreaTemporary(a_NumSlots, a_ParentWindow)
{
}





void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
{
LOG("Clicked");
// Check if Slot is in the Enchantment Table
if (a_SlotNum == 0)
{
if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick))
{
ShiftClickedResult(a_Player);
}
else
{
ClickedResult(a_Player);
}
return;
}
super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
}





void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player)
{
// Toss the item in the enchanting slot
TossItems(a_Player, 0, 0);
// Player not found - that is acceptable
}





void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player)
{
LOG("Click!");

if (a_Player.GetDraggingItem().IsEmpty())
{
LOG("EMPTY");

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 22, 2014

The property value is a number, NULL is a pointer. Don't mix the two.

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 22, 2014

Author Owner

Thanks. But i don't know how can i remove the 3 enchanting options (what will be set with property).

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 23, 2014

Use a zero, that's a number :)

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 23, 2014

Author Owner

But with zero the propertys are showing. I need the same design like a new enchanting window. without the propertys..

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Jan 23, 2014

If it doesn't work with zeroes, it doesn't work with NULL either, because internally they are the same value.
Use ProtoProxy to find out what the Vanilla MC sends in such cases, then.

This comment has been minimized.

Copy link
@daniel0916

daniel0916 Jan 23, 2014

Author Owner

Thanks, i will try ProtoProxy.

this->m_ParentWindow.SetProperty(0, NULL);
this->m_ParentWindow.SetProperty(1, NULL);
this->m_ParentWindow.SetProperty(2, NULL);
}
else if (a_Player.GetDraggingItem().IsEnchantable)
{
LOG("Enchantable");
this->m_ParentWindow.SetProperty(0, 30);
this->m_ParentWindow.SetProperty(1, 20);
this->m_ParentWindow.SetProperty(2, 10);
}
else
{
LOG("Not Enchantable");
this->m_ParentWindow.SetProperty(0, NULL);
this->m_ParentWindow.SetProperty(1, NULL);
this->m_ParentWindow.SetProperty(2, NULL);
}
}





void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player)
{
LOG("Shift Click!");
}





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnderChest:

Expand Down
28 changes: 28 additions & 0 deletions src/UI/SlotArea.h
Expand Up @@ -252,6 +252,34 @@ class cSlotAreaCrafting :



class cSlotAreaEnchanting :
public cSlotAreaTemporary
{
typedef cSlotAreaTemporary super;

public:
/// a_GridSize is allowed to be only 2 or 3
cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow);

// cSlotAreaTemporary overrides:
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
virtual void OnPlayerRemoved(cPlayer & a_Player) override;

// Distributing items into this area is completely disabled
virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {}

protected:
/// Handles a click in the result slot. Crafts using the current recipe, if possible
void ClickedResult(cPlayer & a_Player);

/// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result.
void ShiftClickedResult(cPlayer & a_Player);
};





class cSlotAreaChest :
public cSlotArea
{
Expand Down
15 changes: 15 additions & 0 deletions src/UI/Window.cpp
Expand Up @@ -781,6 +781,21 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cEnchantingWindow:

cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
cWindow(wtEnchantment, "Enchantment Table")
{
m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this));
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
}





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cChestWindow:

Expand Down
12 changes: 12 additions & 0 deletions src/UI/Window.h
Expand Up @@ -231,6 +231,18 @@ class cCraftingWindow :



class cEnchantingWindow :
public cWindow
{
typedef cWindow super;
public:
cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
};





class cFurnaceWindow :
public cWindow
{
Expand Down

0 comments on commit 0c2b307

Please sign in to comment.