how-does-it-work

Introduction

This page is how the plugin works and not how you use it. It's dedicated to people wanted to know more about LazyRoad.

In which format are the roads saved ?

The .ser format does not really exists. It's only a personal reference for Serialization. By this I mean the Java default Serialization. So yes it's a simple class serialized. You can check the source code if you want to know more about it.

A part is composed of two arrays, one of ints representing the block Type ID and one of byte representing the data.

How are the roads build?

  1. First, it finds the road corresponding to the name and sets the initial position and direction of the player.
  2. When you walk, you will trigger the onPlayerMove() event and LazyRoad is hooked on that event.
  3. It will first check if your a builder, then it will check if you moved from your spot.
  4. if you moved, then it will check your direction.
    1. If your direction is the opposite of the old direction (if you go backwards), it won't do anything and thus preventing users to build backwards
    2. If your direction is left or right, it will attempt to create make the corners.
  5. The road is build browsing the arrays of the parts and replacing the blocks on the map. Every block that is different will be stored on an Undo array.
  6. If you have an Y gradient, it will make stairs
  7. If you are building a bridge it will make the pillars.

Where are all the algorithms used for building the roads?

In the RoadEnable class. It has a lot of redundant code because of the directions, North, South, East, West and even more for corners where it has 12 different cases. In all the cases the code is a lot similar but the increments on the variable are all different. The amount of redundant code could be less but I already got some headaches thinking about all the cases and not making errors so let it be so ;)

It isn't complicated stuff and it's well commented, you might as well read the code to know more and to submit improvements if you want.

The undo case

Every block that is replaced by another is added in an undo array. So each different block takes 4 ints and one byte. When a player undo a road a Thread will be launched and the undo array is browsed in a reverse order. Then each blocks is replaced.

What's dangerous here is the use of threads. When it's completely save to browse the blocks in a world, it is not save to change them in a thread. So why do you do that? Well, it's because, not doing it causes lots of lags and because the chances to get an error are very tiny. Perhaps I will remove the thread if someone reports me some errors. But at the moment, I had no complains and quite a lot of downloads.


Comments

Posts Quoted:
Reply
Clear All Quotes