Search in sources :

Example 96 with Box

use of net.minecraft.util.math.Box in project roadrunner by MaxNeedsSnacks.

the class TestOptimizedVoxelShapeMatchesAnywhere method getRandomTestWithComplexShape.

private static VoxelShapeVoxelShapePair getRandomTestWithComplexShape(Random random) {
    VoxelShape complexShape = Util.getRandom(TESTED_COMPLEX_SHAPES, random);
    if (random.nextInt(8) > 1) {
        complexShape = complexShape.offset(getFuzzy(random.nextInt(5) - 2, random, 0, 0.25f, 0.5f, 0f), getFuzzy(random.nextInt(5) - 2, random, 0, 0.25f, 0.5f, 0f), getFuzzy(random.nextInt(5) - 2, random, 0, 0.25f, 0.5f, 0f));
    }
    double x = 0.5D * (complexShape.getMin(Direction.Axis.X) + complexShape.getMax(Direction.Axis.X));
    double y = 0.5D * (complexShape.getMin(Direction.Axis.Y) + complexShape.getMax(Direction.Axis.Y));
    double z = 0.5D * (complexShape.getMin(Direction.Axis.Z) + complexShape.getMax(Direction.Axis.Z));
    double xRadius = 0.5D * (complexShape.getMax(Direction.Axis.X) - complexShape.getMin(Direction.Axis.X));
    double yRadius = 0.5D * (complexShape.getMax(Direction.Axis.Y) - complexShape.getMin(Direction.Axis.Y));
    double zRadius = 0.5D * (complexShape.getMax(Direction.Axis.Z) - complexShape.getMin(Direction.Axis.Z));
    double xRadius2 = random.nextInt(3) + random.nextDouble() - 0.01;
    double yRadius2 = random.nextInt(3) + random.nextDouble() - 0.01;
    double zRadius2 = random.nextInt(3) + random.nextDouble() - 0.01;
    Direction touchSide = Direction.random(random);
    if (random.nextInt(8) > 0) {
        x += touchSide.getOffsetX() * (xRadius + xRadius2);
        y += touchSide.getOffsetY() * (yRadius + yRadius2);
        z += touchSide.getOffsetZ() * (zRadius + zRadius2);
    }
    x = getFuzzy(x, random, xRadius + xRadius2, 0.25f, 0.25f, 0.25f);
    y = getFuzzy(y, random, yRadius + yRadius2, 0.25f, 0.25f, 0.25f);
    z = getFuzzy(z, random, zRadius + zRadius2, 0.25f, 0.25f, 0.25f);
    Box b = new Box(x - xRadius2, y - yRadius2, z - zRadius2, x + xRadius2, y + yRadius2, z + zRadius2);
    BooleanBiFunction function = Util.getRandom(FUNCTIONS, random);
    if (random.nextBoolean()) {
        return new VoxelShapeVoxelShapePair(complexShape, cuboid(b), function);
    }
    return new VoxelShapeVoxelShapePair(cuboid(b), complexShape, function);
}
Also used : VoxelShape(net.minecraft.util.shape.VoxelShape) BooleanBiFunction(net.minecraft.util.function.BooleanBiFunction) Box(net.minecraft.util.math.Box) Direction(net.minecraft.util.math.Direction) AxisCycleDirection(net.minecraft.util.math.AxisCycleDirection)

Example 97 with Box

use of net.minecraft.util.math.Box in project roadrunner by MaxNeedsSnacks.

the class TestCustomVoxelShapesCollisions method testShapeBehaviorEquality.

public void testShapeBehaviorEquality(VoxelShape[] pair) {
    for (Direction.Axis axis : AXES) {
        for (double maxDist : distances) {
            for (Box box : boxes) {
                double resultVanilla = pair[0].calculateMaxDistance(axis, box, maxDist);
                double resultModded = pair[1].calculateMaxDistance(axis, box, maxDist);
                int collided = 0;
                if (resultVanilla == maxDist) {
                    noCollision++;
                } else {
                    collision++;
                    collided = 1;
                }
                if (pair[0].getBoundingBox().intersects(box)) {
                    intersects++;
                    intersectsCollision += collided;
                }
                if (pair[1] instanceof VoxelShapeAlignedCuboid) {
                    withCollisionBoxesInside++;
                }
                if (resultModded != resultVanilla) {
                    // }
                    throw new IllegalStateException(String.format("RNG seed: %s, different results for: %s, %s in calculateMaxDistance with arguments axis: %s, box: %s, maxDist: %s, result vanilla: %s, result modded: %s", randomSeed, pair[0], pair[1], axis, box, maxDist, resultVanilla, resultModded));
                }
            }
        }
    }
}
Also used : VoxelShapeAlignedCuboid(me.jellysquid.mods.lithium.common.shapes.VoxelShapeAlignedCuboid) Box(net.minecraft.util.math.Box) Direction(net.minecraft.util.math.Direction)

