Big fixes

- Disable void fog in pockets and change yBase back to 0
 - Remove depth info from pockets, we already have it in VirtualLocation
 - Fix texture name
 - Fix bug cloud/sky renderer crash
This commit is contained in:
Runemoro 2017-12-19 15:30:06 -05:00
parent 0ed714ed80
commit 02f22ddf76
15 changed files with 156 additions and 102 deletions

View file

@ -12,6 +12,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.WorldProvider;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;

View file

@ -8,7 +8,9 @@ import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;
import com.zixiken.dimdoors.shared.tileentities.TileEntityHorizontalEntranceRift;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@ -54,4 +56,14 @@ public class DDProxyClient extends DDProxyCommon {
public WorldServer getWorldServer(int dimId) {
return Minecraft.getMinecraft().getIntegratedServer().getWorld(dimId);
}
@Override
public void setCloudRenderer(WorldProvider provider, IRenderHandler renderer) {
provider.setCloudRenderer(renderer);
}
@Override
public void setSkyRenderer(WorldProvider provider, IRenderHandler renderer) {
provider.setSkyRenderer(renderer);
}
}

View file

@ -7,7 +7,9 @@ package com.zixiken.dimdoors.server;
import com.zixiken.dimdoors.shared.DDProxyCommon;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.common.DimensionManager;
/**
@ -30,4 +32,10 @@ public class DDProxyServer extends DDProxyCommon {
public WorldServer getWorldServer(int dimId) {
return DimensionManager.getWorld(dimId);
}
@Override
public void setCloudRenderer(WorldProvider provider, IRenderHandler renderer) {}
@Override
public void setSkyRenderer(WorldProvider provider, IRenderHandler renderer) {}
}

View file

@ -10,7 +10,9 @@ import com.zixiken.dimdoors.shared.util.DefaultSchematicGenerator;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import com.zixiken.dimdoors.shared.world.ModBiomes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@ -44,4 +46,9 @@ public abstract class DDProxyCommon implements IDDProxy {
SchematicHandler.INSTANCE.loadSchematics();
DefaultSchematicGenerator.generateDefaultSchematics();
}
abstract public void setCloudRenderer(WorldProvider provider, IRenderHandler renderer);
abstract public void setSkyRenderer(WorldProvider provider, IRenderHandler renderer);
}

View file

@ -47,6 +47,13 @@ public class CommandDimTeleport extends CommandBase { // TODO: localization
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
// Check correct number of arguments
if (args.length < 4 || args.length > 6) {
sender.sendMessage(new TextComponentString("[DimDoors] Usage: /" + getUsage(sender)));
return;
}
// Parse arguments
int dimension, x, y, z;
int yaw = 0; // TODO: keep old yaw and pitch?
int pitch = 0;
@ -57,11 +64,12 @@ public class CommandDimTeleport extends CommandBase { // TODO: localization
z = Integer.parseInt(args[3]);
if (args.length >= 5) yaw = Integer.parseInt(args[4]);
if (args.length >= 6) pitch = Integer.parseInt(args[5]);
} catch (ArrayIndexOutOfBoundsException|NumberFormatException e) {
sender.sendMessage(new TextComponentString("[DimDoors] Incorrect usage."));
} catch (NumberFormatException e) {
sender.sendMessage(new TextComponentString("[DimDoors] Usage: /" + getUsage(sender)));
return;
}
// Teleport if it's a player
if (sender instanceof Entity) {
TeleportUtils.teleport((Entity) sender, new Location(dimension, new BlockPos(x, y, z)), yaw, pitch);
} else {
@ -72,7 +80,7 @@ public class CommandDimTeleport extends CommandBase { // TODO: localization
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
List<String> list = new ArrayList<>();
if (args.length < 2) { //counts an empty ("") argument as an argument as well...
if (args.length == 1) {
list = StringUtils.getAsStringList(DimensionManager.getIDs());
list = StringUtils.getMatchingStrings(args[0], list, false);
}

View file

@ -4,7 +4,9 @@ import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.*;
import com.zixiken.dimdoors.shared.pockets.*;
import com.zixiken.dimdoors.shared.rifts.TileEntityRift;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.util.StringUtils;
import com.zixiken.dimdoors.shared.util.TeleportUtils;
import com.zixiken.dimdoors.shared.util.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.command.CommandBase;
@ -13,6 +15,7 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import javax.annotation.Nullable;
import java.util.ArrayList;
@ -34,7 +37,7 @@ public class PocketCommand extends CommandBase {
@Override
public String getUsage(ICommandSender sender) {
return "dimpocket <group> <name>";
return "dimpocket <group> <name> [setup]";
}
@Override
@ -44,20 +47,56 @@ public class PocketCommand extends CommandBase {
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { // TODO: option to replace current pocket
// Check correct number of arguments
if (args.length > 2 || args.length > 3) {
sender.sendMessage(new TextComponentString("[DimDoors] Usage: /" + getUsage(sender)));
return;
}
String group = args[0];
String name = args[1];
boolean setup = true;
if (args.length >= 3) {
switch (args[2]) {
case "true":
setup = true;
break;
case "false":
setup = false;
break;
default:
sender.sendMessage(new TextComponentString("[DimDoors] Usage: /" + getUsage(sender)));
return;
}
}
// Execute only if it's a player
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
if (areArgumentsValid(args, player)) {
int dim = WorldUtils.getDim(player.world);
if (DimDoorDimensions.isPocketDimension(dim)) {
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(args[0], args[1]);
Pocket pocket = PocketGenerator.generatePocketFromTemplate(dim, 0, template, new VirtualLocation(0, 0, 0, 0,0));
// TODO: options for linking back/not setting entrance
pocket.setup();
TileEntityRift entrance = (TileEntityRift) player.world.getTileEntity(pocket.getEntrance().getPos()); // TODO: what about no entrances?
entrance.teleportTo(player);
} else {
DimDoors.chat(player, "You must be in a pocket dimension to use this command!");
}
// Make sure the player is in a pocket world
if (!DimDoorDimensions.isPocketDimension(WorldUtils.getDim(player.world))) {
DimDoors.chat(player, "You must be in a pocket dimension to use this command!");
return;
}
// Check if the schematic exists
if (!SchematicHandler.INSTANCE.getTemplateGroups().contains(name)) {
DimDoors.chat(player, "Group " + group + " not found");
return;
} else if (!SchematicHandler.INSTANCE.getTemplateNames(name).contains(group)) {
DimDoors.chat(player, "Schematic " + name + " not found in group " + group);
return;
}
// Generate the schematic and teleport the player to it
DimDoors.chat(player, "Generating schematic " + args[1]);
PocketTemplate template = SchematicHandler.INSTANCE.getTemplate(args[0], args[1]);
Pocket pocket = PocketGenerator.generatePocketFromTemplate(WorldUtils.getDim(player.world), template, new VirtualLocation(0, 0, 0, 0,0));
if (setup) pocket.setup();
if (pocket.getEntrance() != null) {
TileEntityRift entrance = (TileEntityRift) player.world.getTileEntity(pocket.getEntrance().getPos());
entrance.teleportTo(player);
} else {
TeleportUtils.teleport(player, new Location(player.world, pocket.getX(), 0, pocket.getZ()), 0, 0);
}
} else {
DimDoors.log.info("Not executing command /" + getName() + " because it wasn't sent by a player.");
@ -67,34 +106,18 @@ public class PocketCommand extends CommandBase {
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
List<String> list = new ArrayList<>();
if (args.length < 2) { //counts an empty ("") argument as an argument as well...
list = SchematicHandler.INSTANCE.getTemplateGroups();
list = StringUtils.getMatchingStrings(args[0], list, false);
} else if (args.length == 2) {
list = SchematicHandler.INSTANCE.getTemplateNames(args[0]);
list = StringUtils.getMatchingStrings(args[1], list, false);
}
return list;
}
private boolean areArgumentsValid(String[] args, EntityPlayerMP player) {
if (args.length < 2) {
DimDoors.chat(player, "Too few arguments.");
return false;
} else if (args.length > 2) {
DimDoors.chat(player, "Too many arguments.");
return false;
} else { //exactly 2 arguments
if (!SchematicHandler.INSTANCE.getTemplateGroups().contains(args[0])) {
DimDoors.chat(player, "Group not found.");
return false;
} else if (!SchematicHandler.INSTANCE.getTemplateNames(args[0]).contains(args[1])) {
DimDoors.chat(player, "Schematic not found.");
return false;
} else {
DimDoors.chat(player, "Generating schematic " + args[1]);
return true;
}
switch (args.length) {
case 1:
list = SchematicHandler.INSTANCE.getTemplateGroups();
break;
case 2:
list = SchematicHandler.INSTANCE.getTemplateNames(args[0]);
break;
case 3:
list.add("true");
list.add("false");
break;
}
return StringUtils.getMatchingStrings(args[0], list, false);
}
}

View file

@ -34,7 +34,7 @@ public class Pocket { // TODO: better visibilities
private Pocket() {}
Pocket(int id, int dimID, int x, int z, int depth) {
Pocket(int id, int dimID, int x, int z) {
this.id = id;
this.dimID = dimID;
this.x = x;

View file

@ -8,39 +8,39 @@ import java.util.Random;
public class PocketGenerator {
public static Pocket generatePocketFromTemplate(int dimID, int depth, PocketTemplate pocketTemplate, VirtualLocation virtualLocation) {
DimDoors.log.info("depth = " + depth + " originalDim = " + virtualLocation);
public static Pocket generatePocketFromTemplate(int dimID, PocketTemplate pocketTemplate, VirtualLocation virtualLocation) {
DimDoors.log.info("Generating pocket from template " + pocketTemplate.getName() + " at virtual location " + virtualLocation);
PocketRegistry registry = PocketRegistry.getForDim(dimID);
Pocket pocket = registry.newPocket(depth);
pocketTemplate.place(pocket, 10); // Sky starts getting dark (because of void) below y = 10 TODO: config option for yBase or maybe param?
Pocket pocket = registry.newPocket();
pocketTemplate.place(pocket, 0); // TODO: config option for yBase
pocket.setVirtualLocation(virtualLocation);
return pocket;
}
public static Pocket generatePrivatePocket(VirtualLocation virtualLocation) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPersonalPocketTemplate();
return generatePocketFromTemplate(DimDoorDimensions.getPrivateDimID(), 0, pocketTemplate, virtualLocation);
return generatePocketFromTemplate(DimDoorDimensions.getPrivateDimID(), pocketTemplate, virtualLocation);
}
public static Pocket generatePublicPocket(VirtualLocation virtualLocation) {
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getPublicPocketTemplate();
return generatePocketFromTemplate(DimDoorDimensions.getPublicDimID(), 0, pocketTemplate, virtualLocation);
return generatePocketFromTemplate(DimDoorDimensions.getPublicDimID(), pocketTemplate, virtualLocation);
}
/**
* Create a dungeon pocket at a certain depth.
*
* @param depth The depth of the dungeon
* @param virtualLocation The virtual location of the pocket
* @return The newly-generated dungeon pocket
*/
public Pocket generateDungeonPocket(int depth, VirtualLocation virtualLocation) { // TODO: Add rift for linking!
public Pocket generateDungeonPocket(VirtualLocation virtualLocation) {
int depth = virtualLocation.getDepth();
float netherProbability = virtualLocation.getDimID() == -1 ? 1 : (float) depth / 50; // TODO: improve nether probability
Random random = new Random();
String group = random.nextFloat() < netherProbability ? "nether" : "ruins";
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, DDConfig.getMaxPocketSize(), false);
return generatePocketFromTemplate(DimDoorDimensions.getDungeonDimID(), depth, pocketTemplate, virtualLocation);
return generatePocketFromTemplate(DimDoorDimensions.getDungeonDimID(), pocketTemplate, virtualLocation);
}
}

