From aac1108056bd0d00d3f5880d2af2ccd69bd9a657 Mon Sep 17 00:00:00 2001
From: Mathijs Riezebos <robijn.bird@gmail.com>
Date: Fri, 20 Jan 2017 15:20:36 +0100
Subject: [PATCH 1/4] Cleaned up a little bit

Removed some useless privates from TileEntityDimDoor
Added some useful privates to DDTileEntityBase
---
 .../dimdoors/tileentities/DDTileEntityBase.java     |  6 ++++++
 .../dimdoors/tileentities/TileEntityDimDoor.java    | 13 +++----------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java b/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java
index 7168351b..cf64011c 100644
--- a/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java
+++ b/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java
@@ -16,6 +16,8 @@ public abstract class DDTileEntityBase extends TileEntity {
     private boolean isPaired = false;
     private int riftID = -1; //should not start at 0
     private int pairedRiftID = -1;
+    private boolean isInPocket = false;
+    private int pocketID = -1;
 
     /**
      *
@@ -66,6 +68,8 @@ public abstract class DDTileEntityBase extends TileEntity {
             this.isPaired = nbt.getBoolean("isPaired");
             this.riftID = nbt.getInteger("riftID");
             this.pairedRiftID = nbt.getInteger("pairedRiftID");
+            this.isInPocket = nbt.getBoolean("isInPocket");
+            this.pocketID = nbt.getInteger("pocketID");
         } catch (Exception e) {
         }
     }
@@ -76,6 +80,8 @@ public abstract class DDTileEntityBase extends TileEntity {
         nbt.setBoolean("isPaired", this.isPaired);
         nbt.setInteger("riftID", this.riftID);
         nbt.setInteger("pairedRiftID", this.pairedRiftID);
+        nbt.setBoolean("isInPocket", this.isInPocket);
+        nbt.setInteger("pocketID", this.pocketID);
         return nbt;
     }
 
diff --git a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java
index 198341f4..3d428cb6 100644
--- a/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java
+++ b/src/main/java/com/zixiken/dimdoors/tileentities/TileEntityDimDoor.java
@@ -11,11 +11,8 @@ public class TileEntityDimDoor extends DDTileEntityBase {
 
     public boolean doorIsOpen = false;
     public EnumFacing orientation = EnumFacing.SOUTH;
-    public boolean hasExit = false;
     public byte lockStatus = 1;
-    public boolean isDungeonChainLink = false;
-    public boolean hasGennedPair = false;
-
+    
     @Override
     public void readFromNBT(NBTTagCompound nbt) {
         super.readFromNBT(nbt);
@@ -23,9 +20,7 @@ public class TileEntityDimDoor extends DDTileEntityBase {
         try {
             this.doorIsOpen = nbt.getBoolean("doorIsOpen");
             this.orientation = EnumFacing.getFront(nbt.getInteger("orientation"));
-            this.hasExit = nbt.getBoolean("hasExit");
-            this.isDungeonChainLink = nbt.getBoolean("isDungeonChainLink");
-            this.hasGennedPair = nbt.getBoolean("hasGennedPair");
+            this.lockStatus = nbt.getByte("lockStatus");
         } catch (Exception e) {
         }
     }
@@ -35,10 +30,8 @@ public class TileEntityDimDoor extends DDTileEntityBase {
         super.writeToNBT(nbt);
 
         nbt.setBoolean("doorIsOpen", this.doorIsOpen);
-        nbt.setBoolean("hasExit", this.hasExit);
         nbt.setInteger("orientation", this.orientation.getIndex());
-        nbt.setBoolean("isDungeonChainLink", isDungeonChainLink);
-        nbt.setBoolean("hasGennedPair", hasGennedPair);
+        nbt.setByte("lockStatus", lockStatus);
         return nbt;
     }
 

From e027947fb0dc798a51deea2b347c36daf3a518d2 Mon Sep 17 00:00:00 2001
From: Waterpicker <Waterpickerenternity@gmail.com>
Date: Sat, 21 Jan 2017 06:54:20 -0600
Subject: [PATCH 2/4] Big batch of unfinished items.

---
 .../java/com/zixiken/dimdoors/DimDoors.java   |  13 ++
 .../zixiken/dimdoors/items/ItemDimDoor.java   |   2 +
 .../dimdoors/items/ItemDimDoorGold.java       |   2 +
 .../dimdoors/items/ItemDimDoorPersonal.java   |   2 +
 .../dimdoors/items/ItemDimDoorUnstable.java   |   3 +-
 .../dimdoors/items/ItemDimDoorWarp.java       |   2 +
 .../zixiken/dimdoors/items/ItemDoorBase.java  |  10 +-
 .../dimdoors/items/ItemLinkSignature.java     |  38 ++++++
 .../zixiken/dimdoors/items/ItemRiftBlade.java | 112 ++++++++++++++++++
 .../dimdoors/items/ItemRiftRemover.java       |   4 +
 .../dimdoors/items/ItemStablizedRiftSig.java  |   4 +
 .../models/item/itemLinkSignature.json        |   6 +
 .../dimdoors/models/item/itemRiftRemover.json |   6 +
 .../models/item/itemStabilizedRiftSig.json    |   6 +
 14 files changed, 200 insertions(+), 10 deletions(-)
 create mode 100644 src/main/java/com/zixiken/dimdoors/items/ItemLinkSignature.java
 create mode 100644 src/main/java/com/zixiken/dimdoors/items/ItemRiftRemover.java
 create mode 100644 src/main/java/com/zixiken/dimdoors/items/ItemStablizedRiftSig.java
 create mode 100644 src/main/resources/assets/dimdoors/models/item/itemLinkSignature.json
 create mode 100644 src/main/resources/assets/dimdoors/models/item/itemRiftRemover.json
 create mode 100644 src/main/resources/assets/dimdoors/models/item/itemStabilizedRiftSig.json

diff --git a/src/main/java/com/zixiken/dimdoors/DimDoors.java b/src/main/java/com/zixiken/dimdoors/DimDoors.java
index 11ce748d..e43c74ef 100644
--- a/src/main/java/com/zixiken/dimdoors/DimDoors.java
+++ b/src/main/java/com/zixiken/dimdoors/DimDoors.java
@@ -8,6 +8,7 @@ import net.minecraft.creativetab.CreativeTabs;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.item.Item;
 import net.minecraft.util.text.TextComponentString;
+import net.minecraft.util.text.translation.I18n;
 import net.minecraft.world.World;
 import net.minecraftforge.fml.common.FMLLog;
 import net.minecraftforge.fml.common.Mod;
@@ -16,6 +17,8 @@ import net.minecraftforge.fml.common.event.*;
 import net.minecraftforge.fml.relauncher.Side;
 import net.minecraftforge.fml.relauncher.SideOnly;
 
+import java.util.List;
+
 @Mod(modid = DimDoors.MODID, name = "Dimensional Doors", version = DimDoors.VERSION)
 public class DimDoors {
 
@@ -75,4 +78,14 @@ public class DimDoors {
     public static void log(Class classFiredFrom, String text) {
         FMLLog.info("[DimDoors] " + text + " (" + classFiredFrom.toString() + " )", 0);
     }
+
+    public static void translateAndAdd(String key, List<String> list) {
+        for (int i = 0; i < 10; i++) {
+            if(I18n.canTranslate(key+Integer.toString(i))) {
+                String line = I18n.translateToLocal(key + Integer.toString(i));
+                list.add(line);
+            } else
+                break;
+        }
+    }
 }
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoor.java b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoor.java
index ebb8696a..37e06feb 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoor.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoor.java
@@ -9,6 +9,8 @@ import net.minecraft.init.Items;
 import net.minecraft.item.ItemDoor;
 import net.minecraft.item.ItemStack;
 
+import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
+
 public class ItemDimDoor extends ItemDoorBase {
 
     public static final String ID = "itemDimDoor";
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorGold.java b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorGold.java
index 5db185b2..7643e5d6 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorGold.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorGold.java
@@ -7,6 +7,8 @@ import com.zixiken.dimdoors.blocks.ModBlocks;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.item.ItemStack;
 
+import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
+
 public class ItemDimDoorGold extends ItemDoorBase {
 
     public static final String ID = "itemDimDoorGold";
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorPersonal.java b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorPersonal.java
index 3e420703..e3445213 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorPersonal.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorPersonal.java
@@ -7,6 +7,8 @@ import com.zixiken.dimdoors.blocks.ModBlocks;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.item.ItemStack;
 
+import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
+
 public class ItemDimDoorPersonal extends ItemDoorBase {
 
     public static final String ID = "itemDimDoorQuartz";
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorUnstable.java b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorUnstable.java
index 635c8d4b..2faf2282 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorUnstable.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorUnstable.java
@@ -6,6 +6,7 @@ import com.zixiken.dimdoors.blocks.BlockDimDoorBase;
 import com.zixiken.dimdoors.blocks.ModBlocks;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.item.ItemStack;
+import net.minecraft.util.text.translation.I18n;
 
 public class ItemDimDoorUnstable extends ItemDoorBase {
 
@@ -19,7 +20,7 @@ public class ItemDimDoorUnstable extends ItemDoorBase {
 
     @Override
     public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
-        //tooltip.add(StatCollector.translateToLocal("info.chaosDoor"));
+        tooltip.add(I18n.translateToLocal("info.chaosDoor"));
     }
 
     @Override
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorWarp.java b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorWarp.java
index 68e26539..413097c4 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorWarp.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDimDoorWarp.java
@@ -10,6 +10,8 @@ import net.minecraft.init.Items;
 import net.minecraft.item.ItemDoor;
 import net.minecraft.item.ItemStack;
 
+import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
+
 public class ItemDimDoorWarp extends ItemDoorBase {
 
     public static final String ID = "itemDimDoorWarp";
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java
index 02190d00..523c7847 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java
@@ -21,6 +21,7 @@ import net.minecraft.util.math.BlockPos;
 import net.minecraft.util.math.MathHelper;
 import net.minecraft.util.math.RayTraceResult;
 import net.minecraft.util.math.Vec3d;
+import net.minecraft.util.text.translation.I18n;
 import net.minecraft.world.World;
 import net.minecraft.block.SoundType;
 import static net.minecraft.item.ItemDoor.placeDoor;
@@ -170,13 +171,4 @@ public abstract class ItemDoorBase extends ItemDoor {
         Vec3d vec31 = vec3.addVector((double) f6 * d3, (double) f5 * d3, (double) f7 * d3);
         return world.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false);
     }
-
-    public void translateAndAdd(String key, List<String> list) {
-        for (int i = 0; i < 10; i++) {
-            /*if(StatCollector.canTranslate(key+Integer.toString(i))) {
-				String line = StatCollector.translateToLocal(key + Integer.toString(i));
-				list.add(line);
-			} else */ break;
-        }
-    }
 }
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemLinkSignature.java b/src/main/java/com/zixiken/dimdoors/items/ItemLinkSignature.java
new file mode 100644
index 00000000..dc34f6b3
--- /dev/null
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemLinkSignature.java
@@ -0,0 +1,38 @@
+package com.zixiken.dimdoors.items;
+
+import com.flowpowered.math.vector.Vector3d;
+import com.zixiken.dimdoors.DimDoors;
+import com.zixiken.dimdoors.blocks.ModBlocks;
+import com.zixiken.dimdoors.tileentities.TileEntityRift;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.*;
+import net.minecraft.util.math.*;
+import net.minecraft.world.World;
+import net.minecraftforge.fml.relauncher.Side;
+import net.minecraftforge.fml.relauncher.SideOnly;
+
+import java.util.List;
+
+import static com.zixiken.dimdoors.DimDoors.translateAndAdd;
+
+public class ItemLinkSignature extends Item {
+    public static final String ID = "itemLinkSignature";
+
+    public ItemLinkSignature() {
+        super();
+        setCreativeTab(DimDoors.dimDoorsCreativeTab);
+        setUnlocalizedName(ID);
+        setRegistryName(ID);
+    }
+
+    @Override
+    public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean advanced) {
+        translateAndAdd("info.riftSignature.unbound", list);
+    }
+}
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java b/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java
index 614514b9..890fb05a 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java
@@ -1,7 +1,24 @@
 package com.zixiken.dimdoors.items;
 
 import com.zixiken.dimdoors.DimDoors;
+import com.zixiken.dimdoors.blocks.ModBlocks;
+import com.zixiken.dimdoors.tileentities.TileEntityRift;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
 import net.minecraft.item.ItemSword;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ActionResult;
+import net.minecraft.util.EnumActionResult;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.util.EnumHand;
+import net.minecraft.util.math.*;
+import net.minecraft.world.World;
+import net.minecraftforge.fml.relauncher.Side;
+import net.minecraftforge.fml.relauncher.SideOnly;
+
+import java.util.List;
 
 /**
  * Created by Jared Johnson on 1/20/2017.
@@ -15,4 +32,99 @@ public class ItemRiftBlade extends ItemSword {
         setUnlocalizedName(ID);
         setRegistryName(ID);
     }
+
+    @Override
+    @SideOnly(Side.CLIENT)
+    public boolean hasEffect(ItemStack par1ItemStack) {
+        return true;
+    }
+
+    private boolean teleportToEntity(ItemStack item, Entity par1Entity, EntityPlayer holder) {
+        Vec3d var2 = new Vec3d(holder.posX - par1Entity.posX, holder.getEntityBoundingBox().minY + holder.height / 2.0F - par1Entity.posY + par1Entity.getEyeHeight(), holder.posZ - par1Entity.posZ);
+
+        double cooef =( var2.lengthVector()-2.5)/var2.lengthVector();
+        var2.scale(cooef);
+        double var5 = holder.posX  - var2.xCoord;
+        double var9 = holder.posZ - var2.zCoord;
+
+
+        double var7 = MathHelper.floor(holder.posY  - var2.yCoord) ;
+
+        int var14 = MathHelper.floor(var5);
+        int var15 = MathHelper.floor(var7);
+        int var16 = MathHelper.floor(var9);
+        while(!holder.world.isAirBlock(new BlockPos(var14, var15, var16))) {
+            var15++;
+        }
+
+        var7=var15;
+
+
+        holder.setPositionAndUpdate(var5, var7, var9);
+
+        return true;
+    }
+
+    @Override
+    public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
+        if (!world.isRemote) {
+            @SuppressWarnings("unchecked")
+            List<EntityLiving> list =  world.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(player.posX-10,player.posY-10, player.posZ-10, player.posX+10,player.posY+10, player.posZ+10));
+            list.remove(player);
+
+            for (EntityLiving ent : list) {
+                Vec3d var3 = player.getLook(1.0F).normalize();
+                Vec3d var4 =  new Vec3d(ent.posX -  player.posX, ent.getEntityBoundingBox().minY + (ent.height) / 2.0F - ( player.posY + player.getEyeHeight()), ent.posZ -  player.posZ);
+                double var5 = var4.lengthVector();
+                var4 = var4.normalize();
+                double var7 = var3.dotProduct(var4);
+
+                if( (var7+.1) > 1.0D - 0.025D / var5 ?  player.canEntityBeSeen(ent) : false) {
+                    teleportToEntity(stack, ent, player);
+                    stack.damageItem(3, player);
+                    return ActionResult.newResult(EnumActionResult.PASS, stack);
+                }
+            }
+
+            RayTraceResult hit = this.rayTrace(world, player, false);
+            if (hit != null) {
+                BlockPos pos = hit.getBlockPos();
+
+                TileEntity tile = world.getTileEntity(pos);
+
+                if (tile != null && tile instanceof TileEntityRift) {
+                    if (((TileEntityRift) tile).isPaired()) {
+                        if (player.canPlayerEdit(pos, hit.sideHit, stack) && player.canPlayerEdit(pos.offset(EnumFacing.UP), hit.sideHit, stack))
+                        {
+                            EnumFacing orientation = EnumFacing.fromAngle(player.rotationYaw).getOpposite();
+
+                            if (ItemDoorBase.canPlace(world, pos) && ItemDoorBase.canPlace(world, pos.offset(EnumFacing.DOWN))) {
+                                ItemDimDoor.placeDoor(world, pos.offset(EnumFacing.DOWN), orientation, ModBlocks.blockDimDoorTransient, true);
+                                stack.damageItem(3, player);
+                                return ActionResult.newResult(EnumActionResult.PASS, stack);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return ActionResult.newResult(EnumActionResult.PASS, stack);
+    }
+
+
+    /**
+     * Return whether this item is repairable in an anvil.
+     */
+    @Override
+    public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
+    {
+        //Don't include a call to super.getIsRepairable()!
+        //That would cause this sword to accept diamonds as a repair material (since we set material = Diamond).
+        return ModItems.itemStableFabric == par2ItemStack.getItem() ? true : false;
+    }
+
+    @Override
+    public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean advanced) {
+        DimDoors.translateAndAdd("info.riftblade", list);
+    }
 }
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemRiftRemover.java b/src/main/java/com/zixiken/dimdoors/items/ItemRiftRemover.java
new file mode 100644
index 00000000..92e376ff
--- /dev/null
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemRiftRemover.java
@@ -0,0 +1,4 @@
+package com.zixiken.dimdoors.items;
+
+public class ItemRiftRemover {
+}
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemStablizedRiftSig.java b/src/main/java/com/zixiken/dimdoors/items/ItemStablizedRiftSig.java
new file mode 100644
index 00000000..9f12ef9b
--- /dev/null
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemStablizedRiftSig.java
@@ -0,0 +1,4 @@
+package com.zixiken.dimdoors.items;
+
+public class ItemStablizedRiftSig {
+}
diff --git a/src/main/resources/assets/dimdoors/models/item/itemLinkSignature.json b/src/main/resources/assets/dimdoors/models/item/itemLinkSignature.json
new file mode 100644
index 00000000..7eecb983
--- /dev/null
+++ b/src/main/resources/assets/dimdoors/models/item/itemLinkSignature.json
@@ -0,0 +1,6 @@
+{
+  "parent": "item/handheld",
+  "textures": {
+    "layer0": "dimdoors:items/itemLinkSignature"
+  }
+}
diff --git a/src/main/resources/assets/dimdoors/models/item/itemRiftRemover.json b/src/main/resources/assets/dimdoors/models/item/itemRiftRemover.json
new file mode 100644
index 00000000..1138dbc2
--- /dev/null
+++ b/src/main/resources/assets/dimdoors/models/item/itemRiftRemover.json
@@ -0,0 +1,6 @@
+{
+  "parent": "item/handheld",
+  "textures": {
+    "layer0": "dimdoors:items/itemRiftRemover"
+  }
+}
diff --git a/src/main/resources/assets/dimdoors/models/item/itemStabilizedRiftSig.json b/src/main/resources/assets/dimdoors/models/item/itemStabilizedRiftSig.json
new file mode 100644
index 00000000..6335baf4
--- /dev/null
+++ b/src/main/resources/assets/dimdoors/models/item/itemStabilizedRiftSig.json
@@ -0,0 +1,6 @@
+{
+  "parent": "item/handheld",
+  "textures": {
+    "layer0": "dimdoors:items/itemStablizedRiftSig"
+  }
+}

From 7554e3fc62ce885601dac5f5f85005974206c8fc Mon Sep 17 00:00:00 2001
From: Waterpicker <Waterpickerenternity@gmail.com>
Date: Sun, 22 Jan 2017 06:54:55 -0600
Subject: [PATCH 3/4] Rift Blade sorta works

---
 .../zixiken/dimdoors/items/ItemDoorBase.java  |  32 +----
 .../zixiken/dimdoors/items/ItemRiftBlade.java | 126 ++++++------------
 .../items/ItemRiftConnectionTool.java         |   2 +-
 .../dimdoors/shared/RayTraceHelper.java       |  21 +++
 4 files changed, 68 insertions(+), 113 deletions(-)
 create mode 100644 src/main/java/com/zixiken/dimdoors/shared/RayTraceHelper.java

diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java
index 523c7847..bda3db9f 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemDoorBase.java
@@ -14,6 +14,7 @@ import net.minecraft.block.state.IBlockState;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
 import net.minecraft.item.ItemDoor;
 import net.minecraft.item.ItemStack;
 import net.minecraft.util.*;
@@ -66,7 +67,7 @@ public abstract class ItemDoorBase extends ItemDoor {
         if (worldIn.isRemote) {
             return new ActionResult(EnumActionResult.FAIL, stack);
         }
-        RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
+        RayTraceResult hit = rayTrace(worldIn, playerIn, true);
         if (hit != null) {
             BlockPos pos = hit.getBlockPos();
             if (worldIn.getBlockState(pos).getBlock() == ModBlocks.blockRift) {
@@ -142,33 +143,4 @@ public abstract class ItemDoorBase extends ItemDoor {
 
         return (state.getBlock() == ModBlocks.blockRift || state.equals(Blocks.AIR) || state.getMaterial().isReplaceable());
     }
-
-    /**
-     * Copied from minecraft Item.class TODO we probably can improve this
-     *
-     * @param world
-     * @param player
-     * @param useLiquids
-     * @return
-     */
-    protected static RayTraceResult doRayTrace(World world, EntityPlayer player, boolean useLiquids) {
-        float f = player.rotationPitch;
-        float f1 = player.rotationYaw;
-        double d0 = player.posX;
-        double d1 = player.posY + (double) player.getEyeHeight();
-        double d2 = player.posZ;
-        Vec3d vec3 = new Vec3d(d0, d1, d2);
-        float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI);
-        float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI);
-        float f4 = -MathHelper.cos(-f * 0.017453292F);
-        float f5 = MathHelper.sin(-f * 0.017453292F);
-        float f6 = f3 * f4;
-        float f7 = f2 * f4;
-        double d3 = 5.0D;
-        if (player instanceof EntityPlayerMP) {
-            d3 = ((EntityPlayerMP) player).interactionManager.getBlockReachDistance();
-        }
-        Vec3d vec31 = vec3.addVector((double) f6 * d3, (double) f5 * d3, (double) f7 * d3);
-        return world.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false);
-    }
 }
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java b/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java
index 890fb05a..b3b6eeb1 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemRiftBlade.java
@@ -1,14 +1,21 @@
 package com.zixiken.dimdoors.items;
 
 import com.zixiken.dimdoors.DimDoors;
+import com.zixiken.dimdoors.blocks.BlockDimDoor;
+import com.zixiken.dimdoors.blocks.BlockDimDoorTransient;
 import com.zixiken.dimdoors.blocks.ModBlocks;
+import com.zixiken.dimdoors.shared.Location;
+import com.zixiken.dimdoors.shared.RayTraceHelper;
+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 com.zixiken.dimdoors.tileentities.TileEntityRift;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityLiving;
+import net.minecraft.block.BlockDoor;
+import net.minecraft.block.state.IBlockState;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.item.ItemStack;
 import net.minecraft.item.ItemSword;
-import net.minecraft.tileentity.TileEntity;
 import net.minecraft.util.ActionResult;
 import net.minecraft.util.EnumActionResult;
 import net.minecraft.util.EnumFacing;
@@ -27,7 +34,7 @@ public class ItemRiftBlade extends ItemSword {
     public static final String ID = "itemRiftBlade";
 
     public ItemRiftBlade() {
-        super(ToolMaterial.IRON);
+        super(ToolMaterial.DIAMOND);
         setCreativeTab(DimDoors.dimDoorsCreativeTab);
         setUnlocalizedName(ID);
         setRegistryName(ID);
@@ -39,88 +46,43 @@ public class ItemRiftBlade extends ItemSword {
         return true;
     }
 
-    private boolean teleportToEntity(ItemStack item, Entity par1Entity, EntityPlayer holder) {
-        Vec3d var2 = new Vec3d(holder.posX - par1Entity.posX, holder.getEntityBoundingBox().minY + holder.height / 2.0F - par1Entity.posY + par1Entity.getEyeHeight(), holder.posZ - par1Entity.posZ);
-
-        double cooef =( var2.lengthVector()-2.5)/var2.lengthVector();
-        var2.scale(cooef);
-        double var5 = holder.posX  - var2.xCoord;
-        double var9 = holder.posZ - var2.zCoord;
-
-
-        double var7 = MathHelper.floor(holder.posY  - var2.yCoord) ;
-
-        int var14 = MathHelper.floor(var5);
-        int var15 = MathHelper.floor(var7);
-        int var16 = MathHelper.floor(var9);
-        while(!holder.world.isAirBlock(new BlockPos(var14, var15, var16))) {
-            var15++;
-        }
-
-        var7=var15;
-
-
-        holder.setPositionAndUpdate(var5, var7, var9);
-
-        return true;
-    }
-
-    @Override
-    public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
-        if (!world.isRemote) {
-            @SuppressWarnings("unchecked")
-            List<EntityLiving> list =  world.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(player.posX-10,player.posY-10, player.posZ-10, player.posX+10,player.posY+10, player.posZ+10));
-            list.remove(player);
-
-            for (EntityLiving ent : list) {
-                Vec3d var3 = player.getLook(1.0F).normalize();
-                Vec3d var4 =  new Vec3d(ent.posX -  player.posX, ent.getEntityBoundingBox().minY + (ent.height) / 2.0F - ( player.posY + player.getEyeHeight()), ent.posZ -  player.posZ);
-                double var5 = var4.lengthVector();
-                var4 = var4.normalize();
-                double var7 = var3.dotProduct(var4);
-
-                if( (var7+.1) > 1.0D - 0.025D / var5 ?  player.canEntityBeSeen(ent) : false) {
-                    teleportToEntity(stack, ent, player);
-                    stack.damageItem(3, player);
-                    return ActionResult.newResult(EnumActionResult.PASS, stack);
-                }
-            }
-
-            RayTraceResult hit = this.rayTrace(world, player, false);
-            if (hit != null) {
-                BlockPos pos = hit.getBlockPos();
-
-                TileEntity tile = world.getTileEntity(pos);
-
-                if (tile != null && tile instanceof TileEntityRift) {
-                    if (((TileEntityRift) tile).isPaired()) {
-                        if (player.canPlayerEdit(pos, hit.sideHit, stack) && player.canPlayerEdit(pos.offset(EnumFacing.UP), hit.sideHit, stack))
-                        {
-                            EnumFacing orientation = EnumFacing.fromAngle(player.rotationYaw).getOpposite();
-
-                            if (ItemDoorBase.canPlace(world, pos) && ItemDoorBase.canPlace(world, pos.offset(EnumFacing.DOWN))) {
-                                ItemDimDoor.placeDoor(world, pos.offset(EnumFacing.DOWN), orientation, ModBlocks.blockDimDoorTransient, true);
-                                stack.damageItem(3, player);
-                                return ActionResult.newResult(EnumActionResult.PASS, stack);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return ActionResult.newResult(EnumActionResult.PASS, stack);
-    }
-
-
     /**
      * Return whether this item is repairable in an anvil.
      */
     @Override
-    public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
-    {
-        //Don't include a call to super.getIsRepairable()!
-        //That would cause this sword to accept diamonds as a repair material (since we set material = Diamond).
-        return ModItems.itemStableFabric == par2ItemStack.getItem() ? true : false;
+    public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
+        return ModItems.itemStableFabric == repair.getItem();
+    }
+
+    @Override
+    public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
+        RayTraceResult hit = rayTrace(world, player, true);
+        if (RayTraceHelper.isRift(hit, world)) {
+            TileEntityRift rift = (TileEntityRift) world.getTileEntity(hit.getBlockPos());
+
+            ItemDoorBase.placeDoor(world, hit.getBlockPos().down(2), EnumFacing.fromAngle((double) player.rotationYaw), ModBlocks.blockDimDoorTransient, false);
+
+            DDTileEntityBase newTileEntityDimDoor = (DDTileEntityBase) world.getTileEntity(hit.getBlockPos());
+            if (rift instanceof DDTileEntityBase) { //
+                DDTileEntityBase oldRift = (DDTileEntityBase) rift;
+                newTileEntityDimDoor.loadDataFrom(oldRift);
+            } else {
+                newTileEntityDimDoor.register();
+            }
+            if (newTileEntityDimDoor instanceof TileEntityDimDoor) {
+                TileEntityDimDoor tileEntityDimDoor = (TileEntityDimDoor) newTileEntityDimDoor;
+                tileEntityDimDoor.orientation
+                        = newTileEntityDimDoor.getWorld().getBlockState(newTileEntityDimDoor.getPos()).getValue(BlockDimDoor.FACING).getOpposite();
+                //storing the orientation inside the tile-entity, because that thing can actually save the orientation in the worldsave, unlike the block itself, which fucks up somehow
+            }
+
+            return  new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
+        } if(RayTraceHelper.isLivingEntity(hit)) {
+            TeleportHelper.teleport(player, new Location(world, hit.getBlockPos()));
+            return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
+        }
+
+        return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
     }
 
     @Override
diff --git a/src/main/java/com/zixiken/dimdoors/items/ItemRiftConnectionTool.java b/src/main/java/com/zixiken/dimdoors/items/ItemRiftConnectionTool.java
index 3c584de3..82563a24 100644
--- a/src/main/java/com/zixiken/dimdoors/items/ItemRiftConnectionTool.java
+++ b/src/main/java/com/zixiken/dimdoors/items/ItemRiftConnectionTool.java
@@ -49,7 +49,7 @@ public class ItemRiftConnectionTool extends ItemTool {
             stack.setTagCompound(compound);
         }
 
-        RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
+        RayTraceResult hit = rayTrace(worldIn, playerIn, true);
         if (hit != null && worldIn.getTileEntity(hit.getBlockPos()) instanceof DDTileEntityBase) {
             DDTileEntityBase rift = (DDTileEntityBase) worldIn.getTileEntity(hit.getBlockPos());
             if (playerIn.isSneaking()) {
diff --git a/src/main/java/com/zixiken/dimdoors/shared/RayTraceHelper.java b/src/main/java/com/zixiken/dimdoors/shared/RayTraceHelper.java
new file mode 100644
index 00000000..4190b5a7
--- /dev/null
+++ b/src/main/java/com/zixiken/dimdoors/shared/RayTraceHelper.java
@@ -0,0 +1,21 @@
+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;
+import net.minecraft.world.World;
+
+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 isLivingEntity(RayTraceResult hit) {
+        return isNotNull(hit) && hit.typeOfHit == RayTraceResult.Type.ENTITY && hit.entityHit instanceof EntityLivingBase;
+    }
+
+    private static boolean isNotNull(RayTraceResult hit) {
+        return hit != null;
+    }
+}

From 4ce32c98285dbfa69dd7fa14fc190fb8b55faad6 Mon Sep 17 00:00:00 2001
From: Waterpicker <Waterpickerenternity@gmail.com>
Date: Mon, 23 Jan 2017 19:58:42 -0600
Subject: [PATCH 4/4] Server and client are seperate.

---
 .../java/com/zixiken/dimdoors/DDProxyCommon.java    |  4 ----
 .../com/zixiken/dimdoors/client/DDProxyClient.java  | 13 +++++++++++++
 .../com/zixiken/dimdoors/shared/TeleportHelper.java |  2 +-
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zixiken/dimdoors/DDProxyCommon.java b/src/main/java/com/zixiken/dimdoors/DDProxyCommon.java
index 2714a980..a252ea6e 100644
--- a/src/main/java/com/zixiken/dimdoors/DDProxyCommon.java
+++ b/src/main/java/com/zixiken/dimdoors/DDProxyCommon.java
@@ -24,9 +24,6 @@ public abstract class DDProxyCommon implements IDDProxy {
         ModBlocks.registerBlocks();
         ModItems.registerItems();
 
-        ModelManager.registerModelVariants();
-        ModelManager.addCustomStateMappers();
-
         GameRegistry.registerTileEntity(TileEntityDimDoor.class, "TileEntityDimDoor");
         GameRegistry.registerTileEntity(TileEntityRift.class, "TileEntityRift");
         GameRegistry.registerTileEntity(TileEntityTransTrapdoor.class, "TileEntityDimHatch");
@@ -36,7 +33,6 @@ public abstract class DDProxyCommon implements IDDProxy {
     @Override
     public void onInitialization(FMLInitializationEvent event) {
         CraftingManager.registerRecipes();
-        ModelManager.registerModels();
     }
 
     public void updateDoorTE(BlockDimDoorBase door, World world, BlockPos pos) {
diff --git a/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java b/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java
index 91cdf4b0..010e9096 100644
--- a/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java
+++ b/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java
@@ -1,6 +1,8 @@
 package com.zixiken.dimdoors.client;
 
+import com.zixiken.dimdoors.CraftingManager;
 import com.zixiken.dimdoors.DDProxyCommon;
+import com.zixiken.dimdoors.ModelManager;
 import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
 import com.zixiken.dimdoors.tileentities.TileEntityRift;
 import com.zixiken.dimdoors.tileentities.TileEntityTransTrapdoor;
@@ -9,6 +11,7 @@ import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.world.World;
 import net.minecraft.world.WorldServer;
 import net.minecraftforge.fml.client.registry.ClientRegistry;
+import net.minecraftforge.fml.common.event.FMLInitializationEvent;
 import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
 
 @SuppressWarnings({"MethodCallSideOnly", "NewExpressionSideOnly"})
@@ -17,9 +20,19 @@ public class DDProxyClient extends DDProxyCommon {
     @Override
     public void onPreInitialization(FMLPreInitializationEvent event) {
         super.onPreInitialization(event);
+
+        ModelManager.registerModelVariants();
+        ModelManager.addCustomStateMappers();
+
         registerRenderers();
     }
 
+    @Override
+    public void onInitialization(FMLInitializationEvent event) {
+        super.onInitialization(event);
+        ModelManager.registerModels();
+    }
+
     public void registerRenderers() {
         ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDimDoor.class, new RenderDimDoor());
         ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTransTrapdoor.class, new RenderTransTrapdoor());
diff --git a/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java b/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java
index 9b816069..8d4925cd 100644
--- a/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java
+++ b/src/main/java/com/zixiken/dimdoors/shared/TeleportHelper.java
@@ -25,7 +25,7 @@ public class TeleportHelper extends Teleporter {
     }
 
     public static boolean teleport(Entity entity, Location newLocation) {
-        if (entity instanceof EntityPlayerSP) {
+        if (DimDoors.isClient()) {
             //DimDoors.log(TeleportHelper.class, "Not teleporting, because EntityPlayerSP.");
             return false;
         }