Example 98 with Box

use of net.minecraft.util.math.Box in project roadrunner by MaxNeedsSnacks.

the class TestCustomVoxelShapesCollisions method testCollisions.

// @Test
public void testCollisions() {
    this.noCollision = 0;
    this.collision = 0;
    this.intersects = 0;
    this.intersectsCollision = 0;
    this.withCollisionBoxesInside = 0;
    this.rand = new Random();
    // insert your seed here for debugging when the test failed and printed its seed
    long seed = this.rand.nextLong();
    this.rand.setSeed(seed);
    this.randomSeed = seed;
    this.boxes = new Box[20];
    this.boxes[0] = new Box(0.2931994021407849, 0.5175531777466607, 0.14575020167685837, 1.4562191976519117, 2.2389429614133496, 0.31827209851790766);
    this.boxes[1] = new Box(0.5 - 0.5E-7, 0.75, 0.125 + 1E-7, 1, 1 + 1E-6, 0.5);
    for (int i = 2; i < 20; i++) {
        this.boxes[i] = getRandomBox(this.rand);
    }
    Random rand = this.rand;
    this.distances = new double[] { 2.814955055053852, 5 * rand.nextDouble(), -5 * rand.nextDouble(), 5 * rand.nextDouble(), -5 * rand.nextDouble(), 1E-7, 1.1E-7, 0.9E-7, -1E-7, -1.1E-7, -0.9E-7, 1, 10, -1, -10, 0.1, -0.1, 0.25, -0.25, 0.33, -0.33, 1 - 1E-7, -1 + 1E-7, 5 * rand.nextDouble(), -5 * rand.nextDouble(), 5 * rand.nextDouble(), -5 * rand.nextDouble() };
    // test all of the 1/8th of a block aligned shapes
    for (int x = 0; x <= 7; x++) {
        for (int x2 = x + 1; x2 <= 8; x2++) {
            for (int y = 0; y <= 7; y++) {
                for (int y2 = y + 1; y2 <= 8; y2++) {
                    for (int z = 0; z <= 7; z++) {
                        for (int z2 = z + 1; z2 <= 8; z2++) {
                            VoxelShape[] pair = getVanillaModdedVoxelShapePair(new Box(x / 8D, y / 8D, z / 8D, x2 / 8D, y2 / 8D, z2 / 8D));
                            this.testShapeBehaviorEquality(pair);
                            // test random offsetting to test VoxelShapeAlignedCuboid_Offset
                            double xOff = 5 * rand.nextGaussian();
                            double yOff = 4 * rand.nextDouble();
                            double zOff = rand.nextDouble();
                            pair[0] = pair[0].offset(xOff, yOff, zOff);
                            pair[1] = pair[1].offset(xOff, yOff, zOff);
                            this.testShapeBehaviorEquality(pair);
                            // test random EPSILON-sized deviations
                            pair = getVanillaModdedVoxelShapePair(new Box(x / 8D + 2E-7 * this.rand.nextDouble(), y / 8D + 4E-8, z / 8D, x2 / 8D, y2 / 8D + 9E-8, z2 / 8D));
                            this.testShapeBehaviorEquality(pair);
                        }
                    }
                }
            }
        }
    }
    // test some random shapes, just in case there is a really stupid mistake somewhere
    for (int i = 0; i < 2000; i++) {
        this.testShapeBehaviorEquality(getVanillaModdedVoxelShapePair(new Box(rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian(), rand.nextGaussian())));
    }
}
Also used : Random(java.util.Random) Box(net.minecraft.util.math.Box)

Example 99 with Box

use of net.minecraft.util.math.Box in project MCDoom by AzureDoom.

the class Chainsaw method inventoryTick.

@Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    LivingEntity user = (LivingEntity) entityIn;
    PlayerEntity player = (PlayerEntity) entityIn;
    if (player.getMainHandStack().isItemEqualIgnoreDamage(stack) && stack.getDamage() < (stack.getMaxDamage() - 1)) {
        final Box aabb = new Box(entityIn.getBlockPos().up()).expand(1D, 1D, 1D);
        entityIn.getEntityWorld().getOtherEntities(user, aabb).forEach(e -> doDamage(user, e));
        entityIn.getEntityWorld().getOtherEntities(user, aabb).forEach(e -> doDeathCheck(user, e, stack));
        entityIn.getEntityWorld().getOtherEntities(user, aabb).forEach(e -> damageItem(user, stack));
        entityIn.getEntityWorld().getOtherEntities(user, aabb).forEach(e -> addParticle(e));
    }
    if (isSelected && stack.getDamage() < (stack.getMaxDamage() - 1)) {
        worldIn.playSound((PlayerEntity) null, user.getX(), user.getY(), user.getZ(), ModSoundEvents.CHAINSAW_IDLE, SoundCategory.PLAYERS, 0.05F, 1.0F / (worldIn.random.nextFloat() * 0.4F + 1.2F) + 0.25F * 0.5F);
    }
    if (worldIn.isClient) {
        if (player.getMainHandStack().getItem() instanceof Chainsaw && ClientInit.reload.isPressed() && isSelected) {
            PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
            passedData.writeBoolean(true);
            ClientPlayNetworking.send(DoomMod.CHAINSAW, passedData);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PacketByteBuf(net.minecraft.network.PacketByteBuf) Box(net.minecraft.util.math.Box) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 100 with Box

use of net.minecraft.util.math.Box in project MCDoom by AzureDoom.

the class SentinelHammerItem method onStoppedUsing.

@Override
public void onStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int remainingUseTicks) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity playerentity = (PlayerEntity) entityLiving;
        if (stack.getDamage() < (stack.getMaxDamage() - 1)) {
            playerentity.getItemCooldownManager().set(this, 200);
            final Box aabb = new Box(entityLiving.getBlockPos().up()).expand(5D, 5D, 5D);
            entityLiving.getEntityWorld().getOtherEntities(entityLiving, aabb).forEach(e -> doDamage(entityLiving, e));
            stack.damage(1, entityLiving, p -> p.sendToolBreakStatus(entityLiving.getActiveHand()));
            AreaEffectCloudEntity areaeffectcloudentity = new AreaEffectCloudEntity(playerentity.world, playerentity.getX(), playerentity.getY(), playerentity.getZ());
            areaeffectcloudentity.setParticleType(ParticleTypes.CRIT);
            areaeffectcloudentity.setRadius(5.0F);
            areaeffectcloudentity.setDuration(20);
            areaeffectcloudentity.updatePosition(playerentity.getX(), playerentity.getY(), playerentity.getZ());
            worldIn.spawnEntity(areaeffectcloudentity);
            if (!worldIn.isClient) {
                final int id = GeckoLibUtil.guaranteeIDForStack(stack, (ServerWorld) worldIn);
                GeckoLibNetwork.syncAnimation(playerentity, this, id, ANIM_OPEN);
                for (PlayerEntity otherPlayer : PlayerLookup.tracking(playerentity)) {
                    GeckoLibNetwork.syncAnimation(otherPlayer, this, id, ANIM_OPEN);
                }
            }
        }
    }
}
Also used : AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) Box(net.minecraft.util.math.Box) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

Box (net.minecraft.util.math.Box)146 Vec3d (net.minecraft.util.math.Vec3d)54 LivingEntity (net.minecraft.entity.LivingEntity)47 PlayerEntity (net.minecraft.entity.player.PlayerEntity)42 BlockPos (net.minecraft.util.math.BlockPos)41 Entity (net.minecraft.entity.Entity)40 Direction (net.minecraft.util.math.Direction)18 PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)17 List (java.util.List)15 VoxelShape (net.minecraft.util.shape.VoxelShape)14 BlockState (net.minecraft.block.BlockState)12 ArrayList (java.util.ArrayList)11 Comparator (java.util.Comparator)11 ItemStack (net.minecraft.item.ItemStack)11 World (net.minecraft.world.World)11 Random (java.util.Random)10 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)10 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)10 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)10 DemonEntity (mod.azure.doom.entity.DemonEntity)9