Overhauled Tick Sending by CommonTickHandler
Overhauled the way in which CommonTickHandler triggers tick-based actions such as Limbo decay, spawning Monoliths, and regenerating rifts. Now CommonTickHandler implements an interface called IRegularTickSender, which indicates that it will periodically call on classes that implement IRegulatTickReceiver to perform some task. I added classes for each regularly scheduled task we were performing: MonolithSpawner and RiftRegenerator, plus converted LimboDecay to a normal class instead of a static class. Modified several classes so that they have access to the MonolithSpawner instance to request MonolithSpawning when needed. This improves the structure of our code and gets us away from the way we did things before, which was accessing a public static list inside CommonTickHandler from other classes and adding arrays to specify chunk coordinates. We should not be exposing the internal state of classes like that! And we should be using clearly defined objects to pass information.
This commit is contained in:
@@ -7,55 +7,56 @@ import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import StevenDimDoors.mod_pocketDim.ticking.IRegularTickReceiver;
|
||||
import StevenDimDoors.mod_pocketDim.ticking.IRegularTickSender;
|
||||
|
||||
/**
|
||||
* Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo
|
||||
* naturally change into stone, then cobble, then gravel, and finally Unraveled Fabric as time passes.
|
||||
*/
|
||||
public class LimboDecay {
|
||||
public class LimboDecay implements IRegularTickReceiver {
|
||||
|
||||
private static final int MAX_DECAY_SPREAD_CHANCE = 100;
|
||||
private static final int DECAY_SPREAD_CHANCE = 50;
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
private static final int SECTION_HEIGHT = 16;
|
||||
private static final int LIMBO_DECAY_INTERVAL = 10; //Apply spread decay every 10 ticks
|
||||
|
||||
//Provides a reversed list of the block IDs that blocks cycle through during decay.
|
||||
//Must be initialized later since it requires DDProperties to be initialized (for LimboBlockID).
|
||||
private static int[] decaySequence = null;
|
||||
private final int[] decaySequence;
|
||||
|
||||
private static Random random = new Random();
|
||||
private static DDProperties properties = null;
|
||||
private Random random;
|
||||
private DDProperties properties = null;
|
||||
|
||||
private LimboDecay() { }
|
||||
public LimboDecay(IRegularTickSender tickSender, DDProperties properties)
|
||||
{
|
||||
decaySequence = new int[] {
|
||||
properties.LimboBlockID,
|
||||
Block.gravel.blockID,
|
||||
Block.cobblestone.blockID,
|
||||
Block.stone.blockID
|
||||
};
|
||||
|
||||
this.properties = properties;
|
||||
this.random = new Random();
|
||||
tickSender.registerForTicking(this, LIMBO_DECAY_INTERVAL, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the array containing the reversed sequence of block IDs that blocks cycle through during decay.
|
||||
* Applies fast Limbo decay periodically.
|
||||
*/
|
||||
private static void initializeDecaySequence()
|
||||
@Override
|
||||
public void notifyTick()
|
||||
{
|
||||
if (decaySequence == null)
|
||||
{
|
||||
if (properties == null)
|
||||
properties = DDProperties.instance();
|
||||
|
||||
decaySequence = new int[] {
|
||||
properties.LimboBlockID,
|
||||
Block.gravel.blockID,
|
||||
Block.cobblestone.blockID,
|
||||
Block.stone.blockID
|
||||
};
|
||||
}
|
||||
applyRandomFastDecay();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks the blocks orthogonally around a given location (presumably the location of an Unraveled Fabric block)
|
||||
* and applies Limbo decay to them. This gives the impression that decay spreads outward from Unraveled Fabric.
|
||||
*/
|
||||
public static void applySpreadDecay(World world, int x, int y, int z)
|
||||
{
|
||||
if (properties == null)
|
||||
properties = DDProperties.instance();
|
||||
|
||||
public void applySpreadDecay(World world, int x, int y, int z)
|
||||
{
|
||||
//Check if we randomly apply decay spread or not. This can be used to moderate the frequency of
|
||||
//full spread decay checks, which can also shift its performance impact on the game.
|
||||
if (random.nextInt(MAX_DECAY_SPREAD_CHANCE) < DECAY_SPREAD_CHANCE)
|
||||
@@ -75,11 +76,8 @@ public class LimboDecay {
|
||||
* Picks random blocks from each active chunk in Limbo and, if decay is applicable, converts them directly to Unraveled Fabric.
|
||||
* This decay method is designed to stop players from avoiding Limbo decay by building floating structures.
|
||||
*/
|
||||
public static void applyRandomFastDecay()
|
||||
private void applyRandomFastDecay()
|
||||
{
|
||||
if (properties == null)
|
||||
properties = DDProperties.instance();
|
||||
|
||||
int x, y, z;
|
||||
int sectionY;
|
||||
int limboHeight;
|
||||
@@ -111,7 +109,7 @@ public class LimboDecay {
|
||||
/**
|
||||
* Checks if a block can be decayed and, if so, changes it directly into Unraveled Fabric.
|
||||
*/
|
||||
private static boolean decayBlockFast(World world, int x, int y, int z)
|
||||
private boolean decayBlockFast(World world, int x, int y, int z)
|
||||
{
|
||||
int blockID = world.getBlockId(x, y, z);
|
||||
if (canDecayBlock(blockID))
|
||||
@@ -125,11 +123,8 @@ public class LimboDecay {
|
||||
/**
|
||||
* Checks if a block can be decayed and, if so, changes it to the next block ID along the decay sequence.
|
||||
*/
|
||||
private static boolean decayBlock(World world, int x, int y, int z)
|
||||
private boolean decayBlock(World world, int x, int y, int z)
|
||||
{
|
||||
//Make sure the decay sequence is initialized
|
||||
initializeDecaySequence();
|
||||
|
||||
int index;
|
||||
int blockID = world.getBlockId(x, y, z);
|
||||
if (canDecayBlock(blockID))
|
||||
@@ -159,7 +154,7 @@ public class LimboDecay {
|
||||
/**
|
||||
* Checks if a block can decay. We will not decay air, Unraveled Fabric, Eternal Fabric, or containers.
|
||||
*/
|
||||
private static boolean canDecayBlock(int blockID)
|
||||
private boolean canDecayBlock(int blockID)
|
||||
{
|
||||
if (blockID == 0 || blockID == properties.LimboBlockID || blockID == properties.PermaFabricBlockID)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user