Restructured Teleportation
Reshaped the teleportation implementation in a way so that it fits my view on the structure. :P Removed redundant methods
This commit is contained in:
parent
2767e36e2c
commit
111f2f9b51
15 changed files with 44 additions and 101 deletions
|
@ -1,14 +1,8 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockDimDoor extends BlockDimDoorBase {
|
||||
|
||||
|
@ -22,16 +16,6 @@ public class BlockDimDoor extends BlockDimDoorBase {
|
|||
setRegistryName(ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
TileEntity te = location.getTileEntity();
|
||||
|
||||
if(te != null && te instanceof DDTileEntityBase) {
|
||||
int id = ((DDTileEntityBase) te).riftID;
|
||||
RiftRegistry.Instance.pair(id, id);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDoor() {
|
||||
return ModItems.itemDimDoor;
|
||||
|
|
|
@ -3,9 +3,7 @@ package com.zixiken.dimdoors.blocks;
|
|||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import com.zixiken.dimdoors.shared.TeleportHelper;
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -24,7 +22,6 @@ import net.minecraft.util.EnumFacing;
|
|||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
@ -42,9 +39,8 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
|
|||
if (down.getValue(BlockDoor.OPEN)
|
||||
&& entity instanceof EntityPlayer
|
||||
&& isEntityFacingDoor(down, (EntityLivingBase) entity)) {
|
||||
enterDimDoor(world, pos, entity);
|
||||
this.toggleDoor(world, pos, false);
|
||||
DimDoors.log(BlockDimDoorBase.class, "RiftID = " + getRiftTile(world, pos, world.getBlockState(pos)).riftID + " Derp");
|
||||
enterDimDoor(world, pos, entity);
|
||||
}
|
||||
} else {
|
||||
BlockPos up = pos.up();
|
||||
|
@ -128,26 +124,17 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
|
|||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
TileEntityDimDoor dimDoor = new TileEntityDimDoor();
|
||||
updateAttachedTile(world, dimDoor.getPos());
|
||||
placeLink(new Location(world, dimDoor.getPos()));
|
||||
|
||||
return dimDoor;
|
||||
return new TileEntityDimDoor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterDimDoor(World world, BlockPos pos, Entity entity) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
|
||||
if(te != null && te instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase base = (DDTileEntityBase) te;
|
||||
Location loc = RiftRegistry.Instance.getRiftLocation(base.pairedRiftID);
|
||||
|
||||
if(loc != null && loc.getTileEntity() instanceof DDTileEntityBase) {
|
||||
loc = ((DDTileEntityBase) loc.getTileEntity()).getTeleportTarget();
|
||||
|
||||
TeleportHelper.teleport(entity, loc);
|
||||
}
|
||||
DDTileEntityBase riftTile = getRiftTile(world, pos, world.getBlockState(pos));
|
||||
if (riftTile.tryTeleport(entity)) {
|
||||
//player is succesfully teleported
|
||||
} else {
|
||||
//@todo some kind of message that teleporting wasn't successfull
|
||||
//probably should only happen on personal dimdoors
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,6 +170,7 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
|
|||
}
|
||||
}
|
||||
|
||||
//returns the DDTileEntityBase that is the tile entity belonging to the door block "state" at this "pos" in the "world"
|
||||
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {
|
||||
TileEntity tileEntity;
|
||||
if (state.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityDimDoorGold;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockDimDoorGold extends BlockDimDoorBase {
|
||||
|
@ -21,10 +18,6 @@ public class BlockDimDoorGold extends BlockDimDoorBase {
|
|||
setRegistryName(ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDoor() {
|
||||
return ModItems.itemDimDoorGold;
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockDimDoorPersonal extends BlockDimDoorBase {
|
||||
|
||||
|
@ -18,10 +15,6 @@ public class BlockDimDoorPersonal extends BlockDimDoorBase {
|
|||
setRegistryName(ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDoor() {
|
||||
return ModItems.itemDimDoorPersonal;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.EnumBlockRenderType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -41,10 +39,6 @@ public class BlockDimDoorTransient extends BlockDimDoorBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDoor() {
|
||||
return null;
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import java.util.Random;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockDimDoorUnstable extends BlockDimDoorBase {
|
||||
|
||||
|
@ -23,10 +19,6 @@ public class BlockDimDoorUnstable extends BlockDimDoorBase {
|
|||
setLightLevel(.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDoor() {
|
||||
return ModItems.itemDimDoorChaos;
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.items.ModItems;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockDimDoorWarp extends BlockDimDoorBase {
|
||||
|
||||
|
@ -18,10 +15,6 @@ public class BlockDimDoorWarp extends BlockDimDoorBase {
|
|||
setRegistryName(ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDoor() {
|
||||
return ModItems.itemDimDoorWarp;
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.zixiken.dimdoors.blocks;
|
|||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityTransTrapdoor;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTrapDoor;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
|
@ -21,7 +21,6 @@ import net.minecraft.util.EnumHand;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityTransTrapdoor;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -76,21 +75,11 @@ public class BlockTransTrapdoor extends BlockTrapDoor implements IDimDoor, ITile
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
|
||||
this.placeLink(new Location(world, pos));
|
||||
world.setTileEntity(pos, createNewTileEntity(world, getMetaFromState(state)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileEntityTransTrapdoor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeLink(Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.zixiken.dimdoors.blocks;
|
||||
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -21,13 +19,6 @@ public interface IDimDoor {
|
|||
*/
|
||||
public void enterDimDoor(World world, BlockPos pos, Entity entity);
|
||||
|
||||
/**
|
||||
* called when a door is placed to determine how it will place a link
|
||||
*
|
||||
* @param location
|
||||
*/
|
||||
public void placeLink(Location location);
|
||||
|
||||
public Item getItemDoor();
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,14 +47,14 @@ public class Location {
|
|||
}
|
||||
|
||||
public World getWorld() {
|
||||
return DimensionManager.getWorld(dimensionID); //@todo HOW?
|
||||
return DimensionManager.getWorld(dimensionID);
|
||||
}
|
||||
|
||||
public int getDimensionID() {
|
||||
return dimensionID;
|
||||
}
|
||||
|
||||
static Location getLocation(TileEntity tileEntity) {
|
||||
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
|
||||
World world = tileEntity.getWorld();
|
||||
int dimID = world.provider.getDimension();
|
||||
BlockPos blockPos = tileEntity.getPos();
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -118,4 +119,8 @@ public class RiftRegistry {
|
|||
public DDTileEntityBase getLastChangedRift() {
|
||||
return lastBrokenRift;
|
||||
}
|
||||
|
||||
public void teleportEntityToRift(Entity entity, int pairedRiftID) {
|
||||
TeleportHelper.teleport(entity, getRiftLocation(pairedRiftID));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.zixiken.dimdoors.shared.Location;
|
|||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import java.util.Random;
|
||||
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;
|
||||
|
@ -89,4 +90,6 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
public Location getTeleportTarget() {
|
||||
return new Location(this.getWorld().provider.getDimension(), this.getPos());
|
||||
}
|
||||
|
||||
public abstract boolean tryTeleport(Entity entity);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package com.zixiken.dimdoors.tileentities;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.zixiken.dimdoors.blocks.BlockDimDoor;
|
||||
import com.zixiken.dimdoors.shared.Location;
|
||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class TileEntityDimDoor extends DDTileEntityBase {
|
||||
|
@ -66,4 +63,13 @@ public class TileEntityDimDoor extends DDTileEntityBase {
|
|||
|
||||
return new Location(world, pos.offset(facing));
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
if (!isPaired) {
|
||||
//@todo try to automatically pair this door somehow
|
||||
}
|
||||
RiftRegistry.Instance.teleportEntityToRift(entity, pairedRiftID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,4 +142,9 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
|
|||
public float[] getRenderColor(Random rand) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
return false; //@todo, rift blade functionality?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.zixiken.dimdoors.tileentities;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class TileEntityTransTrapdoor extends DDTileEntityBase {
|
||||
|
||||
|
@ -18,4 +19,10 @@ public class TileEntityTransTrapdoor extends DDTileEntityBase {
|
|||
}
|
||||
return rgbaColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
//@todo teleport the player somewhere to the Overworld?
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue