Spatial Dimension Changes
This commit is contained in:
@@ -45,6 +45,10 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.block.AEBaseBlock;
|
||||
|
||||
/**
|
||||
* This block is used to fill empty space in spatial dimensions
|
||||
* and delinates the border of a spatial dimensions's usable space.
|
||||
*/
|
||||
public class BlockMatrixFrame extends AEBaseBlock
|
||||
{
|
||||
|
||||
@@ -52,9 +56,7 @@ public class BlockMatrixFrame extends AEBaseBlock
|
||||
|
||||
public BlockMatrixFrame()
|
||||
{
|
||||
super( Properties.create(MATERIAL).hardnessAndResistance(-1.0F, 6000000.0F).noDrops() );
|
||||
// FIXME this.setLightOpacity( 0 );
|
||||
// FIXME this.setOpaque( false );
|
||||
super( Properties.create(MATERIAL).hardnessAndResistance(-1.0F, 6000000.0F).notSolid().noDrops() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +78,8 @@ public class BlockMatrixFrame extends AEBaseBlock
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return VoxelShapes.fullCube();
|
||||
// This also prevents any blocks from being placed on this block!
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,7 @@ import net.minecraft.world.server.ServerWorld;
|
||||
class NullSpatialDimension implements ISpatialDimension
|
||||
{
|
||||
@Override
|
||||
public DimensionType createNewCellDimension(BlockPos size, int owner )
|
||||
public DimensionType createNewCellDimension(BlockPos size)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -40,12 +40,6 @@ class NullSpatialDimension implements ISpatialDimension
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellDimensionOwner( DimensionType cellStorageId )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCellDimensionOrigin( DimensionType cellStorageId )
|
||||
{
|
||||
|
||||
@@ -22,9 +22,9 @@ package appeng.core.worlddata;
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.spatial.StorageCellDimension;
|
||||
import appeng.spatial.StorageCellModDimension;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -32,15 +32,13 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
|
||||
public class SpatialDimensionManager implements ISpatialDimension
|
||||
{
|
||||
private static final int MAX_DIM_PER_PLAYER = 999;
|
||||
|
||||
private static final int MAX_CELL_DIMENSION = 512;
|
||||
private static final String DIM_ID_PREFIX = "storage_cell_";
|
||||
|
||||
@Override
|
||||
public ServerWorld getWorld(DimensionType cellDim) {
|
||||
@@ -48,32 +46,47 @@ public class SpatialDimensionManager implements ISpatialDimension
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionType createNewCellDimension( BlockPos contentSize, int owner )
|
||||
public DimensionType createNewCellDimension(BlockPos contentSize)
|
||||
{
|
||||
// Try to find a free dimension ID for the player
|
||||
ResourceLocation dimKey = null;
|
||||
for (int i = 1; i <= MAX_DIM_PER_PLAYER; i++) {
|
||||
dimKey = new ResourceLocation(AppEng.MOD_ID, "spatial_cell_" + owner + "_" + i);
|
||||
if (DimensionType.byName(dimKey) == null) {
|
||||
break;
|
||||
}
|
||||
dimKey = null;
|
||||
}
|
||||
if (dimKey == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StorageCellData data = new StorageCellData();
|
||||
data.contentDimension = contentSize;
|
||||
data.owner = owner;
|
||||
ResourceLocation dimKey = findFreeDimensionId();
|
||||
AELog.info("Allocating storage cell dimension '%s' for %d", dimKey);
|
||||
|
||||
PacketBuffer extraData = new PacketBuffer(Unpooled.buffer());
|
||||
extraData.writeInt(owner);
|
||||
extraData.writeBlockPos(contentSize);
|
||||
|
||||
return DimensionManager.registerDimension(dimKey, StorageCellModDimension.INSTANCE, extraData, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries finding the next free storage cell dimension ID based on the currently registered storage
|
||||
* cell dimensions.
|
||||
*/
|
||||
private ResourceLocation findFreeDimensionId() {
|
||||
int maxId = 0;
|
||||
for (DimensionType dimensionType : DimensionType.getAll()) {
|
||||
ResourceLocation regName = dimensionType.getRegistryName();
|
||||
if (regName == null || !AppEng.MOD_ID.equals(regName.getNamespace())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String path = regName.getPath();
|
||||
if (!path.startsWith(DIM_ID_PREFIX)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String numericIdPart = path.substring(DIM_ID_PREFIX.length());
|
||||
maxId = Math.max(Integer.parseUnsignedInt(numericIdPart), maxId);
|
||||
} catch (NumberFormatException e) {
|
||||
AELog.warn("Unparsable storage cell dimension id '%s'", path, e);
|
||||
}
|
||||
}
|
||||
|
||||
++maxId;
|
||||
|
||||
return new ResourceLocation(AppEng.MOD_ID, DIM_ID_PREFIX + maxId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCellDimension( DimensionType cellDim )
|
||||
{
|
||||
@@ -102,28 +115,10 @@ public class SpatialDimensionManager implements ISpatialDimension
|
||||
return cellDim.getModType() instanceof StorageCellModDimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCellDimensionOwner( DimensionType cellDim )
|
||||
{
|
||||
if (!(cellDim.getModType() instanceof StorageCellModDimension)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
PacketBuffer data = cellDim.getData();
|
||||
if (data == null) {
|
||||
return -1;
|
||||
}
|
||||
data.readerIndex(0);
|
||||
return data.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCellDimensionOrigin( DimensionType cellDim )
|
||||
{
|
||||
// A region file is 512x512 blocks (32x32 chunks),
|
||||
// to avoid creating the 4 regions around 0,0,0,
|
||||
// we move the origin to the middle of region 0,0
|
||||
return new BlockPos(512 / 2, 61, 512 / 2);
|
||||
return StorageCellDimension.REGION_CENTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,67 +136,4 @@ public class SpatialDimensionManager implements ISpatialDimension
|
||||
return data.readBlockPos();
|
||||
}
|
||||
|
||||
private BlockPos getBlockPosFromId( int id )
|
||||
{
|
||||
int signBits = id & 0b11;
|
||||
int offsetBits = id >> 2;
|
||||
int offsetScale = 1;
|
||||
int posx = MAX_CELL_DIMENSION / 2;
|
||||
int posz = MAX_CELL_DIMENSION / 2;
|
||||
|
||||
// find quadrant
|
||||
while( offsetBits != 0 )
|
||||
{
|
||||
posx += MAX_CELL_DIMENSION * offsetScale * ( offsetBits & 0b01 );
|
||||
posz += MAX_CELL_DIMENSION * offsetScale * ( offsetBits >> 1 & 0b01 );
|
||||
|
||||
offsetBits >>= 2;
|
||||
offsetScale <<= 1;
|
||||
}
|
||||
|
||||
// mirror in one of 4 directions
|
||||
if( ( signBits & 0b01 ) == 0 )
|
||||
{
|
||||
posx *= -1;
|
||||
}
|
||||
if( ( signBits & 0b10 ) == 0 )
|
||||
{
|
||||
posz *= -1;
|
||||
}
|
||||
|
||||
// offset from cell center
|
||||
posx -= 64;
|
||||
posz -= 64;
|
||||
|
||||
return new BlockPos( posx, 64, posz );
|
||||
}
|
||||
|
||||
private static class StorageCellData implements INBTSerializable<CompoundNBT>
|
||||
{
|
||||
private static final String NBT_OWNER_KEY = "owner";
|
||||
private static final String NBT_DIM_X_KEY = "dim_x";
|
||||
private static final String NBT_DIM_Y_KEY = "dim_y";
|
||||
private static final String NBT_DIM_Z_KEY = "dim_z";
|
||||
|
||||
public BlockPos contentDimension;
|
||||
public int owner;
|
||||
|
||||
@Override
|
||||
public CompoundNBT serializeNBT()
|
||||
{
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
nbt.putInt( NBT_DIM_X_KEY, this.contentDimension.getX() );
|
||||
nbt.putInt( NBT_DIM_Y_KEY, this.contentDimension.getY() );
|
||||
nbt.putInt( NBT_DIM_Z_KEY, this.contentDimension.getZ() );
|
||||
nbt.putInt( NBT_OWNER_KEY, this.owner );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT( CompoundNBT nbt )
|
||||
{
|
||||
this.contentDimension = new BlockPos( nbt.getInt( NBT_DIM_X_KEY ), nbt.getInt( NBT_DIM_Y_KEY ), nbt.getInt( NBT_DIM_Z_KEY ) );
|
||||
this.owner = nbt.getInt( NBT_OWNER_KEY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
package appeng.items.storage;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.implementations.TransitionResult;
|
||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.worlddata.SpatialDimensionManager;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.spatial.StorageHelper;
|
||||
import javafx.animation.Transition;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -33,27 +36,15 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import appeng.api.implementations.TransitionResult;
|
||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||
import appeng.api.storage.ISpatialDimension;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.capabilities.Capabilities;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.items.AEBaseItem;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell
|
||||
{
|
||||
private static final String NBT_CELL_ID_KEY = "StorageCellID";
|
||||
private static final String NBT_SIZE_X_KEY = "sizeX";
|
||||
private static final String NBT_SIZE_Y_KEY = "sizeY";
|
||||
private static final String NBT_SIZE_Z_KEY = "sizeZ";
|
||||
private static final String TAG_DIMENSION_ID = "dimension_id";
|
||||
|
||||
private final int maxRegion;
|
||||
|
||||
@@ -67,16 +58,12 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
|
||||
@Override
|
||||
public void addInformation(final ItemStack stack, final World world, final List<ITextComponent> lines, final ITooltipFlag advancedTooltips )
|
||||
{
|
||||
final DimensionType dimType = this.getStoredDimension( stack );
|
||||
if( dimType != null )
|
||||
{
|
||||
lines.add( GuiText.CellId.textComponent().appendText( ": " + dimType.getRegistryName() ) );
|
||||
}
|
||||
|
||||
final WorldCoord wc = this.getStoredSize( stack );
|
||||
if( wc.x > 0 )
|
||||
{
|
||||
lines.add( GuiText.StoredSize.textComponent().appendText( ": " + wc.x + " x " + wc.y + " x " + wc.z ) );
|
||||
if (advancedTooltips.isAdvanced()) {
|
||||
final DimensionType dimType = this.getStoredDimension(stack);
|
||||
if (dimType != null && dimType.getRegistryName() != null) {
|
||||
String ae2Id = dimType.getRegistryName().getPath();
|
||||
lines.add(GuiText.CellId.textComponent().appendText(": " + ae2Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,25 +79,14 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
|
||||
return this.maxRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldCoord getStoredSize( final ItemStack is )
|
||||
{
|
||||
final CompoundNBT c = is.getTag();
|
||||
if( c != null )
|
||||
{
|
||||
return new WorldCoord( c.getInt( NBT_SIZE_X_KEY ), c.getInt( NBT_SIZE_Y_KEY ), c.getInt( NBT_SIZE_Z_KEY ) );
|
||||
}
|
||||
return new WorldCoord( 0, 0, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionType getStoredDimension(final ItemStack is )
|
||||
{
|
||||
final CompoundNBT c = is.getTag();
|
||||
if( c != null && c.contains(NBT_CELL_ID_KEY) )
|
||||
if( c != null && c.contains(TAG_DIMENSION_ID) )
|
||||
{
|
||||
try {
|
||||
ResourceLocation dimTypeId = new ResourceLocation(c.getString( NBT_CELL_ID_KEY) );
|
||||
ResourceLocation dimTypeId = new ResourceLocation(c.getString(TAG_DIMENSION_ID) );
|
||||
return DimensionType.byName(dimTypeId);
|
||||
} catch (Exception e) {
|
||||
AELog.warn("Failed to retrieve storage cell dimension.", e);
|
||||
@@ -134,7 +110,7 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
|
||||
DimensionType storedDim = this.getStoredDimension( is );
|
||||
if( storedDim == null )
|
||||
{
|
||||
storedDim = manager.createNewCellDimension( targetSize, playerId );
|
||||
storedDim = manager.createNewCellDimension( targetSize);
|
||||
}
|
||||
|
||||
if (storedDim == null) {
|
||||
@@ -156,7 +132,7 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
|
||||
{
|
||||
BlockPos offset = manager.getCellDimensionOrigin( storedDim );
|
||||
|
||||
this.setStorageCell( is, storedDim, targetSize );
|
||||
this.setStoredDimension( is, storedDim);
|
||||
StorageHelper.getInstance()
|
||||
.swapRegions( w, min.x + 1, min.y + 1, min.z + 1, cellWorld, offset.getX(), offset.getY(),
|
||||
offset.getZ(), targetX - 1, targetY - 1,
|
||||
@@ -178,13 +154,9 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
|
||||
}
|
||||
}
|
||||
|
||||
private void setStorageCell( final ItemStack is, DimensionType dim, BlockPos size )
|
||||
private void setStoredDimension(final ItemStack is, DimensionType dim)
|
||||
{
|
||||
final CompoundNBT c = is.getOrCreateTag();
|
||||
|
||||
c.putString( NBT_CELL_ID_KEY, dim.getRegistryName().toString() );
|
||||
c.putInt( NBT_SIZE_X_KEY, size.getX() );
|
||||
c.putInt( NBT_SIZE_Y_KEY, size.getY() );
|
||||
c.putInt( NBT_SIZE_Z_KEY, size.getZ() );
|
||||
c.putString(TAG_DIMENSION_ID, dim.getRegistryName().toString() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,14 @@ import appeng.core.AppEng;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
// FIXME: Rename suffix to Dimension
|
||||
public class StorageCellDimension extends Dimension
|
||||
{
|
||||
|
||||
// A region file is 512x512 blocks (32x32 chunks),
|
||||
// to avoid creating the 4 regions around 0,0,0,
|
||||
// we move the origin to the middle of region 0,0
|
||||
public static final BlockPos REGION_CENTER = new BlockPos(512 / 2, 61, 512 / 2);
|
||||
|
||||
public StorageCellDimension(World world, DimensionType dimensionType) {
|
||||
// FIXME: check light value
|
||||
super(world, dimensionType, 1.0f);
|
||||
@@ -111,7 +115,7 @@ public class StorageCellDimension extends Dimension
|
||||
@Override
|
||||
public BlockPos getSpawnCoordinate()
|
||||
{
|
||||
return new BlockPos( 0, 0, 0 );
|
||||
return REGION_CENTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,21 +19,10 @@
|
||||
package appeng.spatial;
|
||||
|
||||
|
||||
import appeng.client.render.SpatialSkyRender;
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.ChunkGenerator;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.IRenderHandler;
|
||||
import net.minecraftforge.common.ModDimension;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
@@ -52,14 +41,4 @@ public class StorageCellModDimension extends ModDimension
|
||||
return StorageCellDimension::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer, boolean network) {
|
||||
super.write(buffer, network);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(PacketBuffer buffer, boolean network) {
|
||||
super.read(buffer, network);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user