Search in sources :

Example 26 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.

the class Rune method beginStackStage.

@Override
public SpellCastResult beginStackStage(ItemSpellBase item, ItemStack stack, EntityLivingBase caster, EntityLivingBase target, World world, double x, double y, double z, int side, boolean consumeMBR, int useCount) {
    int procs = SpellUtils.instance.getModifiedInt_Add(1, stack, caster, target, world, 0, SpellModifiers.PROCS);
    boolean targetWater = SpellUtils.instance.modifierIsPresent(SpellModifiers.TARGET_NONSOLID_BLOCKS, stack, 0);
    MovingObjectPosition mop = item.getMovingObjectPosition(caster, world, 8.0f, true, targetWater);
    if (mop == null || mop.typeOfHit == MovingObjectType.ENTITY)
        return SpellCastResult.EFFECT_FAILED;
    if (!BlocksCommonProxy.spellRune.placeAt(world, mop.blockX, mop.blockY + 1, mop.blockZ, SpellUtils.instance.mainAffinityFor(stack).ordinal())) {
        return SpellCastResult.EFFECT_FAILED;
    }
    if (!world.isRemote) {
        world.setTileEntity(mop.blockX, mop.blockY + 1, mop.blockZ, BlocksCommonProxy.spellRune.createTileEntity(world, 0));
        BlocksCommonProxy.spellRune.setSpellStack(world, mop.blockX, mop.blockY + 1, mop.blockZ, SpellUtils.instance.popStackStage(stack));
        BlocksCommonProxy.spellRune.setPlacedBy(world, mop.blockX, mop.blockY + 1, mop.blockZ, caster);
        int meta = world.getBlockMetadata(mop.blockX, mop.blockY + 1, mop.blockZ);
        BlocksCommonProxy.spellRune.setNumTriggers(world, mop.blockX, mop.blockY + 1, mop.blockZ, meta, procs);
    }
    return SpellCastResult.SUCCESS;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition)

Example 27 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project ArsMagica2 by Mithion.

the class ItemWakebloom method onItemRightClick.

/**
	 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
	 */
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);
    if (movingobjectposition == null) {
        return par1ItemStack;
    } else {
        if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) {
                return par1ItemStack;
            }
            if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
                return par1ItemStack;
            }
            if (par2World.getBlock(i, j, k).getMaterial() == Material.water && par2World.getBlockMetadata(i, j, k) == 0 && par2World.isAirBlock(i, j + 1, k)) {
                par2World.setBlock(i, j + 1, k, BlocksCommonProxy.wakebloom);
                if (!par3EntityPlayer.capabilities.isCreativeMode) {
                    --par1ItemStack.stackSize;
                }
            }
        }
        return par1ItemStack;
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition)

Example 28 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project Engine by VoltzEngine-Project.

the class TestAbstractLocation method testInit.

/**
     * Tests constructors
     */
public void testInit() {
    List<TLocation> locations = new ArrayList();
    //Test main method
    locations.add(new TLocation(world, 10, 11, 12));
    //Test entity method
    Entity entity = new EntitySheep(world);
    entity.setPosition(10, 11, 12);
    locations.add(new TLocation(entity));
    //Test tile
    TileEntity tile = new TileEntity();
    tile.setWorldObj(world);
    tile.xCoord = 10;
    tile.yCoord = 11;
    tile.zCoord = 12;
    locations.add(new TLocation(tile));
    //Test NBT method
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("dimension", world.provider.dimensionId);
    tag.setDouble("x", 10);
    tag.setDouble("y", 11);
    tag.setDouble("z", 12);
    locations.add(new TLocation(tag));
    //Test byte buf method
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(world.provider.dimensionId);
    buf.writeDouble(10);
    buf.writeDouble(11);
    buf.writeDouble(12);
    locations.add(new TLocation(buf));
    //Test IWorldPosition
    locations.add(new TLocation(new IWorldPosition() {

        @Override
        public World world() {
            return world;
        }

        @Override
        public double x() {
            return 10;
        }

        @Override
        public double y() {
            return 11;
        }

        @Override
        public double z() {
            return 12;
        }
    }));
    //Test world, IPos3D
    locations.add(new TLocation(world, new IPos3D() {

        @Override
        public double x() {
            return 10;
        }

        @Override
        public double y() {
            return 11;
        }

        @Override
        public double z() {
            return 12;
        }
    }));
    //Test world, vec3
    locations.add(new TLocation(world, Vec3.createVectorHelper(10, 11, 12)));
    //Test world, moving object
    locations.add(new TLocation(world, new MovingObjectPosition(10, 11, 12, 0, Vec3.createVectorHelper(10, 11, 12))));
    for (int i = 0; i < locations.size(); i++) {
        TLocation location = locations.get(i);
        assertTrue("" + i, location.world == world);
        assertTrue("" + i, location.xi() == 10);
        assertTrue("" + i, location.yi() == 11);
        assertTrue("" + i, location.zi() == 12);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ArrayList(java.util.ArrayList) EntitySheep(net.minecraft.entity.passive.EntitySheep) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) ByteBuf(io.netty.buffer.ByteBuf)

Example 29 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project Engine by VoltzEngine-Project.

the class AbstractTileTest method testGetpickBlock.

@Test
public void testGetpickBlock() {
    FakeWorld world = FakeWorld.newWorld("TestGetpickBlock");
    world.setBlock(0, 0, 0, block);
    Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        for (int i = 0; i < 256; i++) {
            tile.getPickBlock(new MovingObjectPosition(0, 0, 0, dir.ordinal(), getNextClick(dir, i).toVec3(), true));
        }
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) PacketTile(com.builtbroken.mc.core.network.packet.PacketTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) Test(org.junit.Test)

Example 30 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project ICBM-Classic by BuiltBrokenModding.

the class ItemRadarGun method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (world.isRemote) {
        MovingObjectPosition objectMouseOver = player.rayTrace(200, 1);
        TileEntity tileEntity = world.getTileEntity(objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ);
        if (!(tileEntity instanceof ILauncherController)) {
            Engine.instance.packetHandler.sendToServer(new PacketPlayerItem(player, objectMouseOver.blockX, objectMouseOver.blockY, objectMouseOver.blockZ));
        }
    }
    return stack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ILauncherController(resonant.api.explosion.ILauncherController) PacketPlayerItem(com.builtbroken.mc.core.network.packet.PacketPlayerItem)

Aggregations

MovingObjectPosition (net.minecraft.util.MovingObjectPosition)60 Vec3 (net.minecraft.util.Vec3)19 Entity (net.minecraft.entity.Entity)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)17 ItemStack (net.minecraft.item.ItemStack)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Block (net.minecraft.block.Block)8 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 AMVector3 (am2.api.math.AMVector3)5 World (net.minecraft.world.World)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 List (java.util.List)4 SpellCastResult (am2.api.spell.enums.SpellCastResult)3 ParticleApproachPoint (am2.particles.ParticleApproachPoint)3 IBlockState (net.minecraft.block.state.IBlockState)3 AMParticle (am2.particles.AMParticle)2 PacketPlayerItem (com.builtbroken.mc.core.network.packet.PacketPlayerItem)2