Skip to content

Commit

Permalink
Big fixes
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
Runemoro committed Dec 19, 2017
1 parent 0ed714e commit 02f22dd
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 102 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/zixiken/dimdoors/DimDoors.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
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;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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;
Expand Down Expand Up @@ -54,4 +56,14 @@ public EntityPlayer getLocalPlayer() {
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);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/zixiken/dimdoors/server/DDProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

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;

/**
Expand All @@ -30,4 +32,10 @@ public EntityPlayer getLocalPlayer() {
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) {}
}
7 changes: 7 additions & 0 deletions src/main/java/com/zixiken/dimdoors/shared/DDProxyCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
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;
Expand Down Expand Up @@ -44,4 +46,9 @@ public void onInitialization(FMLInitializationEvent event) {
SchematicHandler.INSTANCE.loadSchematics();
DefaultSchematicGenerator.generateDefaultSchematics();
}


abstract public void setCloudRenderer(WorldProvider provider, IRenderHandler renderer);

abstract public void setSkyRenderer(WorldProvider provider, IRenderHandler renderer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public List<String> getAliases() {

@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;
Expand All @@ -57,11 +64,12 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
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 {
Expand All @@ -72,7 +80,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
@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);
}
Expand Down
105 changes: 64 additions & 41 deletions src/main/java/com/zixiken/dimdoors/shared/commands/PocketCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
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;
Expand All @@ -13,6 +15,7 @@
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;
Expand All @@ -34,7 +37,7 @@ public String getName() {

@Override
public String getUsage(ICommandSender sender) {
return "dimpocket <group> <name>";
return "dimpocket <group> <name> [setup]";
}

@Override
Expand All @@ -44,20 +47,56 @@ public List<String> getAliases() {

@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.");
Expand All @@ -67,34 +106,18 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
*
* @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;
}

Expand All @@ -156,10 +156,10 @@ public Pocket newPocket(int depth) {
*
* @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();
Expand Down
Loading

0 comments on commit 02f22dd

Please sign in to comment.