use of net.minecraft.block.state.pattern.BlockPattern.PatternHelper in project takumicraft by TNTModders.
the class TakumiTeleporter method placeInExistingPortal.
@Override
public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) {
int i = 128;
double d0 = -1.0D;
int j = MathHelper.floor(entityIn.posX);
int k = MathHelper.floor(entityIn.posZ);
boolean flag = true;
BlockPos blockpos = BlockPos.ORIGIN;
long l = ChunkPos.asLong(j, k);
if (this.destinationCoordinateCache.containsKey(l)) {
PortalPosition teleporter$portalposition = this.destinationCoordinateCache.get(l);
d0 = 0.0D;
blockpos = teleporter$portalposition;
teleporter$portalposition.lastUpdateTime = this.world.getTotalWorldTime();
flag = false;
} else {
BlockPos blockpos3 = new BlockPos(entityIn);
for (int i1 = -128; i1 <= 128; ++i1) {
BlockPos blockpos2;
for (int j1 = -128; j1 <= 128; ++j1) {
for (BlockPos blockpos1 = blockpos3.add(i1, this.world.getActualHeight() - 1 - blockpos3.getY(), j1); blockpos1.getY() >= 0; blockpos1 = blockpos2) {
blockpos2 = blockpos1.down();
if (this.world.getBlockState(blockpos1).getBlock() == TakumiBlockCore.TAKUMI_PORTAL) {
for (blockpos2 = blockpos1.down(); this.world.getBlockState(blockpos2).getBlock() == TakumiBlockCore.TAKUMI_PORTAL; blockpos2 = blockpos2.down()) {
blockpos1 = blockpos2;
}
double d1 = blockpos1.distanceSq(blockpos3);
if (d0 < 0.0D || d1 < d0) {
d0 = d1;
blockpos = blockpos1;
}
}
}
}
}
}
if (d0 >= 0.0D) {
if (flag) {
this.destinationCoordinateCache.put(l, new PortalPosition(blockpos, this.world.getTotalWorldTime()));
}
double d5 = (double) blockpos.getX() + 0.5D;
double d7 = (double) blockpos.getZ() + 0.5D;
PatternHelper blockpattern$patternhelper = TakumiBlockCore.TAKUMI_PORTAL.createPatternHelper(this.world, blockpos);
boolean flag1 = blockpattern$patternhelper.getForwards().rotateY().getAxisDirection() == AxisDirection.NEGATIVE;
double d2 = blockpattern$patternhelper.getForwards().getAxis() == Axis.X ? (double) blockpattern$patternhelper.getFrontTopLeft().getZ() : (double) blockpattern$patternhelper.getFrontTopLeft().getX();
double d6 = (double) (blockpattern$patternhelper.getFrontTopLeft().getY() + 1) - entityIn.getLastPortalVec().y * (double) blockpattern$patternhelper.getHeight();
if (flag1) {
++d2;
}
if (blockpattern$patternhelper.getForwards().getAxis() == Axis.X) {
d7 = d2 + (1.0D - entityIn.getLastPortalVec().x) * (double) blockpattern$patternhelper.getWidth() * (double) blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
d5 += this.world.rand.nextBoolean() ? 1.25 : -1.25;
} else {
d5 = d2 + (1.0D - entityIn.getLastPortalVec().x) * (double) blockpattern$patternhelper.getWidth() * (double) blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
d7 += this.world.rand.nextBoolean() ? 1.25 : -1.25;
}
float f = 0.0F;
float f1 = 0.0F;
float f2 = 0.0F;
float f3 = 0.0F;
if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection()) {
f = 1.0F;
f1 = 1.0F;
} else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection().getOpposite()) {
f = -1.0F;
f1 = -1.0F;
} else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection().rotateY()) {
f2 = 1.0F;
f3 = -1.0F;
} else {
f2 = -1.0F;
f3 = 1.0F;
}
double d3 = entityIn.motionX;
double d4 = entityIn.motionZ;
entityIn.motionX = d3 * (double) f + d4 * (double) f3;
entityIn.motionZ = d3 * (double) f2 + d4 * (double) f1;
entityIn.rotationYaw = rotationYaw - (float) (entityIn.getTeleportDirection().getOpposite().getHorizontalIndex() * 90) + (float) (blockpattern$patternhelper.getForwards().getHorizontalIndex() * 90);
if (entityIn instanceof EntityPlayerMP) {
BlockPos pos = new BlockPos(d5, d6, d7);
world.setBlockToAir(pos);
world.setBlockToAir(pos.up());
((EntityPlayerMP) entityIn).connection.setPlayerLocation(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch);
} else {
entityIn.setLocationAndAngles(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch);
}
return true;
}
return false;
}
Aggregations