Implemented Regeneration for BlockRift

1. Made it so that rifts regenerate when rift blocks are replaced by
other blocks.
2. Changed the rift regeneration scheduling functions to streamline
their use in other classes. Common code that was needed to validate
links before calling those functions has been moved into them so that
the checks are always performed internally.
This commit is contained in:
SenseiKiwi
2014-07-11 03:26:40 -04:00
parent 1f59dc17d9
commit 71e7fdaafc
3 changed files with 26 additions and 15 deletions

View File

@@ -7,7 +7,6 @@ import java.util.Queue;
import java.util.Random; import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockFlowing; import net.minecraft.block.BlockFlowing;
import net.minecraft.block.BlockFluid; import net.minecraft.block.BlockFluid;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
@@ -87,9 +86,6 @@ public class BlockRift extends Block implements ITileEntityProvider
{ {
return false; return false;
} }
@Override
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {}
@Override @Override
public boolean isOpaqueCube() public boolean isOpaqueCube()
@@ -116,10 +112,10 @@ public class BlockRift extends Block implements ITileEntityProvider
return true; return true;
} }
//this doesnt do anything yet.
@Override @Override
public int getRenderType() public int getRenderType()
{ {
// This doesn't do anything yet
if (mod_pocketDim.isPlayerWearingGoogles) if (mod_pocketDim.isPlayerWearingGoogles)
{ {
return 0; return 0;
@@ -235,7 +231,7 @@ public class BlockRift extends Block implements ITileEntityProvider
} }
} }
private void addAdjacentBlocks(int x, int y, int z, int distance, HashMap<Point3D, Integer> pointDistances, Queue<Point3D> points) private static void addAdjacentBlocks(int x, int y, int z, int distance, HashMap<Point3D, Integer> pointDistances, Queue<Point3D> points)
{ {
Point3D[] neighbors = new Point3D[] { Point3D[] neighbors = new Point3D[] {
new Point3D(x - 1, y, z), new Point3D(x - 1, y, z),
@@ -462,4 +458,15 @@ public class BlockRift extends Block implements ITileEntityProvider
{ {
return new TileEntityRift(); return new TileEntityRift();
} }
@Override
public void breakBlock(World world, int x, int y, int z, int oldBlockID, int oldMeta)
{
// This function runs on the server side after a block is replaced
// We MUST call super.breakBlock() since it involves removing tile entities
super.breakBlock(world, x, y, z, oldBlockID, oldMeta);
// Schedule rift regeneration for this block
mod_pocketDim.riftRegenerator.scheduleSlowRegeneration(x, y, z, world);
}
} }

View File

@@ -48,15 +48,23 @@ public class RiftRegenerator implements IRegularTickReceiver {
scheduleRegeneration(link, MIN_SLOW_DELAY, MAX_SLOW_DELAY); scheduleRegeneration(link, MIN_SLOW_DELAY, MAX_SLOW_DELAY);
} }
public void scheduleFastRegeneration(DimLink link) public void scheduleSlowRegeneration(int x, int y, int z, World world)
{ {
scheduleRegeneration(link, MIN_FAST_DELAY, MAX_FAST_DELAY); scheduleRegeneration(PocketManager.getLink(x, y, z, world), MIN_SLOW_DELAY, MAX_SLOW_DELAY);
}
public void scheduleFastRegeneration(int x, int y, int z, World world)
{
scheduleRegeneration(PocketManager.getLink(x, y, z, world), MIN_FAST_DELAY, MAX_FAST_DELAY);
} }
private void scheduleRegeneration(DimLink link, int minDelay, int maxDelay) private void scheduleRegeneration(DimLink link, int minDelay, int maxDelay)
{ {
int tickDelay = MathHelper.getRandomIntegerInRange(random, minDelay * TICKS_PER_SECOND, maxDelay * TICKS_PER_SECOND); if (link != null)
ticketQueue.add(new RiftTicket(link.source(), tickCount + tickDelay)); {
int tickDelay = MathHelper.getRandomIntegerInRange(random, minDelay * TICKS_PER_SECOND, maxDelay * TICKS_PER_SECOND);
ticketQueue.add(new RiftTicket(link.source(), tickCount + tickDelay));
}
} }
private void processTicketQueue() private void processTicketQueue()

View File

@@ -40,11 +40,7 @@ public class TileEntityDimDoor extends DDTileEntityBase
super.invalidate(); super.invalidate();
if (!worldObj.isRemote && worldObj.getBlockId(xCoord, yCoord, zCoord) == 0) if (!worldObj.isRemote && worldObj.getBlockId(xCoord, yCoord, zCoord) == 0)
{ {
DimLink link = PocketManager.getLink(xCoord, yCoord, zCoord, worldObj); mod_pocketDim.riftRegenerator.scheduleFastRegeneration(xCoord, yCoord, zCoord, worldObj);
if (link != null)
{
mod_pocketDim.riftRegenerator.scheduleFastRegeneration(link);
}
} }
} }