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