Search in sources :

Example 1 with ItemEntity

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

the class PlayerHandler method onPlayerTick.

@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
    TickEvent.Phase phase = event.phase;
    World world = event.player.getEntityWorld();
    PlayerEntity player = event.player;
    if (phase == TickEvent.Phase.END) {
        if (!world.isRemote) {
            IInventory inventory = player.inventory;
            int mirrorCount = 0;
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack stack = inventory.getStackInSlot(i);
                if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                    mirrorCount++;
                    if (mirrorCount > 1) {
                        ItemEntity item = new ItemEntity(world, player.getPosX(), player.getPosY() + 0.5F, player.getPosZ(), stack);
                        item.setPickupDelay(50);
                        world.addEntity(item);
                        inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                        break;
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemEntity(net.minecraft.entity.item.ItemEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) TickEvent(net.minecraftforge.event.TickEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ItemEntity

use of net.minecraft.entity.item.ItemEntity in project Overloaded by CJ-MC-Mods.

the class TileEnergyInjectorChest method tick.

/**
 * Like the old updateEntity(), except more generic.
 */
@Override
public void tick() {
    if (this.getLevel().isClientSide) {
        return;
    }
    BlockPos me = this.getBlockPos();
    TileEntity frontTE = getLevel().getBlockEntity(me.offset(getFacing().getNormal()));
    frontTE.getCapability(ENERGY, getFacing().getOpposite()).ifPresent(storage -> {
        AtomicInteger energy = new AtomicInteger(storage.extractEnergy(Integer.MAX_VALUE, false));
        for (Direction facing : Direction.values()) {
            if (energy.get() == 0)
                return;
            if (facing == getFacing())
                continue;
            TileEntity te = level.getBlockEntity(me.offset(facing.getNormal()));
            te.getCapability(ITEM_HANDLER_CAPABILITY, facing.getOpposite()).ifPresent(inventory -> {
                for (int i = 0; i < inventory.getSlots(); i++) {
                    final ItemStack stack = inventory.getStackInSlot(i);
                    final int slot = i;
                    stack.getCapability(ENERGY, facing.getOpposite()).ifPresent(receiver -> {
                        ItemStack tempStack = inventory.extractItem(slot, 1, false);
                        if (tempStack.isEmpty() || !receiver.canReceive()) {
                            return;
                        }
                        int acceptedAmount = receiver.receiveEnergy(energy.get(), true);
                        if (acceptedAmount != 0) {
                            receiver.receiveEnergy(acceptedAmount, false);
                            energy.addAndGet(-storage.receiveEnergy(energy.get(), true));
                        }
                        tempStack = inventory.insertItem(slot, tempStack, false);
                        if (tempStack.isEmpty()) {
                            return;
                        }
                        getLevel().addFreshEntity(new ItemEntity(getLevel(), getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ(), tempStack));
                    });
                }
            });
        }
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 3 with ItemEntity

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

the class TileTransposer method suckItems.

private void suckItems() {
    for (ItemEntity entity : (List<ItemEntity>) level.getEntitiesOfClass(ItemEntity.class, ITEM_SUCK_AABBS[getFacingDirection().ordinal()].move(worldPosition))) {
        ItemStack stack = entity.getItem();
        if (isItemAccepted(stack) && entity.isAlive()) {
            addItemToOutputBuffer(stack, getAcceptedItemColor(stack));
            entity.remove();
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ItemEntity

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

the class TubeStack method render.

@OnlyIn(Dist.CLIENT)
public void render(float partialTick) {
    if (renderMode == RenderMode.AUTO) {
        renderMode = Minecraft.getInstance().options.graphicsMode == GraphicsFanciness.FANCY ? RenderMode.NORMAL : RenderMode.REDUCED;
    }
    final RenderMode finalRenderMode = renderMode;
    if (customRenderItem == null) {
        customRenderItem = Minecraft.getInstance().getItemRenderer();
        renderedItem = new ItemEntity(Minecraft.getInstance().level, 0, 0, 0);
    }
    double renderProgress = (oldProgress + (progress - oldProgress) * partialTick) * 2 - 1;
    GL11.glPushMatrix();
    GL11.glTranslated(heading.getStepX() * renderProgress * 0.5, heading.getStepY() * renderProgress * 0.5, heading.getStepZ() * renderProgress * 0.5);
    if (finalRenderMode != RenderMode.NONE) {
        GL11.glPushMatrix();
        if (stack.getCount() > 5) {
            GL11.glScaled(0.8, 0.8, 0.8);
        }
        if (!(stack.getItem() instanceof BlockItem)) {
            GL11.glScaled(0.8, 0.8, 0.8);
            GL11.glTranslated(0, -0.15, 0);
        }
        // TODO: customRenderItem.renderItem(stack, ItemCameraTransforms.TransformType.GROUND);
        GL11.glPopMatrix();
    } else {
        float size = 0.02F;
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glBegin(GL11.GL_QUADS);
        RenderHelper.drawColoredCube(new AxisAlignedBB(-size, -size, -size, size, size, size), 1, 1, 1, 1);
        GL11.glEnd();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }
    if (color != TubeColor.NONE) {
        float size = 0.2F;
        int colorInt = DyeColor.values()[color.ordinal()].getId();
        float red = (colorInt >> 16) / 256F;
        float green = (colorInt >> 8 & 255) / 256F;
        float blue = (colorInt & 255) / 256F;
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glColor3f(red, green, blue);
        // TODO: Find replacement for RenderEngine
        // Minecraft.getInstance().renderEngine.bindTexture(new ResourceLocation(Refs.MODID, "textures/blocks/tubes/inside_color_border.png"));
        RenderHelper.drawTesselatedTexturedCube(new AxisAlignedBB(-size, -size, -size, size, size, size));
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_LIGHTING);
    }
    GL11.glPopMatrix();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ItemEntity(net.minecraft.entity.item.ItemEntity) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 5 with ItemEntity

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

the class IOHelper method spawnItemInWorld.

public static void spawnItemInWorld(World world, ItemStack itemStack, double x, double y, double z) {
    if (world.isClientSide)
        return;
    float dX = world.random.nextFloat() * 0.8F + 0.1F;
    float dY = world.random.nextFloat() * 0.8F + 0.1F;
    float dZ = world.random.nextFloat() * 0.8F + 0.1F;
    ItemEntity entityItem = new ItemEntity(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.getCount()));
    if (itemStack.hasTag()) {
        entityItem.getItem().setTag(itemStack.getTag().copy());
    }
    float factor = 0.05F;
    entityItem.setDeltaMovement(world.random.nextGaussian() * factor, world.random.nextGaussian() * factor + 0.2F, world.random.nextGaussian() * factor);
    world.addFreshEntity(entityItem);
    itemStack.setCount(0);
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) ItemStack(net.minecraft.item.ItemStack)

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