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;
}
}
}
}
}
}
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));
});
}
});
}
});
}
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();
}
}
}
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();
}
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);
}
Aggregations