Skip to content

Instantly share code, notes, and snippets.

@Nixtren
Last active August 29, 2015 14:23
Show Gist options
  • Save Nixtren/fc4bdb51d3a11a6431a7 to your computer and use it in GitHub Desktop.
Save Nixtren/fc4bdb51d3a11a6431a7 to your computer and use it in GitHub Desktop.
Cuberite Item Multiplication Bug Fix (Survival Mode) Plugin
-- Coded by Nixtren
-- Released under Public Domain, it's a very simple plugin.
-- More information: https://github.com/cuberite/cuberite/issues/2272 and https://github.com/cuberite/cuberite/issues/1700
PLUGIN = nil
function Initialize(Plugin)
Plugin:SetName("ItemMultiplicationBugFix")
Plugin:SetVersion(4)
-- Hooks
PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock)
-- Command Bindings
-- Other stuff
LOG("[ItemMultiplicationBugFix] Loaded. This fixes a multiplication bug in Survival Mode. Don't forget to remove this plugin once the problem is internally fixed!")
return true
end
function OnDisable()
LOG(PLUGIN:GetName() .. " is shutting down...")
end
function OnPlayerPlacingBlock(Player, BlockX, BlockY, BlockZ, BlockType, BlockMeta)
if Player:GetGameMode() == gmSurvival then -- The API Docs ask me to use IsGameModeXXX() functions, but I don't really know how to use them :P
if BlockType == E_BLOCK_BED or BlockType == E_BLOCK_LILY_PAD or BlockType == E_BLOCK_ACACIA_DOOR or BlockType == E_BLOCK_BIRCH_DOOR or BlockType == E_BLOCK_DARK_OAK_DOOR or BlockType == E_BLOCK_IRON_DOOR or BlockType == E_BLOCK_JUNGLE_DOOR or BlockType == E_BLOCK_SPRUCE_DOOR or BlockType == E_BLOCK_WOODEN_DOOR then -- Thanks to Seadragon91 for the list of bugged items (https://github.com/cuberite/cuberite/issues/1700)
Player:GetInventory():RemoveOneEquippedItem()
end
end
end
@madmaxoft
Copy link

Doesn't this remove more items for the regular items (that were working before)? It would seem to me that when placing e. g. dirt, the server would remove one and then this plugin would remove another one.

@Nixtren
Copy link
Author

Nixtren commented Jun 21, 2015

You are correct, I completely forgot about that. I guess this becomes kind of useless unless we add a condition to check if the BlockType is one of the bugged ones. I will edit the plugin soon.

Edit: Plugin updated, should be working without bugs now.

@Nixtren
Copy link
Author

Nixtren commented Jun 21, 2015

Plugin updated due to a double-spend bug in some cases (when BlockMeta = 0), you should update to version 3 of this plugin ASAP.

Edit: Plugin updated to version 4. Only blocks are safe from multiplication, so an internal fix is really required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment