Port most of the world patches (#5294)

This commit is contained in:
tterrag authored and LexManos committed 2018-12-22 10:31:18 -08:00
1 parent 4879b0611a
commit 8a11e3bac4
34 files changed
+1203 -855

No files matched your search

@@ -28,11 +28,11 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.NetherDimension;
import net.minecraft.world.dimension.OverworldDimension;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -44,6 +44,8 @@ public interface IForgeDimension
{
return (Dimension) this;
}
World getWorld();
/**
* Called from {@link World#initCapabilities()}, to gather capabilities for this
@@ -79,6 +81,22 @@ public interface IForgeDimension
}
return 1.0;
}
/**
* If this method returns true, then chunks received by the client will
* have {@link net.minecraft.world.chunk.Chunk#resetRelightChecks} called
* on them, queuing lighting checks for all air blocks in the chunk (and
* any adjacent light-emitting blocks).
*
* Returning true here is recommended if the chunk generator used also
* does this for newly generated chunks.
*
* @return true if lighting checks should be performed
*/
default boolean shouldClientCheckLighting()
{
return !(this instanceof OverworldDimension);
}
/**
* Sets the providers current dimension ID, used in default getSaveFolder()
@@ -149,15 +167,34 @@ public interface IForgeDimension
{
return null;
}
/**
* Determines if the player can sleep in this world (or if the bed should explode for example).
*
* @param player The player that is attempting to sleep
* @param pos The location where the player tries to sleep at (the position of the clicked on bed for example)
* @return the result of a player trying to sleep at the given location
*/
default SleepResult canSleepAt(net.minecraft.entity.player.EntityPlayer player, BlockPos pos)
{
return (getDimension().canRespawnHere() && getWorld().getBiome(pos) != net.minecraft.init.Biomes.NETHER) ? SleepResult.ALLOW : SleepResult.BED_EXPLODES;
}
enum SleepResult
{
ALLOW,
DENY,
BED_EXPLODES;
}
default Biome getBiome(BlockPos pos)
{
return getDimension().getWorld().getBiomeBody(pos);
return getWorld().getBiomeBody(pos);
}
default boolean isDaytime()
{
return getDimension().getWorld().getSkylightSubtracted() < 4;
return getWorld().getSkylightSubtracted() < 4;
}
/**
@@ -170,7 +207,7 @@ public interface IForgeDimension
**/
default float getSunBrightnessFactor(float partialTicks)
{
return getDimension().getWorld().getSunBrightnessFactor(partialTicks);
return getWorld().getSunBrightnessFactor(partialTicks);
}
/**
@@ -179,19 +216,19 @@ public interface IForgeDimension
@OnlyIn(Dist.CLIENT)
default float getSunBrightness(float partialTicks)
{
return getDimension().getWorld().getSunBrightnessBody(partialTicks);
return getWorld().getSunBrightnessBody(partialTicks);
}
@OnlyIn(Dist.CLIENT)
default Vec3d getSkyColor(Entity cameraEntity, float partialTicks)
{
return getDimension().getWorld().getSkyColorBody(cameraEntity, partialTicks);
return getWorld().getSkyColorBody(cameraEntity, partialTicks);
}
@OnlyIn(Dist.CLIENT)
default Vec3d getCloudColor(float partialTicks)
{
return getDimension().getWorld().getCloudColorBody(partialTicks);
return getWorld().getCloudColorBody(partialTicks);
}
/**
@@ -210,7 +247,7 @@ public interface IForgeDimension
@OnlyIn(Dist.CLIENT)
default float getStarBrightness(float partialTicks)
{
float f = getDimension().getWorld().getCelestialAngle(partialTicks);
float f = getWorld().getCelestialAngle(partialTicks);
float f1 = 1.0F - (MathHelper.cos(f * ((float)Math.PI * 2F)) * 2.0F + 0.25F);
f1 = MathHelper.clamp(f1, 0.0F, 1.0F);
return f1 * f1 * 0.5F;
@@ -220,48 +257,48 @@ public interface IForgeDimension
default void calculateInitialWeather()
{
getDimension().getWorld().calculateInitialWeatherBody();
getWorld().calculateInitialWeatherBody();
}
default void updateWeather()
{
getDimension().getWorld().updateWeatherBody();
getWorld().updateWeatherBody();
}
default long getSeed()
{
return getDimension().getWorld().getWorldInfo().getSeed();
return getWorld().getWorldInfo().getSeed();
}
default long getWorldTime()
{
return getDimension().getWorld().getWorldInfo().getDayTime();
return getWorld().getWorldInfo().getDayTime();
}
default void setWorldTime(long time)
{
getDimension().getWorld().getWorldInfo().setDayTime(time);
getWorld().getWorldInfo().setDayTime(time);
}
default BlockPos getSpawnPoint()
{
WorldInfo info = getDimension().getWorld().getWorldInfo();
WorldInfo info = getWorld().getWorldInfo();
return new BlockPos(info.getSpawnX(), info.getSpawnY(), info.getSpawnZ());
}
default void setSpawnPoint(BlockPos pos)
{
getDimension().getWorld().getWorldInfo().setSpawn(pos);
getWorld().getWorldInfo().setSpawn(pos);
}
default boolean canMineBlock(EntityPlayer player, BlockPos pos)
{
return getDimension().getWorld().canMineBlockBody(player, pos);
return getWorld().canMineBlockBody(player, pos);
}
default boolean isHighHumidity(BlockPos pos)
{
return getDimension().getWorld().getBiome(pos).isHighHumidity();
return getWorld().getBiome(pos).isHighHumidity();
}
default int getHeight()
@@ -276,7 +313,7 @@ public interface IForgeDimension
default double getHorizon()
{
return getDimension().getWorld().getWorldInfo().getTerrainType().getHorizon(getDimension().getWorld());
return getWorld().getWorldInfo().getTerrainType().getHorizon(getWorld());
}
default String getSaveFolder()
@@ -297,4 +334,15 @@ public interface IForgeDimension
{
return getId() < 0;
}
/**
* Determines the dimension the player will be respawned in, typically this brings them back to the overworld.
*
* @param player The player that is respawning
* @return The dimension to respawn the player in
*/
default int getRespawnDimension(net.minecraft.entity.player.EntityPlayerMP player)
{
return player.getSpawnDimension();
}
}
@@ -0,0 +1,104 @@
package net.minecraftforge.common.extensions;
import java.util.function.LongFunction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiCreateBuffetWorld;
import net.minecraft.client.gui.GuiCreateFlatWorld;
import net.minecraft.client.gui.GuiCreateWorld;
import net.minecraft.world.World;
import net.minecraft.world.WorldType;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.IContextExtended;
import net.minecraft.world.gen.OverworldGenSettings;
import net.minecraft.world.gen.area.IArea;
import net.minecraft.world.gen.area.IAreaFactory;
import net.minecraft.world.gen.layer.GenLayerBiome;
import net.minecraft.world.gen.layer.GenLayerBiomeEdge;
import net.minecraft.world.gen.layer.GenLayerZoom;
import net.minecraft.world.gen.layer.LayerUtil;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public interface IForgeWorldType
{
default WorldType getWorldType()
{
return (WorldType) this;
}
/**
* Called when 'Create New World' button is pressed before starting game
*/
default void onGUICreateWorldPress()
{
}
/**
* Called when the 'Customize' button is pressed on world creation GUI
*
* @param mc The Minecraft instance
* @param gui the createworld GUI
*/
@OnlyIn(Dist.CLIENT)
default void onCustomizeButton(Minecraft mc, GuiCreateWorld gui)
{
if (this == WorldType.FLAT)
mc.displayGuiScreen(new GuiCreateFlatWorld(gui, gui.chunkProviderSettingsJson));
else if (this == WorldType.CUSTOMIZED)
mc.displayGuiScreen(new GuiCreateBuffetWorld(gui, gui.chunkProviderSettingsJson));
}
default boolean handleSlimeSpawnReduction(java.util.Random random, World world)
{
return this == WorldType.FLAT ? random.nextInt(4) != 1 : false;
}
default double getHorizon(World world)
{
return this == WorldType.FLAT ? 0.0D : 63.0D;
}
default double voidFadeMagnitude()
{
return this == WorldType.FLAT ? 1.0D : 0.03125D;
}
/**
* Get the height to render the clouds for this world type
*
* @return The height to render clouds at
*/
default float getCloudHeight()
{
return 128.0F;
}
@SuppressWarnings("deprecation")
default IChunkGenerator<?> createChunkGenerator(World world)
{
return world.dimension.createChunkGenerator();
}
/**
* Creates the GenLayerBiome used for generating the world with the specified
* ChunkProviderSettings JSON String *IF AND ONLY IF* this WorldType ==
* WorldType.CUSTOMIZED.
*
*
* @param worldSeed The world seed
* @param parentLayer The parent layer to feed into any layer you return
* @param chunkSettings The ChunkGeneratorSettings constructed from the custom
* JSON
* @return A GenLayer that will return ints representing the Biomes to be
* generated, see GenLayerBiome
*/
default <T extends IArea, C extends IContextExtended<T>> IAreaFactory<T> getBiomeLayer(IAreaFactory<T> parentLayer,
OverworldGenSettings chunkSettings, LongFunction<C> contextFactory)
{
parentLayer = (new GenLayerBiome(getWorldType(), chunkSettings)).apply((IContextExtended) contextFactory.apply(200L), parentLayer);
parentLayer = LayerUtil.repeat(1000L, GenLayerZoom.NORMAL, parentLayer, 2, contextFactory);
parentLayer = GenLayerBiomeEdge.INSTANCE.apply((IContextExtended) contextFactory.apply(1000L), parentLayer);
return parentLayer;
}
}