Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 12 additions & 18 deletions src/main/java/com/cardinalstar/cubicchunks/CubicChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
package com.cardinalstar.cubicchunks;

import static com.cardinalstar.cubicchunks.util.ReflectionUtil.cast;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
Expand All @@ -30,6 +28,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.ISaveHandler;
Expand All @@ -45,9 +44,8 @@
import com.cardinalstar.cubicchunks.async.TaskPool;
import com.cardinalstar.cubicchunks.event.handlers.ClientEventHandler;
import com.cardinalstar.cubicchunks.event.handlers.CommonEventHandler;
import com.cardinalstar.cubicchunks.mixin.api.ICubicWorldSettings;
import com.cardinalstar.cubicchunks.mixin.early.common.IIntegratedServer;
import com.cardinalstar.cubicchunks.network.NetworkChannel;
import com.cardinalstar.cubicchunks.server.ICubicChunksServer;
import com.cardinalstar.cubicchunks.server.chunkio.RegionCubeStorage;
import com.cardinalstar.cubicchunks.util.CompatHandler;
import com.cardinalstar.cubicchunks.util.Mods;
Expand All @@ -66,7 +64,6 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.internal.NetworkModHolder;
Expand Down Expand Up @@ -163,6 +160,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 +190,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 +209,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
626 changes: 121 additions & 505 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
@@ -1,6 +1,5 @@
package com.cardinalstar.cubicchunks.api.worldgen.decoration;

import com.cardinalstar.cubicchunks.api.worldgen.impl.StandardWorldDecorator;
import net.minecraft.world.World;

import com.cardinalstar.cubicchunks.util.CubePos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@
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;

import com.cardinalstar.cubicchunks.mixin.api.ICubicWorldInternal;
import com.cardinalstar.cubicchunks.server.ICubicChunksServer;
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 +48,14 @@ 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 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;

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;

@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(
"cubicchunks.build.too.low",
((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 @@ -123,7 +123,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 @@ -562,7 +561,6 @@ public EagerCubeLoadRequest loadCubeEagerly(int x, int y, int z, Requirement eff
@Override
public Cube getCube(int cubeX, int cubeY, int cubeZ, Requirement effort) {
Cube cube = cubeLoader.getCube(cubeX, cubeY, cubeZ, effort);

return cube == null ? emptyCube : cube;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,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,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.WorldServer;
Expand All @@ -29,9 +31,12 @@
import com.cardinalstar.cubicchunks.util.Array3D;
import com.cardinalstar.cubicchunks.util.CubePos;
import com.cardinalstar.cubicchunks.util.XZAddressable;
import com.cardinalstar.cubicchunks.world.CubicChunksSavedData;
import com.cardinalstar.cubicchunks.world.api.ICubeProviderServer.Requirement;
import com.cardinalstar.cubicchunks.world.column.EmptyColumn;
import com.cardinalstar.cubicchunks.world.core.IColumnInternal;
import com.cardinalstar.cubicchunks.world.cube.BlankCube;
import com.cardinalstar.cubicchunks.world.cube.BoundaryCube;
import com.cardinalstar.cubicchunks.world.cube.Cube;

import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
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,11 @@ 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 +661,25 @@ 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