Flipped a Table
Replaced several core classes from DD with new classes to enforce integrity checks. Rewriting everything that depended on those classes is a massive undertaking but it should simplify our code and prevent the many bugs we've seen lately. The rewrite isn't done yet, just committing my progress so far.
This commit is contained in:
164
StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java
Normal file
164
StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package StevenDimDoors.mod_pocketDim.ticking;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||
|
||||
/**
|
||||
* 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 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.
|
||||
private final int[] decaySequence;
|
||||
|
||||
private Random random;
|
||||
private DDProperties properties = null;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies fast Limbo decay periodically.
|
||||
*/
|
||||
@Override
|
||||
public void notifyTick()
|
||||
{
|
||||
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 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)
|
||||
{
|
||||
//Apply decay to the blocks above, below, and on all four sides.
|
||||
//World.getBlockId() implements bounds checking, so we don't have to worry about reaching out of the world
|
||||
decayBlock(world, x - 1, y, z);
|
||||
decayBlock(world, x + 1, y, z);
|
||||
decayBlock(world, x, y, z - 1);
|
||||
decayBlock(world, x, y, z + 1);
|
||||
decayBlock(world, x, y - 1, z);
|
||||
decayBlock(world, x, y + 1, z);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private void applyRandomFastDecay()
|
||||
{
|
||||
int x, y, z;
|
||||
int sectionY;
|
||||
int limboHeight;
|
||||
World limbo = DimensionManager.getWorld(properties.LimboDimensionID);
|
||||
|
||||
if (limbo != null)
|
||||
{
|
||||
limboHeight = limbo.getHeight();
|
||||
|
||||
//Obtain the coordinates of active chunks in Limbo. For each section of each chunk,
|
||||
//pick a random block and try to apply fast decay.
|
||||
for (Object coordObject : limbo.activeChunkSet)
|
||||
{
|
||||
ChunkCoordIntPair chunkCoord = (ChunkCoordIntPair) coordObject;
|
||||
|
||||
//Loop through each chunk section and fast-decay a random block
|
||||
//Apply the changes using the world object instead of directly to the chunk so that clients are always notified.
|
||||
for (sectionY = 0; sectionY < limboHeight; sectionY += SECTION_HEIGHT)
|
||||
{
|
||||
x = chunkCoord.chunkXPos * CHUNK_SIZE + random.nextInt(CHUNK_SIZE);
|
||||
z = chunkCoord.chunkZPos * CHUNK_SIZE + random.nextInt(CHUNK_SIZE);
|
||||
y = sectionY + random.nextInt(SECTION_HEIGHT);
|
||||
decayBlockFast(limbo, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a block can be decayed and, if so, changes it directly into Unraveled Fabric.
|
||||
*/
|
||||
private boolean decayBlockFast(World world, int x, int y, int z)
|
||||
{
|
||||
int blockID = world.getBlockId(x, y, z);
|
||||
if (canDecayBlock(blockID))
|
||||
{
|
||||
world.setBlock(x, y, z, properties.LimboBlockID);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a block can be decayed and, if so, changes it to the next block ID along the decay sequence.
|
||||
*/
|
||||
private boolean decayBlock(World world, int x, int y, int z)
|
||||
{
|
||||
int index;
|
||||
int blockID = world.getBlockId(x, y, z);
|
||||
if (canDecayBlock(blockID))
|
||||
{
|
||||
//Loop over the block IDs that decay can go through.
|
||||
//Find an index matching the current blockID, if any.
|
||||
for (index = 0; index < decaySequence.length; index++)
|
||||
{
|
||||
if (decaySequence[index] == blockID)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Since the decay sequence is a reversed list, the block ID in the index before our match
|
||||
//is the block ID we should change this block into. A trick in this approach is that if
|
||||
//we loop over the array without finding a match, then (index - 1) will contain the
|
||||
//last ID in the array, which is the first one that all blocks decay into.
|
||||
//We assume that Unraveled Fabric is NOT decayable. Otherwise, this will go out of bounds!
|
||||
|
||||
world.setBlock(x, y, z, decaySequence[index - 1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a block can decay. We will not decay air, Unraveled Fabric, Eternal Fabric, or containers.
|
||||
*/
|
||||
private boolean canDecayBlock(int blockID)
|
||||
{
|
||||
if (blockID == 0 || blockID == properties.LimboBlockID || blockID == properties.PermaFabricBlockID)
|
||||
return false;
|
||||
|
||||
Block block = Block.blocksList[blockID];
|
||||
return (block == null || !(block instanceof BlockContainer));
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.DimData;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
||||
import StevenDimDoors.mod_pocketDim.util.ChunkLocation;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewLinkData;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.world.LimboProvider;
|
||||
import StevenDimDoors.mod_pocketDim.world.PocketProvider;
|
||||
|
||||
@@ -173,7 +173,7 @@ public class MobMonolith extends EntityFlying implements IMob
|
||||
|
||||
NewLinkData link = new NewLinkData(this.worldObj.provider.dimensionId, properties.LimboDimensionID, (int)this.posX, (int)this.posY, (int)this.posZ, (int)this.posX+rand.nextInt(500)-250, (int)this.posY+500, (int)this.posZ+rand.nextInt(500)-250, false,0);
|
||||
|
||||
dimHelper.instance.traverseDimDoor(worldObj, link, entityPlayer);
|
||||
PocketManager.instance.traverseDimDoor(worldObj, link, entityPlayer);
|
||||
this.aggro=0;
|
||||
|
||||
entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1);
|
||||
|
||||
@@ -7,9 +7,10 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.DimData;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
||||
import StevenDimDoors.mod_pocketDim.util.ChunkLocation;
|
||||
|
||||
@@ -69,23 +70,24 @@ public class MonolithSpawner implements IRegularTickReceiver {
|
||||
|
||||
private void placeMonolithsInPocket(int dimensionID, int chunkX, int chunkZ)
|
||||
{
|
||||
World pocket = dimHelper.getWorld(dimensionID);
|
||||
DimData dimData = dimHelper.instance.getDimData(dimensionID);
|
||||
NewDimData dimension = PocketManager.getDimensionData(dimensionID);
|
||||
World pocket = DimensionManager.getWorld(dimensionID);
|
||||
|
||||
if (pocket == null ||
|
||||
dimension == null ||
|
||||
dimension.dungeon() == null ||
|
||||
dimension.dungeon().isOpen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int sanity = 0;
|
||||
int blockID = 0;
|
||||
boolean didSpawn = false;
|
||||
|
||||
if (pocket == null ||
|
||||
dimData == null ||
|
||||
dimData.dungeonGenerator == null ||
|
||||
dimData.dungeonGenerator.isOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//The following initialization code is based on code from ChunkProviderGenerate.
|
||||
//It makes our generation depend on the world seed.
|
||||
Random random = new Random(pocket.getSeed());
|
||||
Random random = new Random(pocket.getSeed() ^ 0xA210FE65F20017D6L);
|
||||
long factorA = random.nextLong() / 2L * 2L + 1L;
|
||||
long factorB = random.nextLong() / 2L * 2L + 1L;
|
||||
random.setSeed(chunkX * factorA + chunkZ * factorB ^ pocket.getSeed());
|
||||
@@ -139,7 +141,7 @@ public class MonolithSpawner implements IRegularTickReceiver {
|
||||
|
||||
private void placeMonolithsInLimbo(int dimensionID, int chunkX, int chunkZ)
|
||||
{
|
||||
World limbo = dimHelper.getWorld(dimensionID);
|
||||
World limbo = DimensionManager.getWorld(dimensionID);
|
||||
|
||||
if (limbo == null)
|
||||
{
|
||||
@@ -148,7 +150,7 @@ public class MonolithSpawner implements IRegularTickReceiver {
|
||||
|
||||
//The following initialization code is based on code from ChunkProviderGenerate.
|
||||
//It makes our generation depend on the world seed.
|
||||
Random random = new Random(limbo.getSeed());
|
||||
Random random = new Random(limbo.getSeed() ^ 0xB5130C4ACC71A822L);
|
||||
long factorA = random.nextLong() / 2L * 2L + 1L;
|
||||
long factorB = random.nextLong() / 2L * 2L + 1L;
|
||||
random.setSeed(chunkX * factorA + chunkZ * factorB ^ limbo.getSeed());
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
package StevenDimDoors.mod_pocketDim.ticking;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||
import StevenDimDoors.mod_pocketDim.TileEntityRift;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewLinkData;
|
||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||
import StevenDimDoors.mod_pocketDim.core.IDimLink;
|
||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class RiftRegenerator implements IRegularTickReceiver {
|
||||
|
||||
private static final int RIFT_REGENERATION_INTERVAL = 100; //Regenerate random rifts every 100 ticks
|
||||
|
||||
private static final int RIFT_REGENERATION_INTERVAL = 200; //Regenerate random rifts every 200 ticks
|
||||
private static final int RIFTS_REGENERATED_PER_DIMENSION = 5;
|
||||
|
||||
private DDProperties properties;
|
||||
|
||||
public RiftRegenerator(IRegularTickSender sender, DDProperties properties)
|
||||
@@ -24,49 +28,33 @@ public class RiftRegenerator implements IRegularTickReceiver {
|
||||
@Override
|
||||
public void notifyTick()
|
||||
{
|
||||
regenerate();
|
||||
regenerateRiftsInAllWorlds();
|
||||
}
|
||||
|
||||
private void regenerate()
|
||||
|
||||
public static void regenerateRiftsInAllWorlds()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Regenerate rifts that have been replaced (not permanently removed) by players
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < 15 && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
//Regenerate rifts that have been replaced (not permanently removed) by players
|
||||
DDProperties properties = DDProperties.instance();
|
||||
|
||||
for (NewDimData dimension : PocketManager.getDimensions())
|
||||
{
|
||||
if (dimension.linkCount() > 0)
|
||||
{
|
||||
i++;
|
||||
NewLinkData link;
|
||||
|
||||
//actually gets the random rift based on the size of the list
|
||||
link = (NewLinkData) dimHelper.instance.getRandomLinkData(true);
|
||||
|
||||
if (link != null)
|
||||
{
|
||||
World world = dimHelper.getWorld(link.locDimID);
|
||||
|
||||
if (world != null && !mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord))
|
||||
{
|
||||
if (dimHelper.instance.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID) != null)
|
||||
{
|
||||
world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID);
|
||||
TileEntityRift rift = (TileEntityRift) world.getBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord);
|
||||
if (rift == null)
|
||||
{
|
||||
dimHelper.getWorld(link.locDimID).setBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord, new TileEntityRift());
|
||||
}
|
||||
rift.hasGrownRifts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
World world = DimensionManager.getWorld(dimension.id());
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
for (int count = 0; count < RIFTS_REGENERATED_PER_DIMENSION; count++)
|
||||
{
|
||||
IDimLink link = dimension.getRandomLink();
|
||||
Point4D source = link.source();
|
||||
if (!mod_pocketDim.blockRift.isBlockImmune(world, source.getX(), source.getY(), source.getZ()))
|
||||
{
|
||||
world.setBlock(source.getX(), source.getY(), source.getZ(), properties.RiftBlockID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("An exception occurred in RiftRegenerator.regenerate():");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user