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
@@ -222,7 +222,7 @@ public class BlockCableBus extends AEBaseTileBlock<TileCableBus> /* FIXME implem
double z = target.getHitVec().z;
// FIXME: Check how this looks, probably like shit, maybe provide parts the ability to supply particle textures???
effectRenderer.addEffect(new CableBusBreakingParticle(world, x, y, z, texture)
.multipleParticleScaleBy(0.8F));
.multiplyParticleScaleBy(0.8F));
}
return true;
@@ -20,12 +20,15 @@ package appeng.capabilities;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import appeng.api.storage.ISpatialDimension;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld;
import java.util.List;
class NullSpatialDimension implements ISpatialDimension
{
@@ -47,6 +50,15 @@ class NullSpatialDimension implements ISpatialDimension
}
@Override
public BlockPos getCellDimensionSize(DimensionType cellDim) {
return BlockPos.ZERO;
}
@Override
public void addCellDimensionTooltip(DimensionType cellDim, List<ITextComponent> tooltip) {
}
@Override
public ServerWorld getWorld(DimensionType cellStorageId )
{
return null;
@@ -57,10 +69,4 @@ class NullSpatialDimension implements ISpatialDimension
{
return false;
}
@Override
public BlockPos getCellContentSize( DimensionType cellDimId )
{
return null;
}
}
@@ -21,9 +21,11 @@ package appeng.client.render;
import java.util.Random;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.renderer.Quaternion;
import net.minecraftforge.client.SkyRenderHandler;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
@@ -36,7 +38,7 @@ import net.minecraftforge.client.IRenderHandler;
//TODO https://github.com/MinecraftForge/MinecraftForge/pull/6537
public class SpatialSkyRender implements IRenderHandler
public class SpatialSkyRender implements SkyRenderHandler
{
private static final SpatialSkyRender INSTANCE = new SpatialSkyRender();
@@ -55,14 +57,17 @@ public class SpatialSkyRender implements IRenderHandler
return INSTANCE;
}
@Override
public void render( final int ticks, final float partialTicks, final ClientWorld world, final Minecraft mc )
{
//FIXME, Do not use this until the above PR is merged.
if (true) {
return;
}
private static final Quaternion[] SKYBOX_SIDE_ROTATIONS = {
Quaternion.ONE,
new Quaternion( 90.0F, 0.0F, 0.0F, true ),
new Quaternion( -90.0F, 0.0F, 0.0F, true ),
new Quaternion( 180.0F, 0.0F, 0.0F, true ),
new Quaternion( 0.0F, 0.0F, 90.0F, true ),
new Quaternion( 0.0F, 0.0F, -90.0F, true ),
};
@Override
public void render(int ticks, float partialTicks, MatrixStack matrixStack, ClientWorld world, Minecraft mc) {
final long now = System.currentTimeMillis();
if( now - this.cycle > 2000 )
{
@@ -76,46 +81,22 @@ public class SpatialSkyRender implements IRenderHandler
fade /= 1000;
fade = 0.15f * ( 1.0f - Math.abs( ( fade - 1.0f ) * ( fade - 1.0f ) ) );
GlStateManager.disableFog();
GlStateManager.disableAlphaTest();
RenderSystem.disableFog();
RenderSystem.disableAlphaTest();
RenderSystem.disableBlend();
GlStateManager.depthMask( false );
RenderSystem.depthMask( false );
RenderSystem.color4f( 0.0f, 0.0f, 0.0f, 1.0f );
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder VertexBuffer = tessellator.getBuffer();
// This renders a skybox around the player at a far, fixed distance from them.
// The skybox is pitch black and untextured
for( int i = 0; i < 6; ++i )
for (Quaternion rotation : SKYBOX_SIDE_ROTATIONS)
{
GlStateManager.pushMatrix();
matrixStack.push();
matrixStack.rotate(rotation);
if( i == 1 )
{
GlStateManager.rotatef( 90.0F, 1.0F, 0.0F, 0.0F );
}
if( i == 2 )
{
GlStateManager.rotatef( -90.0F, 1.0F, 0.0F, 0.0F );
}
if( i == 3 )
{
GlStateManager.rotatef( 180.0F, 1.0F, 0.0F, 0.0F );
}
if( i == 4 )
{
GlStateManager.rotatef( 90.0F, 0.0F, 0.0F, 1.0F );
}
if( i == 5 )
{
GlStateManager.rotatef( -90.0F, 0.0F, 0.0F, 1.0F );
}
GlStateManager.disableTexture();
RenderSystem.disableTexture();
VertexBuffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION );
VertexBuffer.pos( -100.0D, -100.0D, -100.0D ).endVertex();
VertexBuffer.pos( -100.0D, -100.0D, 100.0D ).endVertex();
@@ -123,19 +104,19 @@ public class SpatialSkyRender implements IRenderHandler
VertexBuffer.pos( 100.0D, -100.0D, -100.0D ).endVertex();
tessellator.draw();
RenderSystem.enableTexture();
GlStateManager.popMatrix();
matrixStack.pop();
}
GlStateManager.depthMask( true );
RenderSystem.depthMask( true );
if( fade > 0.0f )
{
GlStateManager.disableFog();
GlStateManager.disableAlphaTest();
RenderSystem.disableFog();
RenderSystem.disableAlphaTest();
RenderSystem.enableBlend();
GlStateManager.disableTexture();
GlStateManager.depthMask( false );
GlStateManager.blendFuncSeparate( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0 );
RenderSystem.disableTexture();
RenderSystem.depthMask( false );
RenderSystem.blendFuncSeparate( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0 );
RenderHelper.disableStandardItemLighting();
@@ -143,11 +124,11 @@ public class SpatialSkyRender implements IRenderHandler
GL11.glCallList( this.dspList );
}
GlStateManager.depthMask( true );
RenderSystem.depthMask( true );
RenderSystem.enableBlend();
GlStateManager.enableAlphaTest();
RenderSystem.enableAlphaTest();
RenderSystem.enableTexture();
GlStateManager.enableFog();
RenderSystem.enableFog();
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
@@ -155,8 +136,8 @@ public class SpatialSkyRender implements IRenderHandler
private void renderTwinkles()
{
final Tessellator tessellator = Tessellator.getInstance();
final BufferBuilder VertexBuffer = tessellator.getBuffer();
VertexBuffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION );
final BufferBuilder vb = tessellator.getBuffer();
vb.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION );
for( int i = 0; i < 50; ++i )
{
@@ -196,7 +177,7 @@ public class SpatialSkyRender implements IRenderHandler
final double d23 = d17 * d12 - d20 * d13;
final double d24 = d23 * d9 - d21 * d10;
final double d25 = d21 * d9 + d23 * d10;
VertexBuffer.pos( x + d24, y + d22, z + d25 ).endVertex();
vb.pos( x + d24, y + d22, z + d25 ).endVertex();
}
}
}
@@ -92,8 +92,10 @@ public enum GuiText
QuartzCuttingKnife,
// spatial
SpatialCapacity,
StoredSize,
CellId,
Unformatted,
SerialNumber,
CopyMode,
CopyModeDesc,
@@ -215,4 +217,8 @@ public enum GuiText
return new TranslationTextComponent(getTranslationKey());
}
public ITextComponent textComponent(Object... args) {
return new TranslationTextComponent(getTranslationKey(), args);
}
}
@@ -34,6 +34,8 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.api.distmarker.Dist;
@@ -58,11 +60,17 @@ 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.Unformatted.textComponent().applyTextStyle(TextFormatting.ITALIC));
lines.add( GuiText.SpatialCapacity.textComponent(maxRegion, maxRegion, maxRegion));
} else {
SpatialDimensionManager.INSTANCE.addCellDimensionTooltip(dimType, lines);
}
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));
lines.add(new StringTextComponent("Dimension: " + dimType.getRegistryName()));
}
}
}
@@ -105,7 +113,7 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
final BlockPos targetSize = new BlockPos( targetX, targetY, targetZ );
ISpatialDimension manager = new SpatialDimensionManager();
ISpatialDimension manager = SpatialDimensionManager.INSTANCE;
DimensionType storedDim = this.getStoredDimension( is );
if( storedDim == null )
@@ -124,7 +132,7 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
{
World cellWorld = manager.getWorld(storedDim);
BlockPos scale = manager.getCellContentSize( storedDim );
BlockPos scale = manager.getCellDimensionSize( storedDim );
if( scale.equals( targetSize ) )
{
@@ -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() {