Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ dependencies {

// ========================= Compat Deps ========================= //

compileOnly("com.falsepattern:chunkapi-mc1.7.10:0.8.0:dev")
compileOnly("com.falsepattern:endlessids-mc1.7.10:1.7.0:dev")
compileOnly("com.falsepattern:chunkapi-mc1.7.10:0.8.1:dev")
compileOnly("com.falsepattern:endlessids-mc1.7.10:1.7.1:dev")
compileOnly("ganymedes01.etfuturum:Et-Futurum-Requiem:2.6.2.21-GTNH-daily:dev")

// ========================= Test Deps ========================= //
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/cardinalstar/cubicchunks/CubicChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import com.cardinalstar.cubicchunks.server.ICubicChunksServer;
import com.cardinalstar.cubicchunks.world.CubicChunksSavedData;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.ISaveHandler;
Expand Down Expand Up @@ -163,6 +166,12 @@ public String call() throws Exception {

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
try {
CubicChunksConfig.init();
} catch (ConfigException ex) {
throw new RuntimeException(ex);
}

CommonEventHandler eventHandler = new CommonEventHandler();
MinecraftForge.EVENT_BUS.register(eventHandler);
FMLCommonHandler.instance()
Expand All @@ -187,18 +196,12 @@ public void postInit(FMLPostInitializationEvent event) {
}
}

@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent evt) {
CubicChunksConfig.registerCommands(evt);
}