View file

@ -144,9 +144,9 @@ public class PocketRegistry extends WorldSavedData {
*
* @return The newly created Pocket
*/
public Pocket newPocket(int depth) {
public Pocket newPocket() {
Pocket pocket = null;
while(pocket == null) pocket = newPocket(nextID++, depth); // TODO: config option to reuse IDs (start at 0 rather than nextFreePocket)
while(pocket == null) pocket = newPocket(nextID++); // TODO: config option to reuse IDs (start at 0 rather than nextFreePocket)
return pocket;
}
@ -156,10 +156,10 @@ public class PocketRegistry extends WorldSavedData {
*
* @return The newly created Pocket, or null if that ID is taken already.
*/
public Pocket newPocket(int id, int depth) {
public Pocket newPocket(int id) {
if (pockets.get(id) != null) return null;
GridUtils.GridPos pos = getGridPosFromID(id);
Pocket pocket = new Pocket(id, dimID, pos.getX(), pos.getZ(), depth);
Pocket pocket = new Pocket(id, dimID, pos.getX(), pos.getZ());
pockets.put(id, pocket);
if (id >= nextID) nextID = id + 1;
markDirty();

View file

@ -19,7 +19,23 @@ import java.util.EnumSet;
public class TeleportUtils {
public static Entity teleport(Entity entity, Location location, float yaw, float pitch) { // TODO float position?
public static Entity teleport(Entity entity, Location location) {
return teleport(entity, location, entity.rotationYaw, entity.rotationPitch);
}
public static Entity teleport(Entity entity, Location location, float yaw, float pitch) {
return teleport(entity, location.getDimID(), location.getPos().getX(), location.getPos().getY(), location.getPos().getZ(), yaw, pitch);
}
public static Entity teleport(Entity entity, BlockPos pos, float yaw, float pitch) {
return teleport(entity, WorldUtils.getDim(entity.getEntityWorld()), pos.getX(), pos.getY(), pos.getZ(), yaw, pitch);
}
public static Entity teleport(Entity entity, double x, double y, double z, float yaw, float pitch) {
return teleport(entity, WorldUtils.getDim(entity.getEntityWorld()), x, y, z, yaw, pitch);
}
public static Entity teleport(Entity entity, int newDimension, double x, double y, double z, float yaw, float pitch) {
if (entity.world.isRemote || !(entity.world instanceof WorldServer) || entity.isDead) return entity; // dead means inactive, not a dead player
yaw = MathHelper.wrapDegrees(yaw);
@ -29,7 +45,7 @@ public class TeleportUtils {
entity.removePassengers();
int oldDimension = entity.dimension;
int newDimension = location.getDimID();
// int newDimension = dim;
if (entity instanceof EntityPlayerMP) {
entity.noClip = true;
@ -38,14 +54,14 @@ public class TeleportUtils {
if (oldDimension == newDimension) { // Based on CommandTeleport.doTeleport
if (entity instanceof EntityPlayerMP) {
((EntityPlayerMP) entity).connection.setPlayerLocation(
location.getPos().getX(),
location.getPos().getY(),
location.getPos().getZ(),
x,
y,
z,
yaw,
pitch,
EnumSet.noneOf(SPacketPlayerPosLook.EnumFlags.class));
} else {
entity.setLocationAndAngles(location.getPos().getX(), location.getPos().getY(), location.getPos().getZ(), yaw, pitch);
entity.setLocationAndAngles(x, y, z, yaw, pitch);
}
entity.setRotationYawHead(yaw);
return entity;
@ -60,7 +76,7 @@ public class TeleportUtils {
if (entity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entity;
try {
Field invulnerableDimensionChange = EntityPlayerMP.class.getDeclaredField("invulnerableDimensionChange"); // Prevents cancelling the position change in survival. TODO: necessary?
Field invulnerableDimensionChange = EntityPlayerMP.class.getDeclaredField("invulnerableDimensionChange"); // Prevents cancelling the position change in survival.
invulnerableDimensionChange.setAccessible(true);
invulnerableDimensionChange.setBoolean(player, true); // without this, there's a chance that the new player position gets cancelled
} catch (NoSuchFieldException|IllegalAccessException e) {
@ -77,7 +93,7 @@ public class TeleportUtils {
// Move to new world
oldServer.profiler.startSection("moving");
player.moveToBlockPosAndAngles(location.getPos(), yaw, pitch); // TODO: clamp to world border or -29999872, 29999872 like in original code?
player.setLocationAndAngles(x, y, z, yaw, pitch); // TODO: clamp to world border or -29999872, 29999872 like in original code?
if (entity.isEntityAlive()) oldServer.updateEntityWithOptionalForce(entity, false);
oldServer.profiler.endSection();
@ -100,7 +116,7 @@ public class TeleportUtils {
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldDimension, newDimension);
player.connection.sendPacket(new SPacketEffect(1032, BlockPos.ORIGIN, 0, false));
//player.connection.sendPacket(new SPacketEffect(1032, BlockPos.ORIGIN, 0, false)); // TODO
//player.prevBlockpos = null; // For frost walk. Is this needed? What about other fields?
/*player.lastExperience = -1;
@ -127,7 +143,7 @@ public class TeleportUtils {
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
newEntity.moveToBlockPosAndAngles(location.getPos(), yaw, pitch);
newEntity.setPositionAndRotation(x, y, z, yaw, pitch);
boolean oldForceSpawn = newEntity.forceSpawn;
newEntity.forceSpawn = true;
newServer.spawnEntity(newEntity);

View file

@ -1,5 +1,6 @@
package com.zixiken.dimdoors.shared.world.limbodimension;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.CloudRenderBlank;
import com.zixiken.dimdoors.shared.blocks.BlockFabric;
import com.zixiken.dimdoors.shared.blocks.ModBlocks;
@ -22,13 +23,12 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class WorldProviderLimbo extends WorldProvider {
@SideOnly(Side.CLIENT) private final IRenderHandler skyRenderer = new LimboSkyProvider();
@SideOnly(Side.CLIENT) private final IRenderHandler cloudRenderer = new CloudRenderBlank();
@Override
public void init() {
hasSkyLight = false;
biomeProvider = new BiomeProviderSingle(ModBiomes.LIMBO);
DimDoors.proxy.setCloudRenderer(this, new CloudRenderBlank());
DimDoors.proxy.setSkyRenderer(this, new LimboSkyProvider());
}
@Override
@ -113,16 +113,4 @@ public class WorldProviderLimbo extends WorldProvider {
public Vec3d getFogColor(float celestialAngle, float partialTicks) {
return new Vec3d(.2, .2, .2);
}
@Override
@SideOnly(Side.CLIENT)
public IRenderHandler getSkyRenderer() {
return skyRenderer;
}
@Override
@SideOnly(Side.CLIENT)
public IRenderHandler getCloudRenderer() {
return cloudRenderer;
}
}

View file

@ -29,16 +29,6 @@ public class WorldProviderPersonalPocket extends WorldProviderPocket {
}
}
@Override
public double getHorizon() {
return world.getHeight() - 256;
}
@Override
public int getActualHeight() {
return -256;
}
@SideOnly(Side.CLIENT)
@Override
public Vec3d getSkyColor(Entity cameraEntity, float partialTicks) {

View file

@ -1,5 +1,6 @@
package com.zixiken.dimdoors.shared.world.pocketdimension;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.CloudRenderBlank;
import com.zixiken.dimdoors.shared.pockets.EnumPocketType;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
@ -8,7 +9,6 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DimensionType;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -16,12 +16,11 @@ import javax.annotation.Nullable;
public abstract class WorldProviderPocket extends WorldProvider {
@SideOnly(Side.CLIENT) private final IRenderHandler cloudRenderer = new CloudRenderBlank();
@Override
public void init() {
// TODO: save pocket registry nbt here? (see WorldProviderEnd)
hasSkyLight = true;
DimDoors.proxy.setCloudRenderer(this, new CloudRenderBlank());
}
@Override
@ -49,12 +48,6 @@ public abstract class WorldProviderPocket extends WorldProvider {
@Override @Nullable
@SideOnly(Side.CLIENT) public float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks) { return null; }
@Override
@SideOnly(Side.CLIENT)
public IRenderHandler getCloudRenderer() {
return cloudRenderer;
}
@Override @SideOnly(Side.CLIENT) public boolean doesXZShowFog(int x, int z) {
return false; // TODO: set this to true outside of pockets
}
@ -67,5 +60,12 @@ public abstract class WorldProviderPocket extends WorldProvider {
@Override @SideOnly(Side.CLIENT) public Vec3d getFogColor(float celestialAngle, float partialTicks) { return Vec3d.ZERO; }
@Override
@SideOnly(Side.CLIENT)
public double getVoidFogYFactor() {
return 1;
}
public abstract EnumPocketType getPocketType();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB