Rift Blade sorta works

This commit is contained in:
Waterpicker 2017-01-22 06:54:55 -06:00
parent e027947fb0
commit 7554e3fc62
4 changed files with 68 additions and 113 deletions

View file

@ -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);
}
}

View file

@ -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

View file

@ -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()) {

View file

@ -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;
}
}