Updated starmap registry with a proper API
This commit is contained in:
parent
55ac99acc6
commit
0ad270073e
5 changed files with 354 additions and 165 deletions
|
@ -0,0 +1,30 @@
|
|||
package cr0s.warpdrive.api;
|
||||
|
||||
import cr0s.warpdrive.data.VectorI;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface IStarMapRegistryTileEntity {
|
||||
|
||||
// get the registry type
|
||||
String getStarMapType();
|
||||
|
||||
// get the unique id
|
||||
UUID getUUID();
|
||||
|
||||
// get the area controlled by this tile entity
|
||||
AxisAlignedBB getStarMapArea();
|
||||
|
||||
// mass of the multi-block
|
||||
int getMass();
|
||||
|
||||
// isolation rate from radars
|
||||
double getIsolationRate();
|
||||
|
||||
// name to remove for Friend-or-Foe
|
||||
String getStarMapName();
|
||||
|
||||
// report an update in the area
|
||||
void onBlockUpdatedInArea(final VectorI vector);
|
||||
}
|
|
@ -6,6 +6,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockAbstractAccelerator extends Block {
|
||||
public final byte tier;
|
||||
|
@ -43,4 +44,10 @@ public class BlockAbstractAccelerator extends Block {
|
|||
public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
|
||||
WarpDrive.starMap.onBlockUpdated(world, x, y, z);
|
||||
super.breakBlock(world, x, y, z, block, metadata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package cr0s.warpdrive.block.movement;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import cr0s.warpdrive.api.IStarMapRegistryTileEntity;
|
||||
import cr0s.warpdrive.data.StarMapRegistryItem.EnumStarMapEntryType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -38,7 +40,7 @@ import cr0s.warpdrive.world.SpaceTeleporter;
|
|||
/**
|
||||
* @author Cr0s
|
||||
*/
|
||||
public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
||||
public class TileEntityShipCore extends TileEntityAbstractEnergy implements IStarMapRegistryTileEntity {
|
||||
|
||||
public int dx, dz;
|
||||
private int direction;
|
||||
|
@ -151,8 +153,8 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
if (uuid == null || (uuid.getMostSignificantBits() == 0 && uuid.getLeastSignificantBits() == 0)) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
// recovery registration, shouldn't be needed, in theory...
|
||||
WarpDrive.starMap.updateInRegistry(new StarMapRegistryItem(this));
|
||||
// recover registration, shouldn't be needed, in theory...
|
||||
WarpDrive.starMap.updateInRegistry(this);
|
||||
|
||||
TileEntity controllerFound = findControllerBlock();
|
||||
if (controllerFound == null) {
|
||||
|
@ -386,6 +388,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
}
|
||||
}
|
||||
isolationBlocksCount = newCount;
|
||||
double legacy_isolationRate = isolationRate;
|
||||
if (isolationBlocksCount >= WarpDriveConfig.RADAR_MIN_ISOLATION_BLOCKS) {
|
||||
isolationRate = Math.min(1.0, WarpDriveConfig.RADAR_MIN_ISOLATION_EFFECT
|
||||
+ (isolationBlocksCount - WarpDriveConfig.RADAR_MIN_ISOLATION_BLOCKS) // bonus blocks
|
||||
|
@ -394,7 +397,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
} else {
|
||||
isolationRate = 0.0D;
|
||||
}
|
||||
if (WarpDriveConfig.LOGGING_RADAR) {
|
||||
if (WarpDriveConfig.LOGGING_RADAR && (WarpDrive.isDev || legacy_isolationRate != isolationRate)) {
|
||||
WarpDrive.logger.info(this + " Isolation updated to " + isolationBlocksCount + " (" + String.format("%.1f", isolationRate * 100.0) + "%)");
|
||||
}
|
||||
}
|
||||
|
@ -1183,17 +1186,53 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
return;
|
||||
}
|
||||
|
||||
WarpDrive.starMap.updateInRegistry(new StarMapRegistryItem(this));
|
||||
WarpDrive.starMap.updateInRegistry(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (!worldObj.isRemote) {
|
||||
WarpDrive.starMap.removeFromRegistry(new StarMapRegistryItem(this));
|
||||
WarpDrive.starMap.removeFromRegistry(this);
|
||||
}
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
// IStarMapRegistryTileEntity overrides
|
||||
@Override
|
||||
public String getStarMapType() {
|
||||
return EnumStarMapEntryType.SHIP.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getStarMapArea() {
|
||||
return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMass() {
|
||||
return shipMass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIsolationRate() {
|
||||
return isolationRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStarMapName() {
|
||||
return shipName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockUpdatedInArea(VectorI vector) {
|
||||
// no operation
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package cr0s.warpdrive.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import cr0s.warpdrive.api.IStarMapRegistryTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.gen.ChunkProviderServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
@ -23,53 +28,76 @@ import cr0s.warpdrive.data.StarMapRegistryItem.EnumStarMapEntryType;
|
|||
* @author LemADEC
|
||||
*/
|
||||
public class StarMapRegistry {
|
||||
private final LinkedList<StarMapRegistryItem> registry;
|
||||
private final HashMap<Integer, CopyOnWriteArraySet<StarMapRegistryItem>> registry;
|
||||
private int countAdd = 0;
|
||||
private int countRemove = 0;
|
||||
private int countRead = 0;
|
||||
|
||||
public StarMapRegistry() {
|
||||
registry = new LinkedList<>();
|
||||
registry = new HashMap<>();
|
||||
}
|
||||
|
||||
public int searchInRegistry(StarMapRegistryItem entryKey) {
|
||||
int res = -1;
|
||||
public void updateInRegistry(IStarMapRegistryTileEntity tileEntity) {
|
||||
assert(tileEntity instanceof TileEntity);
|
||||
|
||||
for (int i = 0; i < registry.size(); i++) {
|
||||
StarMapRegistryItem entry = registry.get(i);
|
||||
|
||||
if (entry.dimensionId == entryKey.dimensionId && entry.x == entryKey.x && entry.y == entryKey.y && entry.z == entryKey.z) {
|
||||
return i;
|
||||
countRead++;
|
||||
if (WarpDriveConfig.LOGGING_STARMAP) {
|
||||
if (countRead % 1000 == 0) {
|
||||
WarpDrive.logger.info("Starmap registry stats: read " + countRead + " add " + countAdd + " remove " + countRemove + " => " + ((float) countRead) / (countRemove + countRead + countAdd) + "% read");
|
||||
}
|
||||
}
|
||||
CopyOnWriteArraySet<StarMapRegistryItem> setRegistryItems = registry.get(((TileEntity) tileEntity).getWorldObj().provider.dimensionId);
|
||||
if (setRegistryItems == null) {
|
||||
setRegistryItems = new CopyOnWriteArraySet<>();
|
||||
}
|
||||
for (StarMapRegistryItem registryItem : setRegistryItems) {
|
||||
if (registryItem.sameIdOrCoordinates(tileEntity)) {
|
||||
// already registered
|
||||
registryItem.update(tileEntity); // @TODO probably not thread safe
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean isInRegistry(StarMapRegistryItem entryKey) {
|
||||
return (searchInRegistry(entryKey) != -1);
|
||||
}
|
||||
|
||||
public void updateInRegistry(StarMapRegistryItem entryKey) {
|
||||
int idx = searchInRegistry(entryKey);
|
||||
|
||||
// update
|
||||
if (idx != -1) {
|
||||
registry.set(idx, entryKey);
|
||||
} else {
|
||||
registry.add(entryKey);
|
||||
if (WarpDriveConfig.LOGGING_STARMAP) {
|
||||
printRegistry("added");
|
||||
}
|
||||
// not found => add
|
||||
countAdd++;
|
||||
setRegistryItems.add(new StarMapRegistryItem(tileEntity));
|
||||
registry.put(((TileEntity) tileEntity).getWorldObj().provider.dimensionId, setRegistryItems);
|
||||
if (WarpDriveConfig.LOGGING_STARMAP) {
|
||||
printRegistry("added");
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromRegistry(StarMapRegistryItem entryKey) {
|
||||
int idx = searchInRegistry(entryKey);
|
||||
public void removeFromRegistry(IStarMapRegistryTileEntity tileEntity) {
|
||||
assert(tileEntity instanceof TileEntity);
|
||||
|
||||
if (idx != -1) {
|
||||
registry.remove(idx);
|
||||
if (WarpDriveConfig.LOGGING_STARMAP) {
|
||||
printRegistry("removed");
|
||||
countRead++;
|
||||
Set<StarMapRegistryItem> setRegistryItems = registry.get(((TileEntity) tileEntity).getWorldObj().provider.dimensionId);
|
||||
if (setRegistryItems == null) {
|
||||
// noting to remove
|
||||
return;
|
||||
}
|
||||
|
||||
for (StarMapRegistryItem registryItem : setRegistryItems) {
|
||||
if (registryItem.isSameTileEntity(tileEntity)) {
|
||||
// found it, remove and exit
|
||||
countRemove++;
|
||||
setRegistryItems.remove(registryItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// not found => ignore it
|
||||
}
|
||||
|
||||
public void onBlockUpdated(World world, final int x, final int y, final int z) {
|
||||
CopyOnWriteArraySet<StarMapRegistryItem> setStarMapRegistryItems = registry.get(world.provider.dimensionId);
|
||||
for (StarMapRegistryItem registryItem : setStarMapRegistryItems) {
|
||||
if (registryItem.contains(x, y, z)) {
|
||||
TileEntity tileEntity = world.getTileEntity(registryItem.x, registryItem.y, registryItem.z);
|
||||
if (tileEntity instanceof IStarMapRegistryTileEntity) {
|
||||
((IStarMapRegistryTileEntity) tileEntity).onBlockUpdatedInArea(new VectorI(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<StarMapRegistryItem> radarScan(TileEntity tileEntity, final int radius) {
|
||||
|
@ -78,16 +106,18 @@ public class StarMapRegistry {
|
|||
|
||||
// printRegistry();
|
||||
int radius2 = radius * radius;
|
||||
for (StarMapRegistryItem entry : registry) {
|
||||
double dX = entry.x - tileEntity.xCoord;
|
||||
double dY = entry.y - tileEntity.yCoord;
|
||||
double dZ = entry.z - tileEntity.zCoord;
|
||||
double distance2 = dX * dX + dY * dY + dZ * dZ;
|
||||
|
||||
if ( distance2 <= radius2
|
||||
&& (entry.isolationRate == 0.0D || tileEntity.getWorldObj().rand.nextDouble() >= entry.isolationRate)
|
||||
&& (entry.getSpaceCoordinates() != null)) {
|
||||
res.add(entry);
|
||||
for (Map.Entry<Integer, CopyOnWriteArraySet<StarMapRegistryItem>> entryDimension : registry.entrySet()) {
|
||||
for (StarMapRegistryItem entry : entryDimension.getValue()) {
|
||||
double dX = entry.x - tileEntity.xCoord;
|
||||
double dY = entry.y - tileEntity.yCoord;
|
||||
double dZ = entry.z - tileEntity.zCoord;
|
||||
double distance2 = dX * dX + dY * dY + dZ * dZ;
|
||||
|
||||
if (distance2 <= radius2
|
||||
&& (entry.isolationRate == 0.0D || tileEntity.getWorldObj().rand.nextDouble() >= entry.isolationRate)
|
||||
&& (entry.getSpaceCoordinates() != null)) {
|
||||
res.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,10 +127,14 @@ public class StarMapRegistry {
|
|||
public void printRegistry(final String trigger) {
|
||||
WarpDrive.logger.info("Starmap registry (" + registry.size() + " entries after " + trigger + "):");
|
||||
|
||||
for (StarMapRegistryItem entry : registry) {
|
||||
WarpDrive.logger.info("- " + entry.type + " '" + entry.name + "' @ "
|
||||
+ entry.dimensionId + ": " + entry.x + ", " + entry.y + ", " + entry.z
|
||||
+ " with " + entry.isolationRate + " isolation rate");
|
||||
for (Map.Entry<Integer, CopyOnWriteArraySet<StarMapRegistryItem>> entryDimension : registry.entrySet()) {
|
||||
String message = "";
|
||||
for (StarMapRegistryItem registryItem : entryDimension.getValue()) {
|
||||
message += "\n- " + registryItem.type + " '" + registryItem.name + "' @ "
|
||||
+ registryItem.dimensionId + ": " + registryItem.x + " " + registryItem.y + " " + registryItem.z
|
||||
+ " with " + registryItem.isolationRate + " isolation rate";
|
||||
}
|
||||
WarpDrive.logger.info("- " + entryDimension.getValue().size() + " entries in dimension " + entryDimension.getKey() + ": " + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,45 +146,39 @@ public class StarMapRegistry {
|
|||
core.validateShipSpatialParameters(reason);
|
||||
aabb1 = AxisAlignedBB.getBoundingBox(core.minX, core.minY, core.minZ, core.maxX, core.maxY, core.maxZ);
|
||||
|
||||
for (StarMapRegistryItem entry : registry) {
|
||||
// Skip cores in other worlds
|
||||
if (entry.dimensionId != core.getWorldObj().provider.dimensionId) {
|
||||
continue;
|
||||
}
|
||||
CopyOnWriteArraySet<StarMapRegistryItem> setRegistryItems = registry.get(core.getWorldObj().provider.dimensionId);
|
||||
if (setRegistryItems == null) {
|
||||
return false;
|
||||
}
|
||||
for (StarMapRegistryItem registryItem : setRegistryItems) {
|
||||
assert(registryItem.dimensionId == core.getWorldObj().provider.dimensionId);
|
||||
|
||||
// only check cores
|
||||
if (entry.type != EnumStarMapEntryType.SHIP) {
|
||||
if (registryItem.type != EnumStarMapEntryType.SHIP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip self
|
||||
if (entry.x == core.xCoord && entry.y == core.yCoord && entry.z == core.zCoord) {
|
||||
if (registryItem.x == core.xCoord && registryItem.y == core.yCoord && registryItem.z == core.zCoord) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip missing ship cores
|
||||
TileEntity tileEntity = core.getWorldObj().getTileEntity(entry.x, entry.y, entry.z);
|
||||
TileEntity tileEntity = core.getWorldObj().getTileEntity(registryItem.x, registryItem.y, registryItem.z);
|
||||
if (!(tileEntity instanceof TileEntityShipCore)) {
|
||||
continue;
|
||||
}
|
||||
TileEntityShipCore shipCore = (TileEntityShipCore) core.getWorldObj().getTileEntity(entry.x, entry.y, entry.z);
|
||||
TileEntityShipCore shipCore = (TileEntityShipCore) core.getWorldObj().getTileEntity(registryItem.x, registryItem.y, registryItem.z);
|
||||
|
||||
// Skip offline warp cores
|
||||
if (shipCore.controller == null || shipCore.controller.getMode() == EnumShipCoreMode.IDLE || !shipCore.validateShipSpatialParameters(reason)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Search for nearest warp cores
|
||||
double d3 = entry.x - core.xCoord;
|
||||
double d4 = entry.y - core.yCoord;
|
||||
double d5 = entry.z - core.zCoord;
|
||||
double distance2 = d3 * d3 + d4 * d4 + d5 * d5;
|
||||
|
||||
if (distance2 <= ((2 * WarpDriveConfig.SHIP_MAX_SIDE_SIZE) - 1) * ((2 * WarpDriveConfig.SHIP_MAX_SIDE_SIZE) - 1)) {
|
||||
// Compare warp-fields for intersection
|
||||
aabb2 = AxisAlignedBB.getBoundingBox(entry.minX, entry.minY, entry.minZ, entry.maxX, entry.maxY, entry.maxZ);
|
||||
if (aabb1.intersectsWith(aabb2)) {
|
||||
return true;
|
||||
}
|
||||
// Compare areas for intersection
|
||||
aabb2 = AxisAlignedBB.getBoundingBox(registryItem.minX, registryItem.minY, registryItem.minZ, registryItem.maxX, registryItem.maxY, registryItem.maxZ);
|
||||
if (aabb1.intersectsWith(aabb2)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,65 +187,76 @@ public class StarMapRegistry {
|
|||
|
||||
// do not call during tileEntity construction (readFromNBT and validate)
|
||||
private void cleanup() {
|
||||
LocalProfiler.start("StarMapRegistry cleanup");
|
||||
LocalProfiler.start("Starmap registry cleanup");
|
||||
|
||||
StarMapRegistryItem entry;
|
||||
boolean isValid;
|
||||
for (int i = registry.size() - 1; i >= 0; i--) {
|
||||
entry = registry.get(i);
|
||||
isValid = false;
|
||||
if (entry != null) {
|
||||
WorldServer world = DimensionManager.getWorld(entry.dimensionId);
|
||||
// skip unloaded worlds
|
||||
if (world == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isLoaded;
|
||||
if (world.getChunkProvider() instanceof ChunkProviderServer) {
|
||||
ChunkProviderServer chunkProviderServer = (ChunkProviderServer) world.getChunkProvider();
|
||||
try {
|
||||
isLoaded = chunkProviderServer.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(entry.x >> 4, entry.z >> 4));
|
||||
} catch (NoSuchFieldError exception) {
|
||||
isLoaded = chunkProviderServer.chunkExists(entry.x >> 4, entry.z >> 4);
|
||||
}
|
||||
} else {
|
||||
isLoaded = world.getChunkProvider().chunkExists(entry.x >> 4, entry.z >> 4);
|
||||
}
|
||||
// skip unloaded chunks
|
||||
if (!isLoaded) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get block and tile entity
|
||||
Block block = world.getBlock(entry.x, entry.y, entry.z);
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(entry.x, entry.y, entry.z);
|
||||
isValid = true;
|
||||
switch (entry.type) {
|
||||
case UNDEFINED: break;
|
||||
case SHIP:
|
||||
isValid = block == WarpDrive.blockShipCore && tileEntity != null && !tileEntity.isInvalid();
|
||||
break;
|
||||
case JUMPGATE: break;
|
||||
case PLANET: break;
|
||||
case STAR: break;
|
||||
case STRUCTURE: break;
|
||||
case WARP_ECHO: break;
|
||||
default: break;
|
||||
}
|
||||
boolean isValid;
|
||||
for (Map.Entry<Integer, CopyOnWriteArraySet<StarMapRegistryItem>> entryDimension : registry.entrySet()) {
|
||||
WorldServer world = DimensionManager.getWorld(entryDimension.getKey());
|
||||
// skip unloaded worlds
|
||||
if (world == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
if (WarpDriveConfig.LOGGING_STARMAP) {
|
||||
if (entry == null) {
|
||||
WarpDrive.logger.info("Cleaning up starmap object ~null~");
|
||||
for (StarMapRegistryItem registryItem : entryDimension.getValue()) {
|
||||
isValid = false;
|
||||
if (registryItem != null) {
|
||||
|
||||
boolean isLoaded;
|
||||
if (world.getChunkProvider() instanceof ChunkProviderServer) {
|
||||
ChunkProviderServer chunkProviderServer = (ChunkProviderServer) world.getChunkProvider();
|
||||
try {
|
||||
isLoaded = chunkProviderServer.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(registryItem.x >> 4, registryItem.z >> 4));
|
||||
} catch (NoSuchFieldError exception) {
|
||||
isLoaded = chunkProviderServer.chunkExists(registryItem.x >> 4, registryItem.z >> 4);
|
||||
}
|
||||
} else {
|
||||
WarpDrive.logger.info("Cleaning up starmap object " + entry.type + " at "
|
||||
+ entry.dimensionId + " " + entry.x + " " + entry.y + " " + entry.z);
|
||||
isLoaded = world.getChunkProvider().chunkExists(registryItem.x >> 4, registryItem.z >> 4);
|
||||
}
|
||||
// skip unloaded chunks
|
||||
if (!isLoaded) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get block and tile entity
|
||||
Block block = world.getBlock(registryItem.x, registryItem.y, registryItem.z);
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(registryItem.x, registryItem.y, registryItem.z);
|
||||
isValid = true;
|
||||
switch (registryItem.type) {
|
||||
case UNDEFINED:
|
||||
break;
|
||||
case SHIP:
|
||||
isValid = block == WarpDrive.blockShipCore && tileEntity != null && !tileEntity.isInvalid();
|
||||
break;
|
||||
case JUMPGATE:
|
||||
break;
|
||||
case PLANET:
|
||||
break;
|
||||
case STAR:
|
||||
break;
|
||||
case STRUCTURE:
|
||||
break;
|
||||
case WARP_ECHO:
|
||||
break;
|
||||
case ACCELERATOR:
|
||||
isValid = block == WarpDrive.blockAcceleratorController && tileEntity != null && !tileEntity.isInvalid();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
registry.remove(i);
|
||||
|
||||
if (!isValid) {
|
||||
if (WarpDriveConfig.LOGGING_STARMAP) {
|
||||
if (registryItem == null) {
|
||||
WarpDrive.logger.info("Cleaning up starmap object ~null~");
|
||||
} else {
|
||||
WarpDrive.logger.info("Cleaning up starmap object " + registryItem.type + " at "
|
||||
+ registryItem.dimensionId + " " + registryItem.x + " " + registryItem.y + " " + registryItem.z);
|
||||
}
|
||||
}
|
||||
countRemove++;
|
||||
entryDimension.getValue().remove(registryItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,67 +1,141 @@
|
|||
package cr0s.warpdrive.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import cr0s.warpdrive.block.movement.TileEntityShipCore;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IStarMapRegistryTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
public class StarMapRegistryItem extends GlobalPosition {
|
||||
public EnumStarMapEntryType type;
|
||||
public UUID uuid;
|
||||
public final EnumStarMapEntryType type;
|
||||
public final UUID uuid;
|
||||
public int maxX, maxY, maxZ;
|
||||
public int minX, minY, minZ;
|
||||
public int volume;
|
||||
public int mass;
|
||||
public double isolationRate = 0.0D;
|
||||
public String name = "default";
|
||||
|
||||
public enum EnumStarMapEntryType {
|
||||
UNDEFINED(0),
|
||||
SHIP(1), // a ship core
|
||||
JUMPGATE(2), // a jump gate
|
||||
PLANET(3), // a planet (a transition plane allowing to move to another dimension)
|
||||
STAR(4), // a star
|
||||
STRUCTURE(5), // a structure from WorldGeneration (moon, asteroid field, etc.)
|
||||
WARP_ECHO(6); // remains of a warp
|
||||
UNDEFINED(0, "-undefined-"),
|
||||
SHIP(1, "ship"), // a ship core
|
||||
JUMPGATE(2, "jumpgate"), // a jump gate
|
||||
PLANET(3, "planet"), // a planet (a transition plane allowing to move to another dimension)
|
||||
STAR(4, "star"), // a star
|
||||
STRUCTURE(5, "structure"), // a structure from WorldGeneration (moon, asteroid field, etc.)
|
||||
WARP_ECHO(6, "warp_echo"), // remains of a warp
|
||||
ACCELERATOR(7, "accelerator"); // an accelerator setup
|
||||
|
||||
private final int code;
|
||||
private final int id;
|
||||
private final String name;
|
||||
|
||||
EnumStarMapEntryType(int code) {
|
||||
this.code = code;
|
||||
// cached values
|
||||
public static final int length;
|
||||
private static final HashMap<String, EnumStarMapEntryType> mapNames = new HashMap<>();
|
||||
|
||||
static {
|
||||
length = EnumStarMapEntryType.values().length;
|
||||
for (EnumStarMapEntryType enumStarMapEntryType : values()) {
|
||||
mapNames.put(enumStarMapEntryType.getName(), enumStarMapEntryType);
|
||||
}
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return code;
|
||||
EnumStarMapEntryType(final int id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static EnumStarMapEntryType getByName(final String name) {
|
||||
return mapNames.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
public StarMapRegistryItem(
|
||||
final EnumStarMapEntryType type, final UUID uuid,
|
||||
final int dimensionId, final int x, final int y, final int z,
|
||||
final int maxX, final int maxY, final int maxZ,
|
||||
final int minX, final int minY, final int minZ,
|
||||
final int volume, final double isolationRate,
|
||||
final String name) {
|
||||
final EnumStarMapEntryType type, final UUID uuid,
|
||||
final int dimensionId, final int x, final int y, final int z,
|
||||
final AxisAlignedBB aabbArea,
|
||||
final int mass, final double isolationRate,
|
||||
final String name) {
|
||||
super(dimensionId, x, y, z);
|
||||
this.type = type;
|
||||
this.uuid = uuid;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.minZ = minZ;
|
||||
this.volume = volume;
|
||||
if (aabbArea == null) {
|
||||
this.maxX = x;
|
||||
this.maxY = y;
|
||||
this.maxZ = z;
|
||||
this.minX = x;
|
||||
this.minY = y;
|
||||
this.minZ = z;
|
||||
} else {
|
||||
this.maxX = (int) aabbArea.maxX;
|
||||
this.maxY = (int) aabbArea.maxY;
|
||||
this.maxZ = (int) aabbArea.maxZ;
|
||||
this.minX = (int) aabbArea.minX;
|
||||
this.minY = (int) aabbArea.minY;
|
||||
this.minZ = (int) aabbArea.minZ;
|
||||
}
|
||||
this.mass = mass;
|
||||
this.isolationRate = isolationRate;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public StarMapRegistryItem(TileEntityShipCore core) {
|
||||
public StarMapRegistryItem(IStarMapRegistryTileEntity tileEntity) {
|
||||
this(
|
||||
EnumStarMapEntryType.SHIP, core.uuid,
|
||||
core.getWorldObj().provider.dimensionId, core.xCoord, core.yCoord, core.zCoord,
|
||||
core.maxX, core.maxY, core.maxZ,
|
||||
core.minX, core.minY, core.minZ,
|
||||
core.shipMass, core.isolationRate,
|
||||
core.shipName);
|
||||
EnumStarMapEntryType.getByName(tileEntity.getStarMapType()), tileEntity.getUUID(),
|
||||
((TileEntity) tileEntity).getWorldObj().provider.dimensionId,
|
||||
((TileEntity) tileEntity).xCoord, ((TileEntity) tileEntity).yCoord, ((TileEntity) tileEntity).zCoord,
|
||||
tileEntity.getStarMapArea(),
|
||||
tileEntity.getMass(), tileEntity.getIsolationRate(),
|
||||
tileEntity.getStarMapName());
|
||||
}
|
||||
|
||||
public boolean sameIdOrCoordinates(final IStarMapRegistryTileEntity tileEntity) {
|
||||
assert(tileEntity instanceof TileEntity);
|
||||
return uuid == tileEntity.getUUID()
|
||||
|| dimensionId == ((TileEntity) tileEntity).getWorldObj().provider.dimensionId
|
||||
&& x == ((TileEntity) tileEntity).xCoord
|
||||
&& y == ((TileEntity) tileEntity).yCoord
|
||||
&& z == ((TileEntity) tileEntity).zCoord;
|
||||
}
|
||||
|
||||
public void update(final IStarMapRegistryTileEntity tileEntity) {
|
||||
if (WarpDrive.isDev) {
|
||||
assert (tileEntity instanceof TileEntity);
|
||||
assert (sameIdOrCoordinates(tileEntity));
|
||||
}
|
||||
AxisAlignedBB aabbArea = tileEntity.getStarMapArea();
|
||||
if (aabbArea != null) {
|
||||
maxX = (int) aabbArea.maxX;
|
||||
maxY = (int) aabbArea.maxY;
|
||||
maxZ = (int) aabbArea.maxZ;
|
||||
minX = (int) aabbArea.minX;
|
||||
minY = (int) aabbArea.minY;
|
||||
minZ = (int) aabbArea.minZ;
|
||||
}
|
||||
mass = tileEntity.getMass();
|
||||
isolationRate = tileEntity.getIsolationRate();
|
||||
name = tileEntity.getStarMapName();
|
||||
}
|
||||
|
||||
public boolean isSameTileEntity(final IStarMapRegistryTileEntity tileEntity) {
|
||||
assert(tileEntity instanceof TileEntity);
|
||||
return dimensionId == ((TileEntity) tileEntity).getWorldObj().provider.dimensionId
|
||||
&& x == ((TileEntity) tileEntity).xCoord
|
||||
&& y == ((TileEntity) tileEntity).yCoord
|
||||
&& z == ((TileEntity) tileEntity).zCoord;
|
||||
}
|
||||
|
||||
public boolean contains(final int x, final int y, final int z) {
|
||||
return minX <= x && x <= maxX && minY <= y && y <= maxY && minZ <= z && z <= maxZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue