Skip to content

Commit

Permalink
Pushing changes for cubic chunks version. Disabled eternal fluid due …
Browse files Browse the repository at this point in the history
…to crash with CC.
  • Loading branch information
Waterpicker committed May 1, 2020
1 parent 30c7a5c commit d7d448b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 153 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ apply plugin: 'net.minecraftforge.gradle.forge'

repositories {
maven { url = "https://jitpack.io" }
mavenCentral()
maven { url = 'http://oss.sonatype.org/content/repositories/public/' }
maven {
name = 'sponge-repo'
url = 'https://repo.spongepowered.org/maven'
}
}

configurations {
Expand All @@ -32,7 +37,7 @@ dependencies {
embed 'org.jgrapht:jgrapht-core:1.1.0'
embed 'com.github.DimensionalDevelopment:poly2tri.java:master-SNAPSHOT'
compileOnly 'com.github.DimensionalDevelopment:AnnotatedNBT:-SNAPSHOT'
compileOnly 'io.github.opencubicchunks:cubicchunks:1.12.2-0.0.819.0-SNAPSHOT'
compileOnly 'io.github.opencubicchunks:cubicchunks:1.12.2-0.0-SNAPSHOT'
}

// Minecraft, MCP, Forge, and Java versions
Expand Down
135 changes: 11 additions & 124 deletions src/main/java/org/dimdev/ddutils/TeleportUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
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.WorldProviderEnd;
import net.minecraft.world.WorldServer;
import net.minecraft.world.end.DragonFightManager;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ITeleporter;
import net.minecraftforge.fml.common.FMLCommonHandler;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -134,9 +136,8 @@ public static Entity teleport(Entity entity, int newDimension, double x, double
if (entity instanceof FakePlayer) return entity;
if (entity.world.isRemote || entity.isDead) return null; // dead means inactive, not a dead player

yaw = MathHelper.wrapDegrees(yaw);
pitch = MathHelper.wrapDegrees(pitch);

float adjustedYaw = MathHelper.wrapDegrees(yaw);
float adjustedPitch = MathHelper.wrapDegrees(pitch);
entity.dismountRidingEntity(); // TODO: would be nice to teleport them too
entity.removePassengers();

Expand All @@ -147,139 +148,25 @@ public static Entity teleport(Entity entity, int newDimension, double x, double
// Workaround for https://bugs.mojang.com/browse/MC-123364. Disables player-in-block checking, but doesn't seem
// to make the player actually noclip.
entity.noClip = true;

// Prevent Minecraft from cancelling the position change being too big if the player is not in creative
// This has to be done when the teleport is done from the player moved function (so any block collision event too)
// Not doing this will cause the player to be invisible for others.
setInvulnerableDimensionChange((EntityPlayerMP) entity, true);
}

if (oldDimension == newDimension) { // Based on CommandTeleport.doTeleport
if (entity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entity;
player.connection.setPlayerLocation(x, y, z, yaw, pitch, EnumSet.noneOf(SPacketPlayerPosLook.EnumFlags.class));
player.connection.setPlayerLocation(x, y, z, adjustedYaw, adjustedPitch, EnumSet.noneOf(SPacketPlayerPosLook.EnumFlags.class));
// Fix for https://bugs.mojang.com/browse/MC-98153. See this comment: https://bugs.mojang.com/browse/MC-98153#comment-411524
captureCurrentPosition(player.connection);
} else {
entity.setLocationAndAngles(x, y, z, yaw, pitch);
entity.setLocationAndAngles(x, y, z, adjustedYaw, adjustedPitch);
}
entity.setRotationYawHead(yaw);

return entity;
} else { // Based on Entity.changeDimension
MinecraftServer server = entity.getServer();
WorldServer oldWorld = server.getWorld(oldDimension);
WorldServer newWorld = server.getWorld(newDimension);

// Allow other mods to cancel the event
if (!ForgeHooks.onTravelToDimension(entity, newDimension)) return entity;

if (entity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entity;

// Setting this field seems to be useful for advancments. Adjusted dimension checks for non-vanilla
// dimension support (entering the nether from any dimension should trigger it now).
if (newDimension == -1) {
setEnteredNetherPosition(player, new Vec3d(player.posX, player.posY, player.posZ));
} else if (oldDimension != -1 && newDimension != 0) {
setEnteredNetherPosition(player, null);
}

// Send respawn packets to the player
player.dimension = newDimension;
player.connection.sendPacket(new SPacketRespawn(player.dimension, newWorld.getDifficulty(), newWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
player.server.getPlayerList().updatePermissionLevel(player); // Sends an SPacketEntityStatus

// Remove player entity from the old world
oldWorld.removeEntityDangerously(player);

// Move the player entity to new world
// We can't use PlayerList.transferEntityToWorld since for newDimension = 1, that would first teleport the
// player to the dimension's spawn before quickly teleporting the player to the correct position. Unlike the vanilla
// code, we don't use the world provider's moveFactor (ex. 8 blocks in the nether) and don't clip to the
// world border.
player.isDead = false;
oldWorld.profiler.startSection("moving");
player.setLocationAndAngles(x, y, z, yaw, pitch);
// PlayerList.transferEntityToWorld does this for some reason when teleporting to the end, but it doesn't
// make any sense (without it, there seems to be some flickering between two positions):
if (entity.isEntityAlive()) oldWorld.updateEntityWithOptionalForce(entity, false);
oldWorld.profiler.endSection();

oldWorld.profiler.startSection("placing");
newWorld.spawnEntity(player);
newWorld.updateEntityWithOptionalForce(player, false);
oldWorld.profiler.endSection();
player.setWorld(newWorld);

// Sync the player
player.server.getPlayerList().preparePlayer(player, oldWorld);
player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
// Fix for https://bugs.mojang.com/browse/MC-98153. See this comment: https://bugs.mojang.com/browse/MC-98153#comment-411524
captureCurrentPosition(player.connection);
player.interactionManager.setWorld(newWorld);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
player.server.getPlayerList().updateTimeAndWeatherForPlayer(player, newWorld);
player.server.getPlayerList().syncPlayerInventory(player);
for (PotionEffect potioneffect : player.getActivePotionEffects()) {
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
}

// Force WorldProviderEnd to check if end dragon bars should be removed. Duplicate end dragon bars even
// happen when leaving the end using an end portal while the dragon is alive, so this might be a vanilla
// or Forge bug (maybe the world is unloaded before checking players?). In vanilla, updateplayers is normally
// called every second.
if (oldWorld.provider instanceof WorldProviderEnd) {
DragonFightManager dragonFightManager = ((WorldProviderEnd) oldWorld.provider).getDragonFightManager();
updateplayers(dragonFightManager);
}
entity.setRotationYawHead(adjustedYaw);

// Vanilla also plays SoundEvents.BLOCK_PORTAL_TRAVEL, we won't do this.

FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldDimension, newDimension);

//player.prevBlockpos = null; // For frost walk. Is this needed? What about other fields?
/*player.lastExperience = -1;
player.lastHealth = -1.0F;
player.lastFoodLevel = -1;*/

return entity;
} else {
if (entity instanceof EntityMinecartContainer) ((EntityMinecartContainer) entity).dropContentsWhenDead = false;
if (entity instanceof EntityEnderPearl) setThrower((EntityThrowable) entity, null); // Otherwise the player will be teleported to the hit position but in the same dimension

entity.world.profiler.startSection("changeDimension");
entity.dimension = newDimension;
entity.world.removeEntity(entity);
entity.isDead = false;

entity.world.profiler.startSection("reposition");
oldWorld.updateEntityWithOptionalForce(entity, false);

entity.world.profiler.endStartSection("reloading");
Entity newEntity = EntityList.newEntity(entity.getClass(), newWorld);

if (newEntity != null) {
copyDataFromOld(newEntity, entity);
newEntity.setPositionAndRotation(x, y, z, yaw, pitch);
boolean oldForceSpawn = newEntity.forceSpawn;
newEntity.forceSpawn = true;
newWorld.spawnEntity(newEntity);
newEntity.forceSpawn = oldForceSpawn;
newWorld.updateEntityWithOptionalForce(newEntity, false);
}

entity.isDead = true;
entity.world.profiler.endSection();

oldWorld.resetUpdateEntityTick();
newWorld.resetUpdateEntityTick();
entity.world.profiler.endSection();

if (newEntity instanceof EntityItem) searchForOtherItemsNearby((EntityItem) newEntity); // TODO: This isn't in same-dimension teleportation in vanilla, but why?

return newEntity;
}
return entity;
} else {
entity.changeDimension(newDimension, (w, e, newYaw) -> e.moveToBlockPosAndAngles(new BlockPos(x, y, z), adjustedYaw, adjustedPitch));
return entity;
}
}
}
56 changes: 30 additions & 26 deletions src/main/java/org/dimdev/ddutils/schem/Schematic.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.dimdev.ddutils.schem;

import cubicchunks.world.ICubicWorld;
import cubicchunks.world.cube.Cube;
import io.github.opencubicchunks.cubicchunks.api.world.ICube;
import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorld;
import io.github.opencubicchunks.cubicchunks.core.world.cube.Cube;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
Expand Down Expand Up @@ -401,34 +402,38 @@ private void setBlocks(World world, int xBase, int yBase, int zBase) {
for (int cubeZ = 0; cubeZ <= (length >> 4) + 1; cubeZ++) {
long setStart = System.nanoTime();
// Get the cube only once for efficiency
Cube cube = cubicWorld.getCubeFromCubeCoords((xBase >> 4) + cubeX, (yBase >> 4) + cubeY, (zBase >> 4) + cubeZ);
ExtendedBlockStorage storage = cube.getStorage();
boolean setAir = storage != null;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int sx = (cubeX << 4) + x - (xBase & 0x0F);
int sy = (cubeY << 4) + y - (yBase & 0x0F);
int sz = (cubeZ << 4) + z - (zBase & 0x0F);
if (sx >= 0 && sy >= 0 && sz >= 0 && sx < width && sy < height && sz < length) {
IBlockState state = palette.get(blockData[sx][sy][sz]);
if (!state.getBlock().equals(Blocks.AIR)) {
if (storage == null) {
cube.setStorage(storage = new ExtendedBlockStorage(cube.getY() << 4, world.provider.hasSkyLight()));
ICube c = cubicWorld.getCubeFromCubeCoords((xBase >> 4) + cubeX, (yBase >> 4) + cubeY, (zBase >> 4) + cubeZ);

if (c instanceof Cube) {
Cube cube = (Cube) c;
ExtendedBlockStorage storage = cube.getStorage();
boolean setAir = storage != null;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int sx = (cubeX << 4) + x - (xBase & 0x0F);
int sy = (cubeY << 4) + y - (yBase & 0x0F);
int sz = (cubeZ << 4) + z - (zBase & 0x0F);
if (sx >= 0 && sy >= 0 && sz >= 0 && sx < width && sy < height && sz < length) {
IBlockState state = palette.get(blockData[sx][sy][sz]);
if (!state.getBlock().equals(Blocks.AIR)) {
if (storage == null) {
cube.setStorage(storage = new ExtendedBlockStorage((yBase >> 4) + cube.getY() << 4, world.provider.hasSkyLight()));
}
storage.set(x, y, z, state);
} else if (setAir) {
storage.set(x, y, z, state);
}
storage.set(x, y, z, state);
} else if (setAir) {
storage.set(x, y, z, state);
}
}
}
}
setTime += System.nanoTime() - setStart;
long relightStart = System.nanoTime();
cube.setInitialLightingDone(false);
relightTime += System.nanoTime() - relightStart;
cube.markDirty();
}
setTime += System.nanoTime() - setStart;
long relightStart = System.nanoTime();
cube.setInitialLightingDone(false);
relightTime += System.nanoTime() - relightStart;
cube.markDirty();
}
}
}
Expand All @@ -454,8 +459,7 @@ private void setBlocks(World world, int xBase, int yBase, int zBase) {
IBlockState state = palette.get(blockData[sx][sy][sz]);
if (!state.getBlock().equals(Blocks.AIR)) {
if (storage == null) {
storage = new ExtendedBlockStorage((yBase >> 4) + storageY << 4, world.provider.hasSkyLight());
storageArray[(yBase >> 4) + storageY] = storage;
storageArray[(yBase >> 4) + storageY] = storage = new ExtendedBlockStorage((yBase >> 4) + storageY << 4, world.provider.hasSkyLight());
}
storage.set(x, y, z, state);
} else if (setAir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public BlockFabricEternal() {
setSoundType(SoundType.STONE);
}

@Override
//This is meant to be a fix for a cubic chunks version. Currently crashes for some reason and don't want to try and fix right now.
/*@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
if (world.isRemote) return;
exitLimbo.receiveEntity(entity, entity.rotationYaw / 90 * 90, 0);
}
}*/
}

0 comments on commit d7d448b

Please sign in to comment.