Placing blocks in lua
#15
Such a plugin will be a bit more difficult than it seems at first.

You'll need to store the list of all blocks that will need converting back to ore - most likely in a SQLite database. And for the conversion from stone to ore, you'll need to make use of ChunkStay, which is an advanced technique (basically, you need to force the server to load a chunk if it is not loaded). You will need to use the per-world task scheduler. The plugin will need to do some processing when it's loaded - in case the server is restarted while some ores are in their "stone" state, you'll need to re-schedule their conversion back to ore.

SQLite in Cuberite: https://api.cuberite.org/sqlite3.html
ChunkStay: https://api.cuberite.org/cWorld.html#ChunkStay_1
Task scheduling: https://api.cuberite.org/cWorld.html#ScheduleTask_1

Basic workflow:
Add a player-block-break handler that:
- places stone right after a player digs an ore block
- stores into the database the world, block coords, ore type and tick when the block should be converted back to ore
- schedules a task on the world to turn the block back to ore
The scheduled task should:
- look in the database for all blocks that are due for conversion back to ore
- use ChunkStay to load the chunks and convert back to ore (as long as the block there is still stone (?))
- delete all blocks that it has processed from the database
Upon loading, the plugin should:
- inspect the database for any blocks that should already be converted, process them (like the Scheduled task)
- schedule tasks on each world for all blocks' conversions left in the database
Reply
Thanks given by: yoboykai


Messages In This Thread
Placing blocks in lua - by yoboykai - 02-25-2017, 03:56 AM
RE: Placing blocks in lua - by Seadragon91 - 02-25-2017, 06:02 AM
RE: Placing blocks in lua - by yoboykai - 02-25-2017, 09:32 AM
RE: Placing blocks in lua - by Seadragon91 - 02-25-2017, 06:18 PM
RE: Placing blocks in lua - by yoboykai - 02-26-2017, 08:40 AM
RE: Placing blocks in lua - by Seadragon91 - 02-27-2017, 11:51 PM
RE: Placing blocks in lua - by yoboykai - 02-28-2017, 10:11 AM
RE: Placing blocks in lua - by yoboykai - 03-12-2017, 09:45 AM
RE: Placing blocks in lua - by NiLSPACE - 03-12-2017, 06:20 PM
RE: Placing blocks in lua - by yoboykai - 03-13-2017, 04:30 AM
RE: Placing blocks in lua - by NiLSPACE - 03-13-2017, 05:00 AM
RE: Placing blocks in lua - by yoboykai - 03-13-2017, 05:59 AM
RE: Placing blocks in lua - by ThuGie - 03-13-2017, 08:22 AM
RE: Placing blocks in lua - by yoboykai - 03-13-2017, 12:27 PM
RE: Placing blocks in lua - by xoft - 03-13-2017, 06:23 PM



Users browsing this thread: 4 Guest(s)