Search in sources :

Example 6 with ItemEntity

use of net.minecraft.entity.item.ItemEntity in project BluePower by Qmunity.

the class TileMachineBase method ejectItemInWorld.

public void ejectItemInWorld(ItemStack stack, Direction oppDirection) {
    float spawnX = worldPosition.getX() + 0.5F + oppDirection.getStepX() * 0.8F;
    float spawnY = worldPosition.getY() + 0.5F + oppDirection.getStepY() * 0.8F;
    float spawnZ = worldPosition.getZ() + 0.5F + oppDirection.getStepZ() * 0.8F;
    ItemEntity droppedItem = new ItemEntity(level, spawnX, spawnY, spawnZ, stack);
    droppedItem.setDeltaMovement(oppDirection.getStepX() * 0.20F, oppDirection.getStepY() * 0.20F, oppDirection.getStepZ() * 0.20F);
    level.addFreshEntity(droppedItem);
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity)

Example 7 with ItemEntity

use of net.minecraft.entity.item.ItemEntity in project BluePower by Qmunity.

the class TileDeployer method redstoneChanged.

@Override
protected void redstoneChanged(boolean newValue) {
    super.redstoneChanged(newValue);
    if (!level.isClientSide && newValue) {
        sendUpdatePacket();
        FakePlayer player = FakePlayerFactory.get((ServerWorld) level, FAKE_PLAYER_PROFILE);
        for (int i = 0; i < inventory.size(); i++) {
            ItemStack stack = inventory.get(i);
            player.inventory.setItem(i, stack);
        }
        rightClick(player, 9);
        for (int i = 0; i < inventory.size(); i++) {
            ItemStack stack = player.inventory.getItem(i);
            if (stack.isEmpty() || stack.getCount() <= 0) {
                inventory.set(i, ItemStack.EMPTY);
            } else {
                inventory.set(i, stack);
            }
            player.inventory.setItem(i, ItemStack.EMPTY);
        }
        for (int i = 0; i < player.inventory.getContainerSize(); i++) {
            ItemStack stack = player.inventory.getItem(i);
            if (!stack.isEmpty() && stack.getCount() > 0) {
                ItemStack remainder = IOHelper.insert(this, stack, getFacingDirection().getOpposite(), false);
                if (!remainder.isEmpty()) {
                    level.addFreshEntity(new ItemEntity(level, worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5, remainder));
                }
                player.inventory.setItem(i, ItemStack.EMPTY);
            }
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 8 with ItemEntity

use of net.minecraft.entity.item.ItemEntity in project BluePower by Qmunity.

the class TileTransposer method suckEntity.

private void suckEntity() {
    Direction direction = getFacingDirection();
    AxisAlignedBB box = new AxisAlignedBB(worldPosition.getX() + direction.getStepX(), worldPosition.getY() + direction.getStepY(), worldPosition.getZ() + direction.getStepZ(), worldPosition.getX() + direction.getStepX() + 1, worldPosition.getY() + direction.getStepY() + 1, worldPosition.getZ() + direction.getStepZ() + 1);
    for (ItemEntity entity : (List<ItemEntity>) level.getEntitiesOfClass(ItemEntity.class, box)) {
        ItemStack stack = entity.getItem();
        if (isItemAccepted(stack) && entity.isAlive()) {
            addItemToOutputBuffer(stack, getAcceptedItemColor(stack));
            entity.remove();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ItemEntity(net.minecraft.entity.item.ItemEntity) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 9 with ItemEntity

use of net.minecraft.entity.item.ItemEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerDrop.

@SubscribeEvent
public static void onPlayerDrop(LivingDropsEvent event) {
    LivingEntity livingEntity = event.getEntityLiving();
    Iterator<ItemEntity> iter = event.getDrops().iterator();
    if (livingEntity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) livingEntity;
        while (iter.hasNext()) {
            ItemEntity entityItem = iter.next();
            ItemStack stack = entityItem.getItem();
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
                iter.remove();
                break;
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 10 with ItemEntity

use of net.minecraft.entity.item.ItemEntity in project AgriCraft by AgriCraft.

the class AgriHornHarvestable method spawnEntity.

private void spawnEntity(World world, BlockPos pos, ItemStack stack) {
    double x = pos.getX() + 0.5 + 0.25 * world.getRandom().nextDouble();
    double y = pos.getY() + 0.5 + 0.25 * world.getRandom().nextDouble();
    double z = pos.getZ() + 0.5 + 0.25 * world.getRandom().nextDouble();
    world.addEntity(new ItemEntity(world, x, y, z, stack));
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity)

Aggregations

ItemEntity (net.minecraft.entity.item.ItemEntity)11 ItemStack (net.minecraft.item.ItemStack)7 List (java.util.List)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Direction (net.minecraft.util.Direction)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 IAgriGeneCarrierItem (com.infinityraider.agricraft.api.v1.genetics.IAgriGeneCarrierItem)1 IAgriGenome (com.infinityraider.agricraft.api.v1.genetics.IAgriGenome)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LivingEntity (net.minecraft.entity.LivingEntity)1 IInventory (net.minecraft.inventory.IInventory)1 ITickableTileEntity (net.minecraft.tileentity.ITickableTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1 TickEvent (net.minecraftforge.event.TickEvent)1