Search in sources :

Example 71 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class TileShelf method onClicked.

protected boolean onClicked(float hitX, float hitY, float hitZ, EntityPlayer player) {
    int slotId = getSlotId(hitX, hitY, hitZ);
    if (slotId < 0)
        return false;
    if (handler.getStackInSlot(slotId).isEmpty()) {
        slotId = toNonBookSlotId(slotId);
    }
    ItemStack stack = handler.getStackInSlot(slotId);
    if (stack.isEmpty())
        return false;
    handler.setStackInSlot(slotId, ItemStack.EMPTY);
    markBlockForUpdate();
    ItemUtils.giveOrSpawnItemEntity(player, getWorld(), new Vec3d(pos).addVector(hitX, hitY, hitZ), stack, 0, 0, 0, 0, true);
    return true;
}
Also used : ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 72 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class BlockShelf method onBlockClicked.

@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
    if (worldIn.isRemote)
        return;
    IBlockState state = worldIn.getBlockState(pos);
    RayTraceResult result = RayTraceUtils.getCollision(worldIn, pos, playerIn, getBoundingBox(state, worldIn, pos));
    if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.sideHit == state.getValue(Properties.FACING4).getOpposite()) {
        TileShelf bookshelf = (TileShelf) worldIn.getTileEntity(pos);
        if (bookshelf != null) {
            Vec3d v = result.hitVec.subtract(pos.getX(), pos.getY(), pos.getZ());
            bookshelf.onClicked((float) v.x, (float) v.y, (float) v.z, playerIn);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 73 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class BlockShelf method getStateForPlacement.

@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    Vec3d placementVec = new Vec3d(hitX - 0.5F, hitY - 0.5F, hitZ - 0.5F).subtract(facing.getFrontOffsetX(), facing.getFrontOffsetY(), facing.getFrontOffsetZ());
    placementVec = placementVec.rotateYaw(placer.getHorizontalFacing().getHorizontalAngle() / 180 * (float) Math.PI);
    return this.getDefaultState().withProperty(Properties.FACING4, placer.getHorizontalFacing()).withProperty(BACK, placementVec.z > 0);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d)

Example 74 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class TileRecordPlayer method activate.

public boolean activate(EntityPlayer player, EnumFacing side, EnumHand hand, Vec3d hitPos) {
    if (player.isSneaking() && side.getAxis() != EnumFacing.Axis.Y) {
        if (!world.isRemote) {
            player.openGui(ModCharset.instance, GuiHandlerCharset.RECORD_PLAYER, getWorld(), getPos().getX(), getPos().getY(), getPos().getZ());
        }
        return true;
    }
    Vec3d realPos = hitPos.subtract(0.5, 0.5, 0.5).rotateYaw((float) (getFacing().getHorizontalAngle() * Math.PI / 180));
    if (side == EnumFacing.UP) {
        if (realPos.x > -0.075 && realPos.z > -0.25 && !getStack().isEmpty()) {
            if (realPos.x > 0.4) {
                if (!world.isRemote) {
                    setState(TraitRecordPlayer.State.STOPPED);
                }
                return true;
            } else {
                if (player.isSneaking()) {
                    // TODO: Store state, allow for recording turning off
                    if (getState() == TraitRecordPlayer.State.PAUSED) {
                        if (!world.isRemote) {
                            setState(TraitRecordPlayer.State.PLAYING);
                            markBlockForUpdate();
                        }
                        return true;
                    } else if (getState() == TraitRecordPlayer.State.PLAYING) {
                        if (!world.isRemote) {
                            setState(TraitRecordPlayer.State.PAUSED);
                            markBlockForUpdate();
                        }
                        return true;
                    } else if (getState() == TraitRecordPlayer.State.RECORDING) {
                        return true;
                    }
                } else {
                    if (!world.isRemote) {
                        if (getState() == TraitRecordPlayer.State.STOPPED) {
                            setState(TraitRecordPlayer.State.PLAYING);
                        }
                        // 0.05f = 0.12f
                        // 0.25f = 0.35f
                        float fmul = 0.0085f;
                        float fsub = 0.05f;
                        float fstart = (CharsetAudioStorage.quartzDisc.getArmStartPosition(holder.getStack()) * fmul) - fsub;
                        float fend = (32f * fmul) - fsub;
                        // System.out.println(fstart + " . " + fend);
                        float newPos = 1f - ((float) (realPos.x - fstart) / (fend - fstart));
                        if (newPos < 0.0f)
                            newPos = 0.0f;
                        else if (newPos > 1.0f)
                            newPos = 1.0f;
                        IDataStorage storage = this.getStorage();
                        if (storage != null) {
                            storage.setPosition(Math.round((storage.getSize() - 1) * newPos));
                            updateProgressClient();
                            this.player.stopAudioPlayback();
                        }
                        markBlockForUpdate();
                    }
                    return true;
                }
            }
        }
        if (getStack().isEmpty() || (player.getHeldItem(hand).isEmpty() && player.isSneaking())) {
            if (holder.activate(this, player, side, hand)) {
                markBlockForUpdate();
                return true;
            }
        }
    }
    return false;
}
Also used : IDataStorage(pl.asie.charset.api.tape.IDataStorage) Vec3d(net.minecraft.util.math.Vec3d)

Example 75 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class BlockScaffold method neighborChanged.

@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
    if (!canStay(worldIn, pos)) {
        ItemStack droppedStack = new ItemStack(this);
        TileEntity tile = worldIn.getTileEntity(pos);
        if (tile instanceof TileBase) {
            droppedStack = ((TileBase) tile).getDroppedBlock(state);
        }
        ItemUtils.spawnItemEntity(worldIn, new Vec3d(pos).addVector(0.5, 0.5, 0.5), droppedStack, 0.1f, 0.1f, 0.1f, 1.0f);
        worldIn.setBlockToAir(pos);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBase(pl.asie.charset.lib.block.TileBase) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Vec3d (net.minecraft.util.math.Vec3d)789 BlockPos (net.minecraft.util.math.BlockPos)204 Entity (net.minecraft.entity.Entity)118 EnumFacing (net.minecraft.util.EnumFacing)108 ItemStack (net.minecraft.item.ItemStack)100 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)97 RayTraceResult (net.minecraft.util.math.RayTraceResult)90 World (net.minecraft.world.World)90 EntityPlayer (net.minecraft.entity.player.EntityPlayer)88 IBlockState (net.minecraft.block.state.IBlockState)76 EntityLivingBase (net.minecraft.entity.EntityLivingBase)74 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)72 ResourceLocation (net.minecraft.util.ResourceLocation)68 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)59 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)59 TileEntity (net.minecraft.tileentity.TileEntity)42 Block (net.minecraft.block.Block)41 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)30 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)27 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)27