Search in sources :

Example 1 with BlockPattern

use of net.minecraft.block.state.pattern.BlockPattern in project SpongeCommon by SpongePowered.

the class MixinTeleporter method handleEntityPortalExit.

private void handleEntityPortalExit(Entity entityIn, Location<World> portalLocation, float rotationYaw) {
    BlockPos blockPos = ((IMixinLocation) (Object) portalLocation).getBlockPos();
    double xTarget = portalLocation.getX() + 0.5D;
    double yTarget = portalLocation.getY() + 0.5D;
    double zTarget = portalLocation.getZ() + 0.5D;
    BlockPattern.PatternHelper blockpattern$patternhelper = Blocks.PORTAL.createPatternHelper(this.world, blockPos);
    boolean flag1 = blockpattern$patternhelper.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE;
    double d2 = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X ? (double) blockpattern$patternhelper.getFrontTopLeft().getZ() : (double) blockpattern$patternhelper.getFrontTopLeft().getX();
    yTarget = blockpattern$patternhelper.getFrontTopLeft().getY() + 1 - entityIn.getLastPortalVec().y * blockpattern$patternhelper.getHeight();
    if (flag1) {
        ++d2;
    }
    if (blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X) {
        zTarget = d2 + (1.0D - entityIn.getLastPortalVec().x) * blockpattern$patternhelper.getWidth() * blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
    } else {
        xTarget = d2 + (1.0D - entityIn.getLastPortalVec().x) * blockpattern$patternhelper.getWidth() * blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
    }
    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 * f + d4 * f3;
    entityIn.motionZ = d3 * f2 + d4 * f1;
    entityIn.rotationYaw = rotationYaw - entityIn.getTeleportDirection().getOpposite().getHorizontalIndex() * 90 + blockpattern$patternhelper.getForwards().getHorizontalIndex() * 90;
    entityIn.setLocationAndAngles(xTarget, yTarget, zTarget, entityIn.rotationYaw, entityIn.rotationPitch);
}
Also used : IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) BlockPattern(net.minecraft.block.state.pattern.BlockPattern) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with BlockPattern

use of net.minecraft.block.state.pattern.BlockPattern in project Gaia-Dimension by Andromander.

the class TeleporterGaia method placeInExistingPortal.

@Override
public boolean placeInExistingPortal(Entity entity, float yaw) {
    double d0 = -1.0D;
    int j = MathHelper.floor(entity.posX);
    int k = MathHelper.floor(entity.posZ);
    boolean flag = true;
    BlockPos blockpos = BlockPos.ORIGIN;
    long l = ChunkPos.asLong(j, k);
    if (this.destinationCoordinateCache.containsKey(1)) {
        PortalPosition teleporter$portalposition = this.destinationCoordinateCache.get(1);
        d0 = 0.0D;
        blockpos = teleporter$portalposition;
        teleporter$portalposition.lastUpdateTime = this.world.getTotalWorldTime();
        flag = false;
    } else {
        BlockPos blockpos3 = new BlockPos(entity);
        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() == GDBlocks.gaiaPortal) {
                        while (this.world.getBlockState(blockpos2 = blockpos1.down()).getBlock() == GDBlocks.gaiaPortal) {
                            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(1, new PortalPosition(blockpos, this.world.getTotalWorldTime()));
        }
        BlockPattern.PatternHelper blockpattern$patternhelper = GDBlocks.gaiaPortal.createPatternHelper(this.world, blockpos);
        EnumFacing eTD = blockpattern$patternhelper.getForwards();
        float f = 0.0F;
        float f1 = 0.0F;
        float f2 = 0.0F;
        float f3 = 0.0F;
        if (blockpattern$patternhelper.getForwards().getOpposite() == eTD) {
            f = 1.0F;
            f1 = 1.0F;
        } else if (blockpattern$patternhelper.getForwards().getOpposite() == eTD.getOpposite()) {
            f = -1.0F;
            f1 = -1.0F;
        } else if (blockpattern$patternhelper.getForwards().getOpposite() == eTD.rotateY()) {
            f2 = 1.0F;
            f3 = -1.0F;
        } else {
            f2 = -1.0F;
            f3 = 1.0F;
        }
        double d3 = entity.motionX;
        double d4 = entity.motionZ;
        entity.motionX = d3 * (double) f + d4 * (double) f3;
        entity.motionZ = d3 * (double) f2 + d4 * (double) f1;
        entity.rotationYaw = yaw - (float) (eTD.getOpposite().getHorizontalIndex() * 90) + (float) (blockpattern$patternhelper.getForwards().getHorizontalIndex() * 90);
        if (entity instanceof EntityPlayerMP)
            ((EntityPlayerMP) entity).connection.setPlayerLocation(blockpos.getX() + 2.5D, blockpos.getY() + 0.5D, blockpos.getZ() + 2.5D, entity.rotationYaw, entity.rotationPitch);
        else
            entity.setLocationAndAngles(blockpos.getX() + 0.5D, blockpos.getY() + 0.5D, blockpos.getZ() + 0.5D, entity.rotationYaw, entity.rotationPitch);
        return true;
    } else {
        return false;
    }
}
Also used : BlockPattern(net.minecraft.block.state.pattern.BlockPattern) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 3 with BlockPattern

use of net.minecraft.block.state.pattern.BlockPattern in project Gaia-Dimension by Andromander.

the class GDGaiaPortal method createPatternHelper.

