Search in sources :

Example 66 with Vec3d

use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.

the class RenderThrownTomahawk method doRender.

@Override
public void doRender(EntityThrownTomahawk entity, double x, double y, double z, float entityYaw, float partialTicks) {
    if (entity == null)
        return;
    ItemStack stack = entity.getThrownStack();
    if (stack == null || stack.getItem() == null || StackHelper.isEmpty(stack))
        return;
    RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
    EntityItem entityitem = new EntityItem(entity.world, entity.posX, entity.posY, entity.posZ, stack);
    StackHelper.setCount(entityitem.getItem(), 1);
    entityitem.hoverStart = 0.0F;
    GlStateManager.pushMatrix();
    GlStateManager.disableLighting();
    Vec3d vec = new Vec3d(0.0, 0.25, 0.0);
    GlStateManager.translate(x, y, z);
    GlStateManager.rotate(90 - entity.throwYaw, 0, 1, 0);
    float rotation = entity.spin + (entity.inAir ? entity.SPIN_RATE * partialTicks : 0);
    GlStateManager.rotate(rotation, 0, 0, 1);
    GlStateManager.pushAttrib();
    RenderHelper.enableStandardItemLighting();
    itemRenderer.renderItem(entityitem.getItem(), ItemCameraTransforms.TransformType.FIXED);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.popAttrib();
    GlStateManager.enableLighting();
    GlStateManager.popMatrix();
}
Also used : RenderItem(net.minecraft.client.renderer.RenderItem) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Vec3d(net.minecraft.util.math.Vec3d)

Example 67 with Vec3d

use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.

the class ItemDrawingCompass method spawnParticles.

public boolean spawnParticles(ItemStack stack, EntityPlayer player, World world) {
    BlockPos pos1 = getBlock1(stack);
    BlockPos pos2 = getBlock2(stack);
    if (pos1.getY() <= 0 || pos2.getY() <= 0 || pos1.equals(pos2)) {
        return false;
    }
    Color color = getColor(stack);
    // Spawn circle.
    BlockPos center = new BlockPos(pos1.getX(), pos2.getY(), pos1.getZ());
    float radius = (float) Math.sqrt(center.distanceSq(pos2));
    int count = (int) (5 * radius);
    float increment = (float) (2 * Math.PI / count);
    float start = increment * (world.getTotalWorldTime() % 30) / 30f;
    Vec3d vec;
    for (float angle = start; angle < 2 * Math.PI + start; angle += increment) {
        vec = new Vec3d(radius, 0, 0).rotateYaw(angle);
        particle(player, world, color, center.getX() + 0.5 + vec.x, center.getY() + 0.5 + vec.y, center.getZ() + 0.5 + vec.z);
    }
    // Spawn line.
    double distance = Math.sqrt(pos1.distanceSq(pos2));
    count = (int) (2 * distance);
    double dx = (double) (pos2.getX() - pos1.getX()) / count;
    double dy = (double) (pos2.getY() - pos1.getY()) / count;
    double dz = (double) (pos2.getZ() - pos1.getZ()) / count;
    for (int i = 0; i < count; ++i) {
        vec = new Vec3d(pos1.getX() + 0.5 + i * dx, pos1.getY() + 0.5 + i * dy, pos1.getZ() + 0.5 + i * dz);
        particle(player, world, color, vec.x, vec.y, vec.z);
    }
    return true;
}
Also used : Color(net.silentchaos512.lib.util.Color) EnumDyeColor(net.minecraft.item.EnumDyeColor) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 68 with Vec3d

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

the class TrackCombiner method onLeftClickBlock.

