Search in sources :

Example 6 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project VoodooCraft by Mod-DevCafeTeam.

the class HexGreenFingers method activeUse.

@Override
public ItemStack activeUse(ItemStack stackIn, World world, EntityPlayer player, EnumHand hand, int strength, @Nullable EntityLivingBase target) {
    if (world.isRemote)
        return super.activeUse(stackIn, world, player, hand, strength, target);
    RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
    BlockPos pos = result.getBlockPos();
    Block block = world.getBlockState(pos).getBlock();
    if (block instanceof BlockCrops) {
        if (block instanceof BlockBeetroot) {
            world.setBlockState(pos, block.getDefaultState().cycleProperty(BlockBeetroot.BEETROOT_AGE));
        } else {
            world.setBlockState(pos, block.getDefaultState().cycleProperty(BlockCrops.AGE));
        }
    }
    return super.activeUse(stackIn, world, player, hand, strength, target);
}
Also used : BlockCrops(net.minecraft.block.BlockCrops) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockBeetroot(net.minecraft.block.BlockBeetroot) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project ConvenientAdditions by Necr0.

the class BlockEnderProof method rayTraceBlocks.

public static List<BlockPos> rayTraceBlocks(World w, Vec3d vec31, Vec3d vec32, boolean ignoreBlockWithoutBoundingBox, @Nullable FloodFill.BlockMatcher matcher) {
    List<BlockPos> ret = new ArrayList<>();
    if (!Double.isNaN(vec31.xCoord) && !Double.isNaN(vec31.yCoord) && !Double.isNaN(vec31.zCoord)) {
        if (!Double.isNaN(vec32.xCoord) && !Double.isNaN(vec32.yCoord) && !Double.isNaN(vec32.zCoord)) {
            int i = MathHelper.floor(vec32.xCoord);
            int j = MathHelper.floor(vec32.yCoord);
            int k = MathHelper.floor(vec32.zCoord);
            int l = MathHelper.floor(vec31.xCoord);
            int i1 = MathHelper.floor(vec31.yCoord);
            int j1 = MathHelper.floor(vec31.zCoord);
            BlockPos blockpos = new BlockPos(l, i1, j1);
            IBlockState iblockstate = w.getBlockState(blockpos);
            if (!ret.contains(blockpos) && matcher.matches(iblockstate)) {
                Block block = iblockstate.getBlock();
                if ((!ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(w, blockpos) != Block.NULL_AABB) && block.canCollideCheck(iblockstate, true)) {
                    RayTraceResult raytraceresult = iblockstate.collisionRayTrace(w, blockpos, vec31, vec32);
                    if (raytraceresult != null) {
                        ret.add(blockpos);
                    }
                }
            }
            int k1 = 200;
            while (k1-- >= 0) {
                if (Double.isNaN(vec31.xCoord) || Double.isNaN(vec31.yCoord) || Double.isNaN(vec31.zCoord)) {
                    return ret;
                }
                if (l == i && i1 == j && j1 == k) {
                    return ret;
                }
                boolean flag2 = true;
                boolean flag = true;
                boolean flag1 = true;
                double d0 = 999.0D;
                double d1 = 999.0D;
                double d2 = 999.0D;
                if (i > l) {
                    d0 = (double) l + 1.0D;
                } else if (i < l) {
                    d0 = (double) l + 0.0D;
                } else {
                    flag2 = false;
                }
                if (j > i1) {
                    d1 = (double) i1 + 1.0D;
                } else if (j < i1) {
                    d1 = (double) i1 + 0.0D;
                } else {
                    flag = false;
                }
                if (k > j1) {
                    d2 = (double) j1 + 1.0D;
                } else if (k < j1) {
                    d2 = (double) j1 + 0.0D;
                } else {
                    flag1 = false;
                }
                double d3 = 999.0D;
                double d4 = 999.0D;
                double d5 = 999.0D;
                double d6 = vec32.xCoord - vec31.xCoord;
                double d7 = vec32.yCoord - vec31.yCoord;
                double d8 = vec32.zCoord - vec31.zCoord;
                if (flag2) {
                    d3 = (d0 - vec31.xCoord) / d6;
                }
                if (flag) {
                    d4 = (d1 - vec31.yCoord) / d7;
                }
                if (flag1) {
                    d5 = (d2 - vec31.zCoord) / d8;
                }
                if (d3 == -0.0D) {
                    d3 = -1.0E-4D;
                }
                if (d4 == -0.0D) {
                    d4 = -1.0E-4D;
                }
                if (d5 == -0.0D) {
                    d5 = -1.0E-4D;
                }
                EnumFacing enumfacing;
                if (d3 < d4 && d3 < d5) {
                    enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
                    vec31 = new Vec3d(d0, vec31.yCoord + d7 * d3, vec31.zCoord + d8 * d3);
                } else if (d4 < d5) {
                    enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
                    vec31 = new Vec3d(vec31.xCoord + d6 * d4, d1, vec31.zCoord + d8 * d4);
                } else {
                    enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
                    vec31 = new Vec3d(vec31.xCoord + d6 * d5, vec31.yCoord + d7 * d5, d2);
                }
                l = MathHelper.floor(vec31.xCoord) - (enumfacing == EnumFacing.EAST ? 1 : 0);
                i1 = MathHelper.floor(vec31.yCoord) - (enumfacing == EnumFacing.UP ? 1 : 0);
                j1 = MathHelper.floor(vec31.zCoord) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
                blockpos = new BlockPos(l, i1, j1);
                IBlockState iblockstate1 = w.getBlockState(blockpos);
                if (!ret.contains(blockpos) && matcher.matches(iblockstate1)) {
                    Block block1 = iblockstate1.getBlock();
                    if ((!ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(w, blockpos) != Block.NULL_AABB) && block1.canCollideCheck(iblockstate, true)) {
                        RayTraceResult raytraceresult = iblockstate1.collisionRayTrace(w, blockpos, vec31, vec32);
                        if (raytraceresult != null) {
                            ret.add(blockpos);
                        }
                    }
                }
            }
        }
    }
    return ret;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) CABlock(convenientadditions.base.block.CABlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 8 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method requestEntityToBuildingIfRequired.

/**
     * Adds entities to the builder building if he needs it.
     */
private void requestEntityToBuildingIfRequired(final Template.EntityInfo entityInfo) {
    if (entityInfo != null) {
        final Entity entity = getEntityFromEntityInfoOrNull(entityInfo);
        if (entity != null) {
            final List<ItemStack> request = new ArrayList<>();
            if (entity instanceof EntityItemFrame) {
                final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
                if (!InventoryUtils.isItemStackEmpty(stack)) {
                    stack.setCount(1);
                    request.add(stack);
                }
                request.add(new ItemStack(Items.ITEM_FRAME, 1));
            } else if (entity instanceof EntityArmorStand) {
                request.add(entity.getPickedResult(new RayTraceResult(worker)));
                entity.getArmorInventoryList().forEach(request::add);
            } else if (entity instanceof EntityMob) {
            //Don't try to request the monster.
            } else {
                request.add(entity.getPickedResult(new RayTraceResult(worker)));
            }
            for (final ItemStack stack : request) {
                final BuildingBuilder building = (BuildingBuilder) getOwnBuilding();
                if (stack != null && stack.getItem() != null) {
                    building.addNeededResource(stack, 1);
                }
            }
        }
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) ItemStack(net.minecraft.item.ItemStack)

Example 9 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project minecolonies by Minecolonies.

the class AbstractEntityAIStructure method spawnEntity.

/**
     * Iterates through all entities and spawns them
     * Suppressing Sonar Rule Squid:S3047
     * The rule thinks we can merge the two forge loops iterating over resources
     * But in this case the rule does not apply because that would destroy the logic.
     */
@SuppressWarnings(MULTIPLE_LOOPS_OVER_THE_SAME_SET_SHOULD_BE_COMBINED)
private Boolean spawnEntity(@NotNull final Structure.StructureBlock currentBlock) {
    final Template.EntityInfo entityInfo = currentBlock.entity;
    if (entityInfo == null) {
        return true;
    }
    final Entity entity = getEntityFromEntityInfoOrNull(entityInfo);
    if (entity != null && !isEntityAtPosition(entity, world)) {
        final List<ItemStack> request = new ArrayList<>();
        if (entity instanceof EntityItemFrame) {
            final ItemStack stack = ((EntityItemFrame) entity).getDisplayedItem();
            if (stack != null) {
                stack.setCount(stack.getCount() + 1);
                request.add(stack);
            }
            request.add(new ItemStack(Items.ITEM_FRAME, 1));
        } else if (entity instanceof EntityArmorStand) {
            request.add(entity.getPickedResult(new RayTraceResult(worker)));
            entity.getArmorInventoryList().forEach(request::add);
        } else {
            request.add(entity.getPickedResult(new RayTraceResult(worker)));
        }
        if (!Configurations.builderInfiniteResources) {
            for (final ItemStack stack : request) {
                if (checkOrRequestItems(stack)) {
                    return false;
                }
            }
            //Surpress
            for (final ItemStack stack : request) {
                if (stack == null) {
                    continue;
                }
                final int slot = worker.findFirstSlotInInventoryWith(stack.getItem(), stack.getItemDamage());
                if (slot != -1) {
                    new InvWrapper(getInventory()).extractItem(slot, 1, false);
                    reduceNeededResources(stack);
                }
            }
        }
        entity.setUniqueId(UUID.randomUUID());
        entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
        if (!world.spawnEntity(entity)) {
            Log.getLogger().info("Failed to spawn entity");
        }
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ArrayList(java.util.ArrayList) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) ItemStack(net.minecraft.item.ItemStack) Template(net.minecraft.world.gen.structure.template.Template)

Example 10 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretProjectile method onUpdate.

@Override
public void onUpdate() {
    if (this.ticksExisted > 80) {
        this.setDead();
    }
    this.lastTickPosX = this.posX;
    this.lastTickPosY = this.posY;
    this.lastTickPosZ = this.posZ;
    Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
    Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
    RayTraceResult raytraceresult = this.worldObj.rayTraceBlocks(vec3d, vec3d1);
    List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expandXyz(0.2D));
    for (Entity entity : list) {
        if (entity.canBeCollidedWith()) {
            this.onHitEntity(entity);
        }
    }
    if (raytraceresult != null) {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
            this.onHitBlock(this.worldObj.getBlockState(raytraceresult.getBlockPos()), raytraceresult.getBlockPos());
        }
    }
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
    for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, (double) f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
    //TODO: what is this?
    }
    while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
        this.prevRotationPitch += 360.0F;
    }
    while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
        this.prevRotationYaw -= 360.0F;
    }
    while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
        this.prevRotationYaw += 360.0F;
    }
    this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
    this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
    float f1 = 0.99F;
    float f2 = this.getGravityVelocity();
    if (this.isInWater()) {
        for (int j = 0; j < 4; ++j) {
            this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ, new int[0]);
        }
        f1 = 0.8F;
    }
    this.motionX *= (double) f1;
    this.motionY *= (double) f1;
    this.motionZ *= (double) f1;
    if (!this.func_189652_ae()) {
        this.motionY -= (double) f2;
    }
    this.setPosition(this.posX, this.posY, this.posZ);
}
Also used : Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

RayTraceResult (net.minecraft.util.math.RayTraceResult)32 ItemStack (net.minecraft.item.ItemStack)16 IBlockState (net.minecraft.block.state.IBlockState)12 Vec3d (net.minecraft.util.math.Vec3d)12 Entity (net.minecraft.entity.Entity)11 BlockPos (net.minecraft.util.math.BlockPos)11 TileEntity (net.minecraft.tileentity.TileEntity)9 Block (net.minecraft.block.Block)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 World (net.minecraft.world.World)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)4 ArrayList (java.util.ArrayList)4 Vector (ValkyrienWarfareBase.API.Vector)2 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)2 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)2