Spatial Sky Renderer fixed

Changed Tooltips for Spatial Cells
Updated forge + mcp
This commit is contained in:
Sebastian Hartte
2020-06-13 15:51:04 +02:00
parent 5ec9600177
commit a4b16c21a3
12 changed files with 187 additions and 110 deletions
@@ -1,5 +1,6 @@
package appeng.spatial;
import appeng.core.AELog;
import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
@@ -14,32 +15,51 @@ import javax.annotation.Nullable;
*/
public final class SpatialDimensionExtraData {
private static final int FORMAT_VERSION = 1;
private static final int OFFSET_VERSION = 0;
private static final int OFFSET_CONTENT_SIZE = 1;
// Used to allow forward compatibility
private static final int CURRENT_FORMAT = 1;
private SpatialDimensionExtraData() {
/**
* The storage size of this dimension. This is dicateted by the pylon structure size used to perform
* the first transfer into this dimension. Once it's set, it cannot be changed anymore.
*/
private final BlockPos size;
public SpatialDimensionExtraData(BlockPos size) {
this.size = size;
}
public static PacketBuffer create(BlockPos contentSize) {
PacketBuffer extraData = new PacketBuffer(Unpooled.buffer());
extraData.writeByte(FORMAT_VERSION);
extraData.writeBlockPos(contentSize);
// Cut the buffer to minimal size
extraData.capacity(extraData.writerIndex());
return extraData;
public PacketBuffer write() {
PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
buf.writeByte(CURRENT_FORMAT);
buf.writeBlockPos(size);
buf.capacity(buf.writerIndex()); // This cuts the backing buffer to the required size
return buf;
}
private static boolean checkVersion(PacketBuffer data){
return data.getByte(OFFSET_VERSION) == FORMAT_VERSION;
public BlockPos getSize() {
return size;
}
public static BlockPos getContentSize(@Nullable PacketBuffer data) {
if (data == null || !checkVersion(data)) {
return BlockPos.ZERO;
@Nullable
public static SpatialDimensionExtraData read(@Nullable PacketBuffer buf) {
if (buf == null) {
return null;
}
data.readerIndex(OFFSET_CONTENT_SIZE);
return data.readBlockPos();
try {
buf.readerIndex(0);
byte version = buf.readByte();
if (version != CURRENT_FORMAT) {
// Currently no new format has been defined, as such anything but the current version is invalid
return null;
}
BlockPos size = buf.readBlockPos();
return new SpatialDimensionExtraData(size);
} catch (IndexOutOfBoundsException e) {
AELog.warn(e, "Failed to read spatial storage dimension data.");
return null;
}
}
}
@@ -22,33 +22,44 @@ package appeng.spatial;
import appeng.api.storage.ISpatialDimension;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.localization.GuiText;
import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Locale;
public class SpatialDimensionManager implements ISpatialDimension
public final class SpatialDimensionManager implements ISpatialDimension
{
public static final ISpatialDimension INSTANCE = new SpatialDimensionManager();
private static final String DIM_ID_PREFIX = "spatial_";
private SpatialDimensionManager() {
}
@Override
public ServerWorld getWorld(DimensionType cellDim) {
return DimensionManager.getWorld(getServer(), cellDim, true, true);
}
@Override
public DimensionType createNewCellDimension(BlockPos contentSize)
public DimensionType createNewCellDimension(BlockPos size)
{
ResourceLocation dimKey = findFreeDimensionId();
AELog.info("Allocating storage cell dimension '%s' for %d", dimKey);
AELog.info("Allocating storage cell dimension '%s'", dimKey);
PacketBuffer extraData = SpatialDimensionExtraData.create(contentSize);
PacketBuffer extraData = new SpatialDimensionExtraData(size).write();
return DimensionManager.registerDimension(dimKey, StorageCellModDimension.INSTANCE, extraData, true);
}
@@ -114,13 +125,48 @@ public class SpatialDimensionManager implements ISpatialDimension
}
@Override
public BlockPos getCellContentSize( DimensionType cellDim )
public BlockPos getCellDimensionSize(DimensionType cellDim )
{
if (!(cellDim.getModType() instanceof StorageCellModDimension)) {
return BlockPos.ZERO;
SpatialDimensionExtraData extraData = getExtraData(cellDim);
return extraData != null ? extraData.getSize() : BlockPos.ZERO;
}
@Override
public void addCellDimensionTooltip(DimensionType cellDim, List<ITextComponent> lines) {
// Check if the cell dimension type is even registered
ResourceLocation registryName = cellDim.getRegistryName();
if (registryName == null || !AppEng.MOD_ID.equals(registryName.getNamespace())) {
return;
}
return SpatialDimensionExtraData.getContentSize(cellDim.getData());
if (!registryName.getPath().startsWith(DIM_ID_PREFIX)) {
return;
}
// Add the actual stored size
BlockPos size = SpatialDimensionManager.INSTANCE.getCellDimensionSize(cellDim);
lines.add( GuiText.StoredSize.textComponent(size.getX(), size.getY(), size.getZ()));
// Add a serial number to allows players to keep different cells apart
int dimId;
try {
String numericIdPart = registryName.getPath().substring(DIM_ID_PREFIX.length());
dimId = Integer.parseUnsignedInt(numericIdPart);
} catch (NumberFormatException ignored) {
return;
}
// Try to make this a little more flavorful.
String serialNumber = String.format(Locale.ROOT, "SP-%04d", dimId);
lines.add(GuiText.SerialNumber.textComponent(serialNumber));
}
@Nullable
private SpatialDimensionExtraData getExtraData( DimensionType cellDim) {
if (!(cellDim.getModType() instanceof StorageCellModDimension)) {
return null;
}
return SpatialDimensionExtraData.read(cellDim.getData());
}
private static MinecraftServer getServer() {