Search in sources :

Example 1 with BlockPos

use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.

the class AnimationTESR method renderTileEntityFast.

public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
    if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
        return;
    }
    if (blockRenderer == null)
        blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos pos = te.getPos();
    IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
    IBlockState state = world.getBlockState(pos);
    if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
        state = state.withProperty(Properties.StaticProperty, false);
    }
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState exState = (IExtendedBlockState) state;
        if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
            float time = Animation.getWorldTime(getWorld(), partialTick);
            IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
            if (capability != null) {
                Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
                handleEvents(te, time, pair.getRight());
                // TODO: caching?
                IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
                exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
                renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
                blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IBlockAccess(net.minecraft.world.IBlockAccess) IModelState(net.minecraftforge.common.model.IModelState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine)

Example 2 with BlockPos

use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.

the class UniversalBucket method onFillBucket.

// low priority so other mods can handle their stuff first
@SubscribeEvent(priority = EventPriority.LOW)
public void onFillBucket(FillBucketEvent event) {
    if (event.getResult() != Event.Result.DEFAULT) {
        // event was already handled
        return;
    }
    // not for us to handle
    ItemStack emptyBucket = event.getEmptyBucket();
    if (emptyBucket.isEmpty() || !emptyBucket.isItemEqual(getEmpty()) || (isNbtSensitive() && ItemStack.areItemStackTagsEqual(emptyBucket, getEmpty()))) {
        return;
    }
    // needs to target a block
    RayTraceResult target = event.getTarget();
    if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
        return;
    }
    World world = event.getWorld();
    BlockPos pos = target.getBlockPos();
    ItemStack singleBucket = emptyBucket.copy();
    singleBucket.setCount(1);
    FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, event.getEntityPlayer(), world, pos, target.sideHit);
    if (filledResult.isSuccess()) {
        event.setResult(Event.Result.ALLOW);
        event.setFilledBucket(filledResult.getResult());
    } else {
        // cancel event, otherwise the vanilla minecraft ItemBucket would
        // convert it into a water/lava bucket depending on the blocks material
        event.setCanceled(true);
    }
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with BlockPos

use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.

the class DispenseFluidContainer method fillContainer.

/**
     * Picks up fluid in front of a Dispenser and fills a container with it.
     */
@Nonnull
private ItemStack fillContainer(@Nonnull IBlockSource source, @Nonnull ItemStack stack) {
    World world = source.getWorld();
    EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
    BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
    FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
    ItemStack resultStack = actionResult.getResult();
    if (!actionResult.isSuccess() || resultStack.isEmpty()) {
        return super.dispenseStack(source, stack);
    }
    if (stack.getCount() == 1) {
        return resultStack;
    } else if (((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(resultStack) < 0) {
        this.dispenseBehavior.dispense(source, resultStack);
    }
    ItemStack stackCopy = stack.copy();
    stackCopy.shrink(1);
    return stackCopy;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TileEntityDispenser(net.minecraft.tileentity.TileEntityDispenser) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with BlockPos

use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.

the class DispenseFluidContainer method dumpContainer.

/**
     * Drains a filled container and places the fluid in front of the Dispenser.
     */
@Nonnull
private ItemStack dumpContainer(IBlockSource source, @Nonnull ItemStack stack) {
    ItemStack singleStack = stack.copy();
    singleStack.setCount(1);
    IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(singleStack);
    if (fluidHandler == null) {
        return super.dispenseStack(source, stack);
    }
    FluidStack fluidStack = fluidHandler.drain(Fluid.BUCKET_VOLUME, false);
    EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
    BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
    FluidActionResult result = fluidStack != null ? FluidUtil.tryPlaceFluid(null, source.getWorld(), blockpos, stack, fluidStack) : FluidActionResult.FAILURE;
    if (result.isSuccess()) {
        ItemStack drainedStack = result.getResult();
        if (drainedStack.getCount() == 1) {
            return drainedStack;
        } else if (!drainedStack.isEmpty() && ((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(drainedStack) < 0) {
            this.dispenseBehavior.dispense(source, drainedStack);
        }
        ItemStack stackCopy = drainedStack.copy();
        stackCopy.shrink(1);
        return stackCopy;
    } else {
        return this.dispenseBehavior.dispense(source, stack);
    }
}
Also used : IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 5 with BlockPos

use of net.minecraft.util.math.BlockPos in project MinecraftForge by MinecraftForge.

the class VanillaInventoryCodeHooks method dropperInsertHook.

/**
     * Copied from BlockDropper#dispense and added capability support
     */
public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, @Nonnull ItemStack stack) {
    EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING);
    BlockPos blockpos = pos.offset(enumfacing);
    Pair<IItemHandler, Object> destinationResult = getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite());
    if (destinationResult == null) {
        return true;
    } else {
        IItemHandler itemHandler = destinationResult.getKey();
        Object destination = destinationResult.getValue();
        ItemStack dispensedStack = stack.copy().splitStack(1);
        ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
        if (remainder.isEmpty()) {
            remainder = stack.copy();
            remainder.shrink(1);
        } else {
            remainder = stack.copy();
        }
        dropper.setInventorySlotContents(slot, remainder);
        return false;
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)4488 IBlockState (net.minecraft.block.state.IBlockState)1202 TileEntity (net.minecraft.tileentity.TileEntity)675 ItemStack (net.minecraft.item.ItemStack)577 World (net.minecraft.world.World)550 Block (net.minecraft.block.Block)545 EnumFacing (net.minecraft.util.EnumFacing)517 EntityPlayer (net.minecraft.entity.player.EntityPlayer)257 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)249 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)216 Vec3d (net.minecraft.util.math.Vec3d)216 ArrayList (java.util.ArrayList)211 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)182 Entity (net.minecraft.entity.Entity)176 NBTTagList (net.minecraft.nbt.NBTTagList)139 Random (java.util.Random)130 Biome (net.minecraft.world.biome.Biome)129 Nullable (javax.annotation.Nullable)126 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)126 RayTraceResult (net.minecraft.util.math.RayTraceResult)112