Some related links:
Build Faster! on Minecraft Forum
Source code on GitHub
Some stuff about Minecraft modding
The main class is SpeedyToolsMod. This is pretty standard; for more details see How Forge starts up your code.
The overall structure of the code is shown in the diagram below. ItemSpeedyTool encapsulates the behaviour of the different types of SpeedyTool and interacts with several other client classes for user input, block selection, rendering, as well as the server class which modifies the world.
![]() |
| Overview of code structure, showing the flow from user input through to its effect on the world. |
The code is grouped roughly into three parts:
(1) Code that runs on the client only (package clientonly)
This code is firstly responsible for intercepting user input:
- InputEventHandler.interceptMouseInput, which captures the mouse scroll wheel movements.
- KeyBindingInterceptor, which replaces the keyBindAttack and keyBindUseItem KeyBindings in GameSettings, in order to capture the right-click and left-click actions.
When the interceptors are active, these actions are prevented from reaching the vanilla code.
Unfortunately I couldn't find a way to intercept the attack and use actions without overwriting the vanilla KeyBinding objects. This means that, if BuildFaster is installed with another mod that uses the same trick, one of the two mods probably won't work.
The interceptors are installed and controlled (turned on/off) by SpeedyToolControls.
The second function of the client code is to control selection and rendering of the selection box:
- ItemEventHandler.blockHighlightDecider is used to turn off vanilla block highlighting if a speedy tool is selected.
- ItemEventHandler.drawSelectionBox calls ItemSpeedyTool.selectBlocks in order to define the current multi-block selection, then renders it as a wire frame. The multi-block selection is saved in ItemSpeedyTool.
- BlockMultiSelector contains the logic used to generate the appropriate multi-block selection:
* Identify the intended starting block, depending on where the player is looking and whether there are any nearby blocks.
* Extend from the starting block to generate the multi-block selection - either a line, following a contour, or a flood fill.
(2) Code that runs on both client and server (package common)
The common code contains:- The four different tools which all inherit from ItemSpeedyTool. ItemSpeedyTool contains
* selectBlocks (and several related): create a multi-block selection based on where the user is looking
* getPlacedBlockFromItemStack: figure out which Block to place based on the Item to the left of the tool. This is obvious for ItemBlocks, but there are some special cases such as lava buckets.
* xxxButtonClicked: when the use or attack button is pressed, play the appropriate sound and send a packet to the Server. The undo history for sounds is stored here too. - The clientserversynch is used to handle packets sent from the client to the server. When the user clicks on use or attack, the client sends a packet to the server with the current tool, the block-to-be-placed, and the coordinates of each block in the multi-block selection. The server then passes this information to SpeedyToolWorldManipulator.
(3) Code that runs on the server only (package serveronly)
- SpeedyToolWorldManipulator is responsible for overwriting the blocks in the multi-block selection with the new block, for maintaining the undo history, and for undoing previous placements.

No comments:
Post a Comment