@Mod.EventHandler
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
SideUtils.runForSide(() -> () -> {
IIntegratedServer integratedServer = cast(event.getServer());
ICubicWorldSettings settings = cast(integratedServer.getWorldSettings());
event.getServer()
.setBuildLimit(CubicChunks.MAX_SUPPORTED_BLOCK_Y);
MinecraftServer server = event.getServer();
server.setBuildLimit(CubicChunks.MAX_SUPPORTED_BLOCK_Y);
((ICubicChunksServer) server).setBuildMinimum(CubicChunks.MIN_SUPPORTED_BLOCK_Y);
}, () -> () -> {
// no-op, done by mixin
});
Expand All @@ -212,10 +215,7 @@ public static void registerAnvil3dStorageFormatProvider() {
public static boolean checkCanConnectWithMods(Map<String, String> modVersions, Side remoteSide) {
String remoteFullVersion = modVersions.get(MODID);
if (remoteFullVersion == null) {
if (remoteSide.isClient()) {
return CubicChunksConfig.allowVanillaClients; // don't allow client without CC to connect
}
return true; // allow connecting to server without CC
return !remoteSide.isClient(); // don't allow client without CC to connect
}
if (!checkVersionFormat(MOD_VERSION, remoteSide.isClient() ? Side.SERVER : Side.CLIENT)) {
return true;
Expand Down
596 changes: 124 additions & 472 deletions src/main/java/com/cardinalstar/cubicchunks/CubicChunksConfig.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
*/
package com.cardinalstar.cubicchunks.mixin.early.common;

import com.cardinalstar.cubicchunks.server.ICubicChunksServer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -33,7 +35,11 @@
import com.cardinalstar.cubicchunks.server.SpawnCubes;

@Mixin(MinecraftServer.class)
public class MixinMinecraftServer {
public class MixinMinecraftServer implements ICubicChunksServer
{
@Unique
private int cubicChunks$buildMinimum;


@Inject(method = "initialWorldChunkLoad", at = @At("HEAD"), cancellable = true)
private void onInitialSpawnLoad(CallbackInfo ci) {
Expand All @@ -43,4 +49,16 @@ private void onInitialSpawnLoad(CallbackInfo ci) {
.update(world);
ci.cancel();
}

@Override
public void setBuildMinimum(int minBuildHeight)
{
cubicChunks$buildMinimum = minBuildHeight;
}

@Override
public int getBuildMinimum()
{
return cubicChunks$buildMinimum;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,71 @@
package com.cardinalstar.cubicchunks.mixin.early.common;

import com.cardinalstar.cubicchunks.world.api.IMinMaxHeight;
import com.llamalad7.mixinextras.expression.Definition;
import com.llamalad7.mixinextras.expression.Expression;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.server.S02PacketChat;
import net.minecraft.server.MinecraftServer;

import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(NetHandlerPlayServer.class)
public class MixinNetHandlerPlayServer {

@Shadow
public EntityPlayerMP playerEntity;

@Redirect(
method = "processPlayerBlockPlacement",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/management/ItemInWorldManager;activateBlockOrUseItem(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;IIIIFFF)Z"
)
)
private boolean preventLowPlacement(ItemInWorldManager manager, EntityPlayer player, World world,
ItemStack stack, int x, int y, int z,
int side, float hitX, float hitY, float hitZ,
@Local(type = WorldServer.class) WorldServer server)
{
if (y < ((IMinMaxHeight)server).getMinHeight() + 1 && (side == 0 || y < ((IMinMaxHeight)server).getMinHeight())) {
ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooLow", ((IMinMaxHeight) server).getMinHeight());
chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation));
return false;
}

return !manager.activateBlockOrUseItem(player, world, stack, x, y, z, side, hitX, hitY, hitZ);
}

@Redirect(
method = "processPlayerBlockPlacement",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getBuildLimit()I"))
public int noopHeightChecks(MinecraftServer instance) {
return Integer.MAX_VALUE;
public int noopHeightChecks(MinecraftServer instance, @Local(type = WorldServer.class) WorldServer server)
{
return ((IMinMaxHeight)server).getMaxHeight();
}

@Definition(id = "serverController", field = "Lnet/minecraft/network/NetHandlerPlayServer;serverController:Lnet/minecraft/server/MinecraftServer;")
@Definition(id = "getBuildLimit", method = "Lnet/minecraft/server/MinecraftServer;getBuildLimit()I")
@Expression("? >= this.serverController.getBuildLimit()")
@ModifyExpressionValue(
method = "processPlayerDigging",
at = @At("MIXINEXTRAS:EXPRESSION")
)
public boolean setDimensionalBounds(boolean original, @Local(type = WorldServer.class) WorldServer server, @Local(type = int.class, name = "j") int j)
{
return j >= ((IMinMaxHeight) server).getMaxHeight() || j < ((IMinMaxHeight) server).getMinHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public void process(World world, PacketCubes packet) {

for (CubePos pos : packet.cubePos) {
Cube cube = cubeCache.loadCube(pos); // new cube
// isEmpty actually checks if the column is a BlankColumn
if (cube == null) {
CubicChunks.LOGGER.error("Out of order cube received! No column for cube at {} exists!", pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import com.cardinalstar.cubicchunks.world.CubicChunksSavedData;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.profiler.Profiler;
Expand Down Expand Up @@ -123,7 +124,6 @@ public CubeProviderServer(WorldServer worldServer, IChunkLoader chunkLoader, IWo
worldServer.provider.createChunkGenerator()); // let's create the chunk generator, for now the vanilla one
// may be enough

// this.cubePrimer = new CubePrimer();
this.worldGenerator = worldGenerator;
this.worldServer = worldServer;
this.profiler = worldServer.theProfiler;
Expand Down Expand Up @@ -363,8 +363,7 @@ private void doEagerLoading() {

cubeLoader.pauseLoadCalls();

Cube cube = cubeLoader
.getCube(request.pos.getX(), request.pos.getY(), request.pos.getZ(), request.effort);
Cube cube = cubeLoader.getCube(request.pos.getX(), request.pos.getY(), request.pos.getZ(), request.effort);

cubeLoader.unpauseLoadCalls();

Expand Down Expand Up @@ -536,7 +535,8 @@ public int getZ() {
}
}

public EagerCubeLoadRequest loadCubeEagerly(int x, int y, int z, Requirement effort) {
public EagerCubeLoadRequest loadCubeEagerly(int x, int y, int z, Requirement effort)
{
CubePos pos = new CubePos(x, y, z);

ChunkCoordIntPair coord = new ChunkCoordIntPair(x, z);
Expand All @@ -560,20 +560,22 @@ public EagerCubeLoadRequest loadCubeEagerly(int x, int y, int z, Requirement eff

@Nullable
@Override
public Cube getCube(int cubeX, int cubeY, int cubeZ, Requirement effort) {
public Cube getCube(int cubeX, int cubeY, int cubeZ, Requirement effort)
{
Cube cube = cubeLoader.getCube(cubeX, cubeY, cubeZ, effort);

return cube == null ? emptyCube : cube;
}

@Override
public boolean cubeExists(int cubeX, int cubeY, int cubeZ) {
public boolean cubeExists(int cubeX, int cubeY, int cubeZ)
{
return cubeLoader.cubeExists(cubeX, cubeY, cubeZ);
}

@Nullable
@Override
public Chunk getColumn(int columnX, int columnZ, Requirement effort) {
public Chunk getColumn(int columnX, int columnZ, Requirement effort)
{
return cubeLoader.getColumn(columnX, columnZ, effort);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import javax.annotation.ParametersAreNonnullByDefault;

import com.cardinalstar.cubicchunks.world.CubicChunksSavedData;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.Packet;
import net.minecraft.server.management.PlayerManager;
Expand Down Expand Up @@ -126,8 +127,8 @@ public CubicPlayerManager(WorldServer worldServer) {
((ICubicPlayerList) worldServer.func_73046_m()
.getConfigurationManager()).getVerticalViewDistance());

provider = ((Server) worldServer).getCubeCache();
provider.registerCallback(this);
this.provider = ((Server) worldServer).getCubeCache();
this.provider.registerCallback(this);
}

public Collection<Chunk> getColumns() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cardinalstar.cubicchunks.server;

public interface ICubicChunksServer
{
void setBuildMinimum(int minBuildHeight);

int getBuildMinimum();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.util.ArrayList;
import java.util.List;

import com.cardinalstar.cubicchunks.world.CubicChunksSavedData;
import com.cardinalstar.cubicchunks.world.column.EmptyColumn;
import com.cardinalstar.cubicchunks.world.cube.BoundaryCube;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.WorldServer;
Expand Down Expand Up @@ -37,6 +40,8 @@
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.Setter;

import javax.annotation.Nonnull;

public class CubeLoaderServer implements ICubeLoader {

private static final MetaKey<CubeInfo> CUBE_INFO = new MetaKey<>() {};
Expand All @@ -57,12 +62,28 @@ public class CubeLoaderServer implements ICubeLoader {
@Setter
private long now;

private final int maxCube;
private final int minCube;

@Nonnull
private final EmptyColumn emptyColumn;
@Nonnull
private final BlankCube emptyCube;

public CubeLoaderServer(WorldServer world, ICubicStorage storage, IWorldGenerator generator,
CubeLoaderCallback callback) {
this.world = world;
this.cubeIO = new CubeIO(storage, generator instanceof IPreloadFailureDelegate delegate ? delegate : null);
this.generator = generator;
this.callback = callback;

CubicChunksSavedData data =CubicChunksSavedData.get(world);

this.minCube = data.minHeight >> 4;
this.maxCube = (data.maxHeight - 1) >> 4;

this.emptyColumn = new EmptyColumn(world, 0, 0);
this.emptyCube = new BlankCube(emptyColumn);
}

@Override
Expand Down Expand Up @@ -458,7 +479,8 @@ private enum ObjectSource {
None,
Disk,
Generated,
GeneratedSideEffect
GeneratedSideEffect,
Boundary
}

private class ColumnInfo implements XZAddressable {
Expand Down Expand Up @@ -606,6 +628,12 @@ public int getZ() {
}

public boolean initialize(Requirement effort) throws IOException {
if (pos.getY() < minCube || pos.getY() > maxCube)
{
loadBoundaryCube();
return true;
}

if (effort == Requirement.GET_CACHED) {
return cube != null;
}
Expand Down Expand Up @@ -634,6 +662,26 @@ public boolean initialize(Requirement effort) throws IOException {
return generate(requestedInitLevel);
}

private void loadBoundaryCube()
{
ensureColumn(Requirement.LOAD);

if (this.column == null) {
CubicChunks.LOGGER.error(
"Tried to load a cube that did not have a saved column: it will be regenerated ({},{},{})",
getX(),
getY(),
getZ(),
new Exception());
this.cube = null;
this.tag = null;
return;
}

this.cube = new BoundaryCube(this.column.column, this.getY());
onCubeLoaded();
}

private boolean loadNBT() {
if (tag != null) return true;

Expand Down
Loading
Loading