@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    if (event.getEntityPlayer().isSneaking()) {
        IBlockState state = world.getBlockState(pos);
        if (transformInv.containsKey(state)) {
            Pair<ItemStack, IBlockState> pair = transformInv.get(state);
            if (!world.isRemote) {
                ItemUtils.spawnItemEntity(world, new Vec3d(pos).addVector(0.5, 0.125, 0.5), pair.getLeft().copy(), 0.02f, 0.05f, 0.02f, 1.0f);
            }
            world.setBlockState(pos, pair.getRight());
            event.setCanceled(true);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 69 with Vec3d

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

the class ItemChisel method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (hand == EnumHand.OFF_HAND) {
        return EnumActionResult.PASS;
    }
    if (!worldIn.isRemote) {
        IBlockState state = worldIn.getBlockState(pos);
        if (!state.getBlock().isAir(state, worldIn, pos)) {
            ItemStack inputStack = state.getBlock().getPickBlock(state, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), facing, pos), worldIn, pos, playerIn);
            if (!inputStack.isEmpty() && inputStack.getCount() == 1) {
                ItemStack heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND);
                ItemStack[] inputStacks = new ItemStack[9];
                int inputMask = getBlockMask(heldItem);
                int inputCount = 0;
                for (int i = 0; i < 9; i++) {
                    if ((inputMask & (1 << i)) != 0) {
                        inputStacks[i] = inputStack;
                        inputCount++;
                    }
                }
                ItemStack result = FastRecipeLookup.getCraftingResult(RecipeUtils.getCraftingInventory(3, 3, RecipeUtils.defaultContainer(playerIn), inputStacks), worldIn);
                if (result != null && !result.isEmpty() && !(result.getItem() instanceof ItemBlock && ((ItemBlock) result.getItem()).getBlock() instanceof BlockButton)) {
                    if (result.getItem() instanceof ItemBlock) {
                        Block block = ((ItemBlock) result.getItem()).getBlock();
                        if (block instanceof BlockButton) {
                            return EnumActionResult.FAIL;
                        }
                        if (block instanceof BlockStairs && (inputCount == 6 && result.getCount() >= 4 && result.getCount() <= 8)) {
                            result.setCount(inputCount);
                        }
                    }
                    if ((result.getCount() % inputCount) == 0) {
                        ItemStack resultCopy = result.copy();
                        resultCopy.setCount(1);
                        ActionResult<ItemStack> placeResult = ToolsUtils.placeBlockOrRollback(resultCopy, playerIn, worldIn, pos);
                        if (placeResult.getType() == EnumActionResult.FAIL) {
                            return EnumActionResult.FAIL;
                        }
                        if (result.getCount() > inputCount) {
                            ItemStack resultCopyRemainder = result.copy();
                            resultCopyRemainder.setCount((result.getCount() / inputCount) - 1);
                            Block.spawnAsEntity(worldIn, pos, resultCopyRemainder);
                        }
                    }
                }
            }
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockStairs(net.minecraft.block.BlockStairs) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockButton(net.minecraft.block.BlockButton) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) Vec3d(net.minecraft.util.math.Vec3d)

Example 70 with Vec3d

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

the class TileShelf method onActivated.

protected boolean onActivated(float hitX, float hitY, float hitZ, ItemStack stack, EntityPlayer player) {
    int slotId = getSlotId(hitX, hitY, hitZ);
    if (slotId < 0)
        return false;
    if (stack.isEmpty()) {
        if (handler.getStackInSlot(slotId).isEmpty()) {
            slotId = toNonBookSlotId(slotId);
        }
        if (!handler.getStackInSlot(slotId).isEmpty()) {
            final int sentSlotId = slotId;
            new Notice(new Vec3d(pos).addVector(hitX, hitY, hitZ), msg -> msg.withItem(handler.getStackInSlot(sentSlotId)).setMessage(new TextComponentString("{ITEM_NAME}{ITEM_INFOS_NEWLINE}"))).sendTo(player);
            return true;
        } else {
            return false;
        }
    } else {
        if (!isBook(stack))
            slotId = toNonBookSlotId(slotId);
        if (isSlotTaken(slotId))
            return false;
        stack = stack.splitStack(1);
        handler.setStackInSlot(slotId, stack);
        markBlockForUpdate();
        return true;
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemUtils(pl.asie.charset.lib.utils.ItemUtils) Constants(net.minecraftforge.common.util.Constants) Properties(pl.asie.charset.lib.Properties) UnlistedPropertyGeneric(pl.asie.charset.lib.utils.UnlistedPropertyGeneric) EnumFacing(net.minecraft.util.EnumFacing) Capability(net.minecraftforge.common.capabilities.Capability) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) TileBase(pl.asie.charset.lib.block.TileBase) Vec3d(net.minecraft.util.math.Vec3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) INoticeUpdater(pl.asie.charset.lib.notify.INoticeUpdater) Notice(pl.asie.charset.lib.notify.Notice) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ItemMaterialRegistry(pl.asie.charset.lib.material.ItemMaterialRegistry) ItemHandlerCharset(pl.asie.charset.lib.ui.ItemHandlerCharset) Nullable(javax.annotation.Nullable) Notice(pl.asie.charset.lib.notify.Notice) Vec3d(net.minecraft.util.math.Vec3d) TextComponentString(net.minecraft.util.text.TextComponentString)

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