public BlockPattern.PatternHelper createPatternHelper(World worldIn, BlockPos pos) {
    EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.Z;
    GDGaiaPortal.Size blockportal$size = new GDGaiaPortal.Size(worldIn, pos, EnumFacing.Axis.X);
    LoadingCache<BlockPos, BlockWorldState> loadingcache = BlockPattern.createLoadingCache(worldIn, true);
    if (!blockportal$size.isValid()) {
        enumfacing$axis = EnumFacing.Axis.X;
        blockportal$size = new GDGaiaPortal.Size(worldIn, pos, EnumFacing.Axis.Z);
    }
    if (!blockportal$size.isValid()) {
        return new BlockPattern.PatternHelper(pos, EnumFacing.NORTH, EnumFacing.UP, loadingcache, 1, 1, 1);
    } else {
        int[] aint = new int[EnumFacing.AxisDirection.values().length];
        EnumFacing enumfacing = blockportal$size.rightDir.rotateYCCW();
        BlockPos blockpos = blockportal$size.bottomLeft.up(blockportal$size.getHeight() - 1);
        for (EnumFacing.AxisDirection enumfacing$axisdirection : EnumFacing.AxisDirection.values()) {
            BlockPattern.PatternHelper blockpattern$patternhelper = new BlockPattern.PatternHelper(enumfacing.getAxisDirection() == enumfacing$axisdirection ? blockpos : blockpos.offset(blockportal$size.rightDir, blockportal$size.getWidth() - 1), EnumFacing.getFacingFromAxis(enumfacing$axisdirection, enumfacing$axis), EnumFacing.UP, loadingcache, blockportal$size.getWidth(), blockportal$size.getHeight(), 1);
            for (int i = 0; i < blockportal$size.getWidth(); ++i) {
                for (int j = 0; j < blockportal$size.getHeight(); ++j) {
                    BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(i, j, 1);
                    if (blockworldstate.getBlockState() != null && blockworldstate.getBlockState().getMaterial() != Material.AIR) {
                        ++aint[enumfacing$axisdirection.ordinal()];
                    }
                }
            }
        }
        EnumFacing.AxisDirection enumfacing$axisdirection1 = EnumFacing.AxisDirection.POSITIVE;
        for (EnumFacing.AxisDirection enumfacing$axisdirection2 : EnumFacing.AxisDirection.values()) {
            if (aint[enumfacing$axisdirection2.ordinal()] < aint[enumfacing$axisdirection1.ordinal()]) {
                enumfacing$axisdirection1 = enumfacing$axisdirection2;
            }
        }
        return new BlockPattern.PatternHelper(enumfacing.getAxisDirection() == enumfacing$axisdirection1 ? blockpos : blockpos.offset(blockportal$size.rightDir, blockportal$size.getWidth() - 1), EnumFacing.getFacingFromAxis(enumfacing$axisdirection1, enumfacing$axis), EnumFacing.UP, loadingcache, blockportal$size.getWidth(), blockportal$size.getHeight(), 1);
    }
}
Also used : BlockPattern(net.minecraft.block.state.pattern.BlockPattern) BlockPos(net.minecraft.util.math.BlockPos) BlockWorldState(net.minecraft.block.state.BlockWorldState)

Example 4 with BlockPattern

use of net.minecraft.block.state.pattern.BlockPattern in project MorePlanets by SteveKunG.

the class ItemVeinEye method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    IBlockState iblockstate = world.getBlockState(pos);
    if (player.canPlayerEdit(pos.offset(facing), facing, itemStack) && iblockstate.getBlock() == NibiruBlocks.VEIN_FRAME && !iblockstate.getValue(BlockVeinFrame.EYE).booleanValue()) {
        if (world.isRemote) {
            for (int i = 0; i < 16; ++i) {
                double d0 = pos.getX() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F;
                double d1 = pos.getY() + 0.8125F;
                double d2 = pos.getZ() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F;
                world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
            }
            return EnumActionResult.SUCCESS;
        } else {
            world.setBlockState(pos, iblockstate.withProperty(BlockVeinFrame.EYE, Boolean.valueOf(true)), 2);
            world.updateComparatorOutputLevel(pos, NibiruBlocks.VEIN_FRAME);
            itemStack.shrink(1);
            BlockPattern.PatternHelper blockpattern$patternhelper = this.getOrCreatePortalShape().match(world, pos);
            if (blockpattern$patternhelper != null) {
                BlockPos blockpos = blockpattern$patternhelper.getFrontTopLeft().add(-3, 0, -3);
                for (int j = 0; j < 3; ++j) {
                    for (int k = 0; k < 3; ++k) {
                        world.setBlockState(blockpos.add(j, 0, k), NibiruBlocks.VEIN_PORTAL.getDefaultState(), 2);
                    }
                }
            }
            return EnumActionResult.SUCCESS;
        }
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FactoryBlockPattern(net.minecraft.block.state.pattern.FactoryBlockPattern) BlockPattern(net.minecraft.block.state.pattern.BlockPattern) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockPattern (net.minecraft.block.state.pattern.BlockPattern)4 BlockPos (net.minecraft.util.math.BlockPos)4 BlockWorldState (net.minecraft.block.state.BlockWorldState)1 IBlockState (net.minecraft.block.state.IBlockState)1 FactoryBlockPattern (net.minecraft.block.state.pattern.FactoryBlockPattern)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 IMixinLocation (org.spongepowered.common.interfaces.world.IMixinLocation)1