Trying to repair teleportation 001
This commit is contained in:
parent
b2f47a6f7d
commit
85f62ca323
8 changed files with 74 additions and 43 deletions
|
@ -76,6 +76,10 @@ public class DimDoors {
|
|||
public static void chat(EntityPlayer player, String text) {
|
||||
player.sendMessage(new TextComponentString("[DimDoors] " + text));
|
||||
}
|
||||
|
||||
public static void warning(Class classFiredFrom, String text) {
|
||||
FMLLog.warning("[DimDoors] " + text + " (" + classFiredFrom.toString() + " )", 0);
|
||||
}
|
||||
|
||||
public static void log(Class classFiredFrom, String text) {
|
||||
FMLLog.info("[DimDoors] " + text + " (" + classFiredFrom.toString() + " )", 0);
|
||||
|
|
|
@ -44,6 +44,9 @@ public class ItemRiftConnectionTool extends ItemTool {
|
|||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
|
||||
if (worldIn.isRemote) {
|
||||
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||
}
|
||||
if (!stack.hasTagCompound()) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("isInConnectMode", true);
|
||||
|
@ -51,7 +54,7 @@ public class ItemRiftConnectionTool extends ItemTool {
|
|||
}
|
||||
|
||||
RayTraceResult hit = rayTrace(worldIn, playerIn, true);
|
||||
if (RayTraceHelper.isRift(hit, worldIn)) {
|
||||
if (RayTraceHelper.isAbstractRift(hit, worldIn)) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) worldIn.getTileEntity(hit.getBlockPos());
|
||||
if (playerIn.isSneaking()) {
|
||||
return selectRift(stack, worldIn, rift, playerIn); //new ActionResult(EnumActionResult.PASS, stack));
|
||||
|
@ -69,11 +72,9 @@ public class ItemRiftConnectionTool extends ItemTool {
|
|||
if (compound.hasKey("RiftID")) {
|
||||
int primaryRiftID = compound.getInteger("RiftID");
|
||||
int secondaryRiftID = rift.getRiftID();
|
||||
if (!worldIn.isRemote) {
|
||||
DimDoors.chat(playerIn, "Pairing rift " + primaryRiftID
|
||||
+ " with rift " + secondaryRiftID + ".");
|
||||
RiftRegistry.Instance.pair(primaryRiftID, secondaryRiftID);
|
||||
}
|
||||
DimDoors.chat(playerIn, "Pairing rift " + primaryRiftID
|
||||
+ " with rift " + secondaryRiftID + ".");
|
||||
RiftRegistry.Instance.pair(primaryRiftID, secondaryRiftID);
|
||||
compound.removeTag("RiftID");
|
||||
stack.damageItem(1, playerIn);
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||
import com.zixiken.dimdoors.tileentities.TileEntityRift;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
@ -9,6 +10,10 @@ public class RayTraceHelper {
|
|||
public static boolean isRift(RayTraceResult hit, World world) {
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.BLOCK && world.getTileEntity(hit.getBlockPos()) instanceof TileEntityRift;
|
||||
}
|
||||
|
||||
public static boolean isAbstractRift(RayTraceResult hit, World world) {
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.BLOCK && world.getTileEntity(hit.getBlockPos()) instanceof DDTileEntityBase;
|
||||
}
|
||||
|
||||
public static boolean isLivingEntity(RayTraceResult hit) {
|
||||
return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.ENTITY && hit.entityHit instanceof EntityLivingBase;
|
||||
|
|
|
@ -184,10 +184,14 @@ public class RiftRegistry {
|
|||
TileEntity tileEntity = location.getTileEntity(); //@todo this method might need to be in another class?
|
||||
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
rift.pair(riftID2);
|
||||
DimDoors.log(this.getClass(), "RiftRegistry trying to connect rift " + riftID + " to rift " + riftID2 + ".");
|
||||
boolean alreadyPaired = rift.pair(riftID2);
|
||||
if (!alreadyPaired) {
|
||||
DimDoors.log(this.getClass(), "RiftRegistry unregistering rift " + riftID + " from unPairedRiftRegistry.");
|
||||
unpairedRiftList.remove((Integer) riftID);
|
||||
//@todo remove the riftID from the depth list as well
|
||||
}
|
||||
}
|
||||
unpairedRiftList.remove((Integer) riftID);
|
||||
//@todo remove the riftID from the depth list as well
|
||||
}
|
||||
|
||||
public void unpair(int riftID) {
|
||||
|
@ -201,10 +205,12 @@ public class RiftRegistry {
|
|||
TileEntity tileEntity = location.getTileEntity();
|
||||
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||
rift.unpair();
|
||||
boolean alreadyUnPaired = rift.unpair();
|
||||
if (!alreadyUnPaired) {
|
||||
unpairedRiftList.add(riftID);
|
||||
//@todo add the riftID from the depth list as well, maybe move this to the tileEntityRift class itself though?
|
||||
}
|
||||
}
|
||||
unpairedRiftList.add(riftID);
|
||||
//@todo add the riftID from the depth list as well, maybe move this to the tileEntityRift class itself though?
|
||||
}
|
||||
|
||||
public void setLastChangedRift(DDTileEntityBase origRift) {
|
||||
|
@ -216,11 +222,16 @@ public class RiftRegistry {
|
|||
}
|
||||
|
||||
public boolean teleportEntityToRift(Entity entity, int pairedRiftID) {
|
||||
DimDoors.log(this.getClass(), "RiftID of rift that entity is teleporting to is " + pairedRiftID + ".");
|
||||
if (pairedRiftID < 0) {
|
||||
DimDoors.warning(this.getClass(), "RiftID of rift that entity is teleporting to seems to be lower than 0 and it shouldn't.");
|
||||
return false;
|
||||
}
|
||||
Location destinationRiftLocation = getRiftLocation(pairedRiftID);
|
||||
DDTileEntityBase destinationRift = (DDTileEntityBase) destinationRiftLocation.getTileEntity();
|
||||
if (destinationRift == null) {
|
||||
DimDoors.warning(this.getClass(), "The rift that an entity is trying to teleport to seems to be null.");
|
||||
}
|
||||
return TeleportHelper.teleport(entity, destinationRift.getTeleportTargetLocation());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import net.minecraft.client.entity.EntityPlayerSP;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.server.SPacketUpdateHealth;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
@ -25,8 +27,7 @@ public class TeleportHelper extends Teleporter {
|
|||
}
|
||||
|
||||
public static boolean teleport(Entity entity, Location newLocation) {
|
||||
if (DimDoors.isClient()) {
|
||||
//DimDoors.log(TeleportHelper.class, "Not teleporting, because EntityPlayerSP.");
|
||||
if (DimDoors.getDefWorld().isRemote) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -38,15 +39,16 @@ public class TeleportHelper extends Teleporter {
|
|||
//DimDoors.log(TeleportHelper.class, "Starting teleporting now:");
|
||||
if (oldDimID == newDimID) {
|
||||
if (entity instanceof EntityPlayer) {
|
||||
//DimDoors.log(TeleportHelper.class, "Using teleport method 1");
|
||||
DimDoors.log(TeleportHelper.class, "Teleporting Player within same dimension.");
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
|
||||
player.setLocationAndAngles(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5, player.getRotationYawHead(), player.getRotatedYaw(Rotation.CLOCKWISE_180)); //@todo, instead of following line
|
||||
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
|
||||
player.world.updateEntityWithOptionalForce(player, false);
|
||||
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
|
||||
player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
|
||||
player.timeUntilPortal = 150;
|
||||
} else {
|
||||
//DimDoors.log(TeleportHelper.class, "Using teleport method 2");
|
||||
DimDoors.log(TeleportHelper.class, "Teleporting non-Player within same dimension.");
|
||||
WorldServer world = (WorldServer) entity.world;
|
||||
|
||||
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
|
||||
|
@ -55,14 +57,14 @@ public class TeleportHelper extends Teleporter {
|
|||
}
|
||||
} else {
|
||||
if (entity instanceof EntityPlayer) {
|
||||
//DimDoors.log(TeleportHelper.class, "Using teleport method 3");
|
||||
DimDoors.log(TeleportHelper.class, "Teleporting Player to new dimension.");
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
player.changeDimension(newDimID); //@todo, this only works for Vanilla dimensions, I've heard?
|
||||
player.setPositionAndUpdate(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
|
||||
player.world.updateEntityWithOptionalForce(player, false);
|
||||
//player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
|
||||
} else if (!entity.world.isRemote) {
|
||||
//DimDoors.log(TeleportHelper.class, "Using teleport method 4");
|
||||
DimDoors.log(TeleportHelper.class, "Teleporting non-Player to new dimension.");
|
||||
entity.changeDimension(newDimID);
|
||||
entity.setPosition(newPos.getX() + 0.5, newPos.getY() + 0.5, newPos.getZ() + 0.5);
|
||||
oldWorldServer.resetUpdateEntityTick();
|
||||
|
|
|
@ -30,10 +30,10 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
return oldState.getBlock() != newSate.getBlock();
|
||||
}
|
||||
|
||||
public void pair(int otherRiftID) { //should only ever be called from the RiftRegistry.pair method
|
||||
public boolean pair(int otherRiftID) { //should only ever be called from the RiftRegistry.pair method
|
||||
if (isPaired) {
|
||||
if (otherRiftID == pairedRiftID) {
|
||||
return;
|
||||
return true;
|
||||
} else {
|
||||
RiftRegistry.Instance.unpair(pairedRiftID);
|
||||
}
|
||||
|
@ -42,16 +42,18 @@ public abstract class DDTileEntityBase extends TileEntity {
|
|||
isPaired = true;
|
||||
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
||||
this.markDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void unpair() { //should only ever be called from the RiftRegistry.unpair method
|
||||
public boolean unpair() { //should only ever be called from the RiftRegistry.unpair method
|
||||
if (!isPaired) {
|
||||
return;
|
||||
return true;
|
||||
} else {
|
||||
isPaired = false;
|
||||
RiftRegistry.Instance.unpair(pairedRiftID);
|
||||
}
|
||||
this.markDirty();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void register(int depth) {
|
||||
|
|
|
@ -61,15 +61,21 @@ public class TileEntityDimDoor extends DDTileEntityBase {
|
|||
|
||||
@Override
|
||||
public boolean tryTeleport(Entity entity) {
|
||||
//DimDoors.log(this.getClass(), "Trying to teleport from rift " + getRiftID() + ".");
|
||||
if (!isPaired()) {
|
||||
//DimDoors.log(this.getClass(), "Trying to find suitable destination rift.");
|
||||
int randomPairedRiftID = RiftRegistry.Instance.getRandomUnpairedRiftID(getRiftID());
|
||||
if (randomPairedRiftID < 0) {
|
||||
//DimDoors.log(this.getClass(), "No suitable destination rift was found.");
|
||||
return false;
|
||||
}
|
||||
RiftRegistry.Instance.pair(getRiftID(), randomPairedRiftID);
|
||||
//@todo try to automatically pair this door somehow
|
||||
} else {
|
||||
//DimDoors.log(this.getClass(), "This rift was already paired correctly.");
|
||||
}
|
||||
return RiftRegistry.Instance.teleportEntityToRift(entity, getPairedRiftID());
|
||||
//DimDoors.log(this.getClass(), "Starting teleportation.");
|
||||
return RiftRegistry.Instance.teleportEntityToRift(entity, getPairedRiftID()); //this seems to return false...
|
||||
}
|
||||
|
||||
public void uponDoorPlacement(@Nullable TileEntity possibleOldRift) {
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
{
|
||||
"modListVersion":2,
|
||||
"modList":
|
||||
[
|
||||
{
|
||||
"modid": "dimdoors",
|
||||
"name": "Dimensional Doors",
|
||||
"description": "Bend and twist reality itself, creating pocket dimensions, rifts, and much more",
|
||||
"version": "3.0.0-a1",
|
||||
"credits": "Created by StevenRS11, Coded by StevenRS11 and SenseiKiwi, Logo and Testing by Jaitsu, Recent updates by Zixiken and Waterpicker",
|
||||
"logoFile": "/dimdoors_logo.png",
|
||||
"mcversion": "1.10.2",
|
||||
"url": "http://www.minecraftforum.net/topic/1650007",
|
||||
"updateUrl": "",
|
||||
"authorList": [ "StevenRS11", "SenseiKiwi", "Zixiken", "WaterPicker" ],
|
||||
"parent":"",
|
||||
"screenshots": [],
|
||||
"dependencies": [ "Forge"]
|
||||
}
|
||||
]
|
||||
"modListVersion":2,
|
||||
"modList":
|
||||
[
|
||||
{
|
||||
"modid": "dimdoors",
|
||||
"name": "Dimensional Doors",
|
||||
"description": "Bend and twist reality itself, creating pocket dimensions, rifts, and much more",
|
||||
"version": "${version}",
|
||||
"credits": "Created by StevenRS11, Coded by StevenRS11 and SenseiKiwi, Logo and Testing by Jaitsu, Recent updates by Zixiken and Waterpicker",
|
||||
"logoFile": "/dimdoors_logo.png",
|
||||
"mcversion": "1.10.2",
|
||||
"url": "http://www.minecraftforum.net/topic/1650007",
|
||||
"updateUrl": "",
|
||||
"authorList": [ "StevenRS11", "SenseiKiwi", "Zixiken", "WaterPicker", "Robijnvogel" ],
|
||||
"parent":"",
|
||||
"screenshots": [],
|
||||
"dependencies": [ "Forge"]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue