Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
Is it possible to update block metadata?
I have been searching for an alternative to MonsterBlocks: http://dev.bukkit.org/bukkit-plugins/monster-blocks/
I, of course, was not able to find anything, so I decided to code my own alternative. I am not sure how to read and change block metadata. Is it even possible?
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
01-21-2016, 04:11 AM
(This post was last modified: 01-21-2016, 04:11 AM by NiLSPACE.)
Use cWorld:SetBlockMeta(PosX, PosY, PosZ, Meta) for that. You can also use a Vector3i object instead of the 3 position numbers.
Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-21-2016, 06:30 AM
(This post was last modified: 01-21-2016, 06:33 AM by nixi.)
Another problem: When I do:
local meta = Player:GetWorld():GetBlockMeta(BlockX, BlockY, BlockZ)
and then send myself a message:
Player:SendMessage(meta)
It prints two lines. I only want one. What even is the other line?
When I send a HOOK_PLAYER_LEFT_CLICK hook to the function, it prints the meta id to the second line and when I send a HOOK_PLAYER_RIGHT_CLICK, it prints it on the first line...
The additional line is always 1.
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Could you show us our code?
Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-21-2016, 06:49 AM
(This post was last modified: 01-21-2016, 06:53 AM by nixi.)
(01-21-2016, 06:44 AM)NiLSPACE Wrote: Could you show us our code?
The mcBlockRespawn function gets called by a HOOK_PLAYER_BREAKING_BLOCK (so i can prevent block breaking in creative), otherwise the mcLeft function is called by HOOK_PLAYER_LEFT_CLICK. This is because HOOK_PLAYER_LEFT_CLICK is not registered in creative.
Here are the files if you want to try it yourself: http://a.pomf.cat/xvwliy.7z
mcMetaTool = 280
mcBiomeTool = 369
function mcLeft(Player, BlockX, BlockY, BlockZ, BlockFace, Action)
if (Player:GetEquippedItem().m_ItemType == mcMetaTool) then
mcMetaLeft(Player, BlockX, BlockY, BlockZ, BlockFace, Action)
elseif (Player:GetEquippedItem().m_ItemType == mcBiomeTool) then
mcBiomeLeft(Player, BlockX, BlockY, BlockZ, BlockFace, Action)
end
end
function mcRight(Player, BlockX, BlockY, BlockZ)
if (Player:GetEquippedItem().m_ItemType == mcMetaTool) then
mcMetaRight(Player, BlockX, BlockY, BlockZ)
elseif (Player:GetEquippedItem().m_ItemType == mcBiomeTool) then
mcBiomeRight(Player, BlockX, BlockY, BlockZ)
end
end
--
function mcMetaLeft(Player, BlockX, BlockY, BlockZ, BlockFace, Action)
if (Action == 1) then
local meta = Player:GetWorld():GetBlockMeta(BlockX, BlockY, BlockZ)
if (meta == 0) then
meta = 16
else
meta = meta - 1
end
Player:SendMessage(meta)
Player:GetWorld():SetBlockMeta(BlockX, BlockY, BlockZ, meta)
end
end
function mcMetaRight(Player, BlockX, BlockY, BlockZ)
local meta = Player:GetWorld():GetBlockMeta(BlockX, BlockY, BlockZ)
if (meta == 16) then
meta = 0
else
meta = meta + 1
end
Player:SendMessage(meta)
Player:GetWorld():SetBlockMeta(BlockX, BlockY, BlockZ, meta)
end
function mcBiomeLeft(Player, BlockX, BlockY, BlockZ, BlockFace, Action)
if (Action == 1) then
local biome = Player:GetWorld():GetBiomeAt(BlockX, BlockZ)
biome = biome - 1
Player:SendMessage(biome)
Player:GetWorld():SetAreaBiome(BlockX, BlockX, BlockZ, BlockZ, biome)
end
end
function mcBiomeRight(Player, BlockX, BlockY, BlockZ)
local biome = Player:GetWorld():GetBiomeAt(BlockX, BlockZ)
biome = biome + 1
Player:SendMessage(biome)
Player:GetWorld():SetAreaBiome(BlockX, BlockX, BlockZ, BlockZ, biome)
end
--
function mcBlockRespawn(Player, BlockX, BlockY, BlockZ, BlockFace, Action)
if (Player:GetEquippedItem().m_ItemType == mcMetaTool) or (Player:GetEquippedItem().m_ItemType == mcBiomeTool) then
if (Player:GetGameMode() == 1) then
mcLeft(Player, BlockX, BlockY, BlockZ, BlockFace, 1)
end
return true
end
end
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Strange, the left click should be called normally in creative. I'm afraid I can't test this at the moment though, so I'll get back to this later.
Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-21-2016, 08:19 PM
(This post was last modified: 01-21-2016, 08:29 PM by nixi.)
(01-21-2016, 05:37 PM)NiLSPACE Wrote: Strange, the left click should be called normally in creative. I'm afraid I can't test this at the moment though, so I'll get back to this later.
Interesting indeed, but that is not the main issue after all, since I can hack around it.
The double meta thing is a different problem entirely.
I have decided to ignore the biome changing for now and fix the meta changing function. Right clicking works well except that it sends me two lines of numbers (one is the real metadata, the other is who knows what). Left clicking the block is just broken because of the two meta numbers. That, as a result, does not let the mcBlockRespawn function prevent the block from being removed.
Another issue is that right-clicking does automatically cycle back to 0 if it reaches meta 16 and 1 is added to it by the function. This does not work the other way when left-clicking and the block simple gets destroyed (in creative).
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
What do you mean with 'two meta numbers'?
The right-click is called twice because Minecraft sends two packets.
Add this check in front of the hook:
if (BlockFace == BLOCK_FACE_NONE) then
return false
end
Posts: 14
Threads: 3
Joined: Jan 2016
Thanks: 3
Given 4 thank(s) in 1 post(s)
01-21-2016, 09:06 PM
(This post was last modified: 01-21-2016, 09:09 PM by nixi.)
(01-21-2016, 08:51 PM)NiLSPACE Wrote: Add this check in front of the hook:
if (BlockFace == BLOCK_FACE_NONE) then
return false
end
Where exactly?
(01-21-2016, 08:51 PM)NiLSPACE Wrote: The right-click is called twice because Minecraft sends two packets.
If the right-click function was called twice, it would increase the number by 2 on one click. Instead it returns an entirely new number.
Here is a screenshot with all the scenarios:
http://i.imgur.com/9kVqPYU.png
The numbers returned in chat are simply the meta variable...
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Add the check for the right click hook.
Also, I believe you should check if the meta is 15 instead of 16. The meta starts from 0 until 15. For the same reason you should also set the left click to 15 instead of 16 when the meta is 0.
|