Merge pull request #174 from SenseiKiwi/master
Fixed Crash on World Creation
This commit is contained in:
@@ -230,8 +230,11 @@ public class EventHookContainer
|
|||||||
{
|
{
|
||||||
// Schedule rift regeneration for any links located in this chunk.
|
// Schedule rift regeneration for any links located in this chunk.
|
||||||
// This event runs on both the client and server. Allow server only.
|
// This event runs on both the client and server. Allow server only.
|
||||||
|
// Also, check that PocketManager is loaded, because onChunkLoad() can
|
||||||
|
// fire while chunks are being initialized in a new world, before
|
||||||
|
// onWorldLoad() fires.
|
||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
if (!chunk.worldObj.isRemote)
|
if (!chunk.worldObj.isRemote && PocketManager.isLoaded())
|
||||||
{
|
{
|
||||||
NewDimData dimension = PocketManager.getDimensionData(chunk.worldObj);
|
NewDimData dimension = PocketManager.getDimensionData(chunk.worldObj);
|
||||||
for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition))
|
for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition))
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class PocketManager
|
|||||||
// that any link destinations must be real dimensions controlled by PocketManager.
|
// that any link destinations must be real dimensions controlled by PocketManager.
|
||||||
|
|
||||||
public InnerDimData(int id, InnerDimData parent, boolean isPocket, boolean isDungeon,
|
public InnerDimData(int id, InnerDimData parent, boolean isPocket, boolean isDungeon,
|
||||||
IUpdateWatcher<ClientLinkData> linkWatcher)
|
IUpdateWatcher<ClientLinkData> linkWatcher)
|
||||||
{
|
{
|
||||||
super(id, parent, isPocket, isDungeon, linkWatcher);
|
super(id, parent, isPocket, isDungeon, linkWatcher);
|
||||||
}
|
}
|
||||||
@@ -151,29 +151,29 @@ public class PocketManager
|
|||||||
originPoint=this.origin.toPoint3D();
|
originPoint=this.origin.toPoint3D();
|
||||||
}
|
}
|
||||||
return new PackedDimData(this.id, depth, this.packDepth, parentID, this.root().id(), orientation,
|
return new PackedDimData(this.id, depth, this.packDepth, parentID, this.root().id(), orientation,
|
||||||
isDungeon, isFilled,packedDungeon, originPoint, ChildIDs, Links, Tails);
|
isDungeon, isFilled,packedDungeon, originPoint, ChildIDs, Links, Tails);
|
||||||
// FIXME: IMPLEMENTATION PLZTHX
|
// FIXME: IMPLEMENTATION PLZTHX
|
||||||
//I tried
|
//I tried
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ClientLinkWatcher implements IUpdateWatcher<ClientLinkData>
|
private static class ClientLinkWatcher implements IUpdateWatcher<ClientLinkData>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onCreated(ClientLinkData link)
|
public void onCreated(ClientLinkData link)
|
||||||
{
|
{
|
||||||
Point4D source = link.point;
|
Point4D source = link.point;
|
||||||
NewDimData dimension = getDimensionData(source.getDimension());
|
NewDimData dimension = getDimensionData(source.getDimension());
|
||||||
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation);
|
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleted(ClientLinkData link)
|
public void onDeleted(ClientLinkData link)
|
||||||
{
|
{
|
||||||
Point4D source = link.point;
|
Point4D source = link.point;
|
||||||
getDimensionData(source.getDimension()).deleteLink(source);
|
getDimensionData(source.getDimension()).deleteLink(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ClientDimWatcher implements IUpdateWatcher<ClientDimData>
|
private static class ClientDimWatcher implements IUpdateWatcher<ClientDimData>
|
||||||
{
|
{
|
||||||
@@ -582,7 +582,7 @@ public class PocketManager
|
|||||||
//Steven
|
//Steven
|
||||||
DimensionManager.registerDimension(dimensionID, mod_pocketDim.properties.PocketProviderID);
|
DimensionManager.registerDimension(dimensionID, mod_pocketDim.properties.PocketProviderID);
|
||||||
}
|
}
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NewDimData getDimensionData(World world)
|
public static NewDimData getDimensionData(World world)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package StevenDimDoors.mod_pocketDim.tileentities;
|
package StevenDimDoors.mod_pocketDim.tileentities;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -42,8 +41,7 @@ public class TileEntityRift extends DDTileEntityBase
|
|||||||
public int yOffset = 0;
|
public int yOffset = 0;
|
||||||
public int zOffset = 0;
|
public int zOffset = 0;
|
||||||
public boolean shouldClose = false;
|
public boolean shouldClose = false;
|
||||||
|
public Point4D nearestRiftLocation = null;
|
||||||
public DimLink nearestRiftData;
|
|
||||||
public int spawnedEndermenID = 0;
|
public int spawnedEndermenID = 0;
|
||||||
|
|
||||||
public TileEntityRift()
|
public TileEntityRift()
|
||||||
@@ -64,20 +62,20 @@ public class TileEntityRift extends DDTileEntityBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worldObj.getBlockId(xCoord, yCoord, zCoord) != mod_pocketDim.blockRift.blockID)
|
if (worldObj.getBlockId(xCoord, yCoord, zCoord) != mod_pocketDim.blockRift.blockID)
|
||||||
{
|
{
|
||||||
this.invalidate();
|
invalidate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this rift should render white closing particles and
|
// Check if this rift should render white closing particles and
|
||||||
// spread the closing effect to other rifts nearby.
|
// spread the closing effect to other rifts nearby.
|
||||||
if (this.shouldClose)
|
if (shouldClose)
|
||||||
{
|
{
|
||||||
closeRift();
|
closeRift();
|
||||||
return;
|
return;
|
||||||
@@ -85,13 +83,13 @@ public class TileEntityRift extends DDTileEntityBase
|
|||||||
|
|
||||||
if (updateTimer >= UPDATE_PERIOD)
|
if (updateTimer >= UPDATE_PERIOD)
|
||||||
{
|
{
|
||||||
this.spawnEndermen(mod_pocketDim.properties);
|
spawnEndermen(mod_pocketDim.properties);
|
||||||
updateTimer = 0;
|
updateTimer = 0;
|
||||||
}
|
}
|
||||||
else if (updateTimer == UPDATE_PERIOD / 2)
|
else if (updateTimer == UPDATE_PERIOD / 2)
|
||||||
{
|
{
|
||||||
this.calculateParticleOffsets();
|
updateNearestRift();
|
||||||
this.spread(mod_pocketDim.properties);
|
spread(mod_pocketDim.properties);
|
||||||
}
|
}
|
||||||
updateTimer++;
|
updateTimer++;
|
||||||
}
|
}
|
||||||
@@ -137,41 +135,28 @@ public class TileEntityRift extends DDTileEntityBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateNearestRift()
|
|
||||||
{
|
|
||||||
nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord);
|
|
||||||
return (nearestRiftData != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeRift()
|
private void closeRift()
|
||||||
{
|
{
|
||||||
NewDimData dimension = PocketManager.getDimensionData(worldObj);
|
NewDimData dimension = PocketManager.getDimensionData(worldObj);
|
||||||
if (closeTimer == CLOSING_PERIOD / 2)
|
if (closeTimer == CLOSING_PERIOD / 2)
|
||||||
{
|
{
|
||||||
ArrayList<DimLink> riftLinks = dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord);
|
for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord))
|
||||||
if (riftLinks.size() > 0)
|
|
||||||
{
|
{
|
||||||
for (DimLink riftLink : riftLinks)
|
Point4D location = riftLink.source();
|
||||||
|
TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ());
|
||||||
|
if (rift != null && !rift.shouldClose)
|
||||||
{
|
{
|
||||||
Point4D location = riftLink.source();
|
rift.shouldClose = true;
|
||||||
TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ());
|
rift.onInventoryChanged();
|
||||||
if (rift != null)
|
|
||||||
{
|
|
||||||
rift.shouldClose = true;
|
|
||||||
rift.onInventoryChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (closeTimer >= CLOSING_PERIOD)
|
if (closeTimer >= CLOSING_PERIOD)
|
||||||
{
|
{
|
||||||
if (!this.worldObj.isRemote)
|
DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj);
|
||||||
|
if (link != null)
|
||||||
{
|
{
|
||||||
DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj);
|
dimension.deleteLink(link);
|
||||||
if (link != null)
|
|
||||||
{
|
|
||||||
dimension.deleteLink(link);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||||
worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false);
|
worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false);
|
||||||
@@ -179,14 +164,30 @@ public class TileEntityRift extends DDTileEntityBase
|
|||||||
closeTimer++;
|
closeTimer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateParticleOffsets()
|
public boolean updateNearestRift()
|
||||||
{
|
{
|
||||||
if (updateNearestRift())
|
Point4D previousNearest = nearestRiftLocation;
|
||||||
|
DimLink nearestRiftLink = PocketManager.getDimensionData(worldObj).findNearestRift(
|
||||||
|
worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord);
|
||||||
|
|
||||||
|
nearestRiftLocation = (nearestRiftLink == null) ? null : nearestRiftLink.source();
|
||||||
|
|
||||||
|
// If the nearest rift location changed, then update particle offsets
|
||||||
|
if (previousNearest != nearestRiftLocation &&
|
||||||
|
(previousNearest == null || nearestRiftLocation == null || !previousNearest.equals(nearestRiftLocation)))
|
||||||
{
|
{
|
||||||
Point4D location = nearestRiftData.source();
|
updateParticleOffsets();
|
||||||
this.xOffset = this.xCoord - location.getX();
|
}
|
||||||
this.yOffset = this.yCoord - location.getY();
|
return (nearestRiftLocation != null);
|
||||||
this.zOffset = this.zCoord - location.getZ();
|
}
|
||||||
|
|
||||||
|
private void updateParticleOffsets()
|
||||||
|
{
|
||||||
|
if (nearestRiftLocation != null)
|
||||||
|
{
|
||||||
|
this.xOffset = this.xCoord - nearestRiftLocation.getX();
|
||||||
|
this.yOffset = this.yCoord - nearestRiftLocation.getY();
|
||||||
|
this.zOffset = this.zCoord - nearestRiftLocation.getZ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user