WarpDoor improvements

-Added Forge version dependency
-Made sure that Warp Doors always lead to a non-pocket dimension if they
lead anywhere at all
-Added Event checks on Players entering chunks in/and pocket dimensions
This commit is contained in:
Mathijs Riezebos 2017-05-08 17:42:27 +02:00
parent 53568707f0
commit c29c9b3d23
9 changed files with 119 additions and 21 deletions

View file

@ -23,7 +23,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
@Mod(modid = DimDoors.MODID, name = "Dimensional Doors", version = DimDoors.VERSION)
@Mod(modid = DimDoors.MODID, name = "Dimensional Doors", version = DimDoors.VERSION, dependencies = "required-after:Forge@[12.18.3.2281,)")
public class DimDoors {
public static final String VERSION = "${version}";

View file

@ -6,28 +6,78 @@
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent;
/**
*
* @author s101426
* @author Robijnvogel
*/
public class DDEventHandler {
@SubscribeEvent
public void onPlayerJoinWorld(EntityJoinWorldEvent event) { //@todo, probably move this to another class
public void onPlayerJoinWorld(EntityJoinWorldEvent event) {
//check if config default values have been checked
if (!DDConfig.HAVE_CONFIG_DEFAULTS_BEEN_CHECKED_FOR_CORRECTNESS) {
if (!DimDoors.VERSION.contains("a")) { //if it is not an alpha version
Entity entity = event.getEntity();
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
DimDoors.chat(player, "The default values for the config files fo this non-alpha version of DimDoors have not been sufficiently checked on correctness. Please notify the developer about this IF no newer version of this mod is available.");
World world = entity.world;
if (!world.isRemote) {
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
DimDoors.chat(player, "The default values for the config files fo this non-alpha version of DimDoors have not been sufficiently checked on correctness. Please notify the developer about this IF no newer version of this mod is available.");
}
}
}
}
}
@SubscribeEvent
public void onPlayerChangedDim(PlayerChangedDimensionEvent event) {
EntityPlayer player = event.player;
int dimID = event.toDim;
World world = player.world;
if (!world.isRemote && DimDoorDimensions.isPocketDimensionID(dimID)) {
if (player instanceof EntityPlayerMP) {
EntityPlayerMP playerMP = (EntityPlayerMP) player;
checkPlayerLocationPermission(playerMP);
}
}
}
@SubscribeEvent
public void onEntityEnterChunk(EntityEvent.EnteringChunk event) {
Entity entity = event.getEntity();
if (entity instanceof EntityPlayerMP) {
World world = entity.world;
if (!world.isRemote && DimDoorDimensions.isPocketDimensionID(world.provider.getDimension())) {
EntityPlayerMP player = (EntityPlayerMP) entity;
checkPlayerLocationPermission(player);
}
}
}
/**
*
* @param player the player entity to check for permissions
* @pre {@code (entity instanceof EntityPlayerMP)}
*/
private void checkPlayerLocationPermission(EntityPlayerMP player) {
if (!player.isDead && !(player.getPosition().getY() < 1)) {
Location location = Location.getLocation(player);
DimDoors.log(this.getClass(), "A player just entered a new chunk in a DimDoors dimension.");
if (!PocketRegistry.INSTANCE.isPlayerAllowedToBeHere(player, location)) {
//@todo this doesn't really work yet.
//DimDoors.chat(player, "You are not supposed to be here. In future version of this mod, you will be teleported to Limbo if you go here.");
}
}
}
}

View file

@ -34,7 +34,7 @@ public class Pocket {
private final int x; //pocket-relative 0 coordinate, should be at x * PocketRegistry.INSTANCE.gridSize * 16
private final int z; //pocket-relative 0 coordinate, should be at z * PocketRegistry.INSTANCE.gridSize * 16
private final List<String> playerUUIDs;
private final List<Integer> riftIDs;
private final List<Integer> riftIDs; //@todo these aren't being used after the entrance door has been paired, I believe
private final Location depthZeroLocation;
//when adding any new variables, don't forget to add them to the write and load functions
@ -158,6 +158,13 @@ public class Pocket {
return index;
}
/**
* @return the depth
*/
public int getDepth() {
return depth;
}
/**
* @return the depthZeroLocation
*/
@ -165,6 +172,10 @@ public class Pocket {
return depthZeroLocation;
}
public void addRiftID(int id) {
riftIDs.add(id);
}
public void validatePlayerEntry(EntityPlayer player) {
String playerUUID = player.getCachedUniqueIdString();
if (!playerUUIDs.contains(playerUUID)) { //the 'contains' method uses the 'equals' method to check, so for Strings, this should work.

View file

@ -316,7 +316,7 @@ public class PocketRegistry {
return group;
}
*/
private int getPocketIDFromCoords(Location location) {
public int getPocketIDFromCoords(Location location) {
final int dimID = location.getDimensionID();
if (DimDoorDimensions.isPocketDimensionID(dimID)) {
int x = location.getPos().getX();

View file

@ -79,7 +79,8 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
return this;
}
public boolean isDoorOnRift(World world, BlockPos pos) {
@Override
public boolean isDoorOnRift(World world, BlockPos pos) { //@todo what does this even mean?
return true;
}

View file

@ -5,6 +5,7 @@ import com.zixiken.dimdoors.shared.*;
import com.zixiken.dimdoors.shared.tileentities.TileEntityDimDoor;
import com.zixiken.dimdoors.shared.util.DDStringUtils;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
@ -52,10 +53,18 @@ public class PocketCommand extends CommandBase {
BlockPos pos = player.getPosition();
World world = player.world;
Location playerLoc = new Location(world, pos);
Location origLoc = new Location(world, pos);
int dimID = origLoc.getDimensionID();
if (DimDoorDimensions.isPocketDimensionID(dimID)) {
int pocketID = PocketRegistry.INSTANCE.getPocketIDFromCoords(origLoc);
EnumPocketType type = DimDoorDimensions.getPocketType(dimID);
Pocket oldPocket = PocketRegistry.INSTANCE.getPocket(pocketID, type);
origLoc = oldPocket.getDepthZeroLocation();
}
PocketTemplate template = SchematicHandler.INSTANCE.getDungeonTemplate(args[0], args[1]);
Pocket pocket = PocketRegistry.INSTANCE.generatePocketAt(EnumPocketType.DUNGEON, 1, playerLoc, template);
Pocket pocket = PocketRegistry.INSTANCE.generatePocketAt(EnumPocketType.DUNGEON, 1, origLoc, template);
int entranceDoorID = pocket.getEntranceDoorID();
RiftRegistry.INSTANCE.setLastGeneratedEntranceDoorID(entranceDoorID);
}

View file

@ -3,6 +3,7 @@ package com.zixiken.dimdoors.shared.tileentities;
import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.shared.DDConfig;
import com.zixiken.dimdoors.shared.EnumPocketType;
import com.zixiken.dimdoors.shared.Pocket;
import com.zixiken.dimdoors.shared.PocketRegistry;
import com.zixiken.dimdoors.shared.blocks.BlockDimDoor;
import com.zixiken.dimdoors.shared.util.Location;
@ -90,26 +91,42 @@ public class TileEntityDimDoor extends DDTileEntityBase {
//load data from old rift (that must already have been registered)
loadDataFrom(oldRift);
} else {
Location locationOfThisRift = new Location(world, pos);
pocketID = PocketRegistry.INSTANCE.getPocketIDFromCoords(locationOfThisRift);
if (pocketID >= 0) {
isInPocket = true;
pocketType = DimDoorDimensions.getPocketType(locationOfThisRift.getDimensionID());
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType);
depth = pocket.getDepth();
}
//default data and set register this rift in the registry
register(0); //@todo check if it's in a pocket and register it at that depth instead if applicable
register(depth); //depth is 0 by default; registration sets this rift's riftID
if (pocketID >= 0) {
Pocket pocket = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType);
pocket.addRiftID(riftID); //@todo not used yet?
}
}
//storing the orientation inside the tile-entity, because that thing can actually save the orientation in the worldsave, unlike the block itself, which fail at that stuff somehow
this.orientation = this.getWorld().getBlockState(this.getPos()).getValue(BlockDimDoor.FACING).getOpposite();
this.orientation = this.getWorld().getBlockState(this.getPos()).getValue(BlockDimDoor.FACING).getOpposite(); //@todo since this is used to determine the render of the "portal, this gets reset to the "wrong" side every time the door gets updated
}
protected int getNewTeleportDestination() {
int otherRiftID;
Location locationOfThisRift = RiftRegistry.INSTANCE.getRiftLocation(this.riftID); //returns null if this rift isn't registered
if (locationOfThisRift.getDimensionID() == DimDoorDimensions.getPocketDimensionType(EnumPocketType.DUNGEON).getId()) { //if this dimdoor is a pocket Dungeon
if (this.isInPocket && this.pocketType ==EnumPocketType.DUNGEON) {
Location origLocation = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType).getDepthZeroLocation();
//choose between generating a new pocket or connecting to another door on a similar or close depth
if (DDRandomUtils.weightedBoolean(20, 80)) { //@todo make this configurable
otherRiftID = RiftRegistry.INSTANCE.getRandomUnpairedRiftIDAroundDepth(getRiftID(), depth);
if (otherRiftID < 0) { //ergo: no other rift can be found
//@todo, this should rarely happen. Put in an easter egg?
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), locationOfThisRift);
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), origLocation);
}
} else {
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), locationOfThisRift);
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), origLocation);
}
} else {
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.PUBLIC, 0, locationOfThisRift); //@todo should this depth be 1 instead?

View file

@ -6,6 +6,7 @@ import com.zixiken.dimdoors.shared.IChunkLoader;
import com.zixiken.dimdoors.shared.PocketRegistry;
import com.zixiken.dimdoors.shared.RiftRegistry;
import com.zixiken.dimdoors.shared.util.Location;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.ForgeChunkManager.Ticket;
@ -68,8 +69,11 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo
//DimDoors.log(this.getClass(), "Trying to find suitable destination rift.");
int otherRiftID = RiftRegistry.INSTANCE.getRandomUnpairedRiftIDAtDepth(getRiftID(), depth);
if (otherRiftID < 0) {
Location locationOfThisRift = RiftRegistry.INSTANCE.getRiftLocation(this.riftID);
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), locationOfThisRift);
Location origLocation = RiftRegistry.INSTANCE.getRiftLocation(this.riftID);
if (origLocation.getDimensionID() == DimDoorDimensions.getPocketDimensionType(EnumPocketType.DUNGEON).getId()) { //if this dimdoor is a pocket Dungeon
origLocation = PocketRegistry.INSTANCE.getPocket(pocketID, pocketType).getDepthZeroLocation();
}
otherRiftID = PocketRegistry.INSTANCE.getEntranceDoorIDOfNewPocket(EnumPocketType.DUNGEON, getRandomlyTransFormedDepth(), origLocation);
}
if (otherRiftID < 0) {

View file

@ -4,6 +4,7 @@ import com.zixiken.dimdoors.DimDoors;
import java.io.Serializable;
import java.util.Objects;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -56,11 +57,16 @@ public class Location implements Serializable {
return dimensionID;
}
public static Location getLocation(TileEntity tileEntity) {//@todo Location is not yet comparable, so a Location begotten by this method, can not be used to find a rift ID in the RiftRegistry
public static Location getLocation(TileEntity tileEntity) {
World world = tileEntity.getWorld();
int dimID = world.provider.getDimension();
BlockPos blockPos = tileEntity.getPos();
return new Location(dimID, blockPos);
return new Location(world, blockPos);
}
public static Location getLocation(Entity entity) {
World world = entity.world;
BlockPos blockPos = entity.getPosition();
return new Location(world, blockPos);
}
public static NBTTagCompound writeToNBT(Location location) {