예제 #1
0
 @Override
 public void updateChest(IBetterChest chest, int tick, World world, ItemStack item) {
   if (tick != 26) {
     return;
   }
   ItemStack bucket = InvUtil.getFirstItem(chest, new ItemStack(Items.bucket), true);
   if (bucket != null) {
     bucket = bucket.copy();
     bucket.stackSize = 1;
     if (InvUtil.putIntoFirstSlot(chest, new ItemStack(Items.water_bucket), false) == null) {
       InvUtil.getFirstItem(chest, bucket, false);
     }
   }
 }
예제 #2
0
 @SubscribeEvent
 public void pickup(EntityItemPickupEvent event) {
   EntityPlayer player = event.entityPlayer;
   EntityItem eitem = event.item;
   ItemStack item = eitem.getEntityItem();
   if (item != null) {
     int c = -1;
     for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
       ItemStack stack = player.inventory.getStackInSlot(i);
       if (stack != null && stack.getItem() instanceof ItemBag) {
         BagInventory inv = ItemBag.getInventory(stack);
         if (inv.isUpgradeInstalled(Upgrade.COLLECTOR.getItem())) {
           c = i;
           break;
         }
       }
     }
     if (c != -1) {
       BagInventory inv = ItemBag.getInventory(player.inventory.getStackInSlot(c));
       ItemStack ret = InvUtil.putIntoFirstSlot(inv, item, false);
       if (ret == null) {
         event.setCanceled(true);
         eitem.setDead();
       } else if (!ItemStack.areItemStacksEqual(item, ret)) {
         eitem.setEntityItemStack(ret);
       }
     }
   }
 }
예제 #3
0
  @SuppressWarnings("unchecked")
  @Override
  public void updateChest(IBetterChest chest, int tick, World world, ItemStack item) {
    if (tick == 63) {
      AxisAlignedBB bounds =
          AxisAlignedBB.getBoundingBox(
              chest.getXPos() - Reference.Conf.FEED_RADIUS / 2,
              chest.getYPos() - Reference.Conf.FEED_HEIGHT / 2,
              chest.getZPos() - Reference.Conf.FEED_RADIUS / 2,
              chest.getXPos() + Reference.Conf.FEED_RADIUS / 2,
              chest.getYPos() + Reference.Conf.FEED_HEIGHT / 2,
              chest.getZPos() + Reference.Conf.FEED_RADIUS / 2);
      List<EntityAnimal> list = world.getEntitiesWithinAABB(EntityAnimal.class, bounds);

      for (EntityAnimal entity : list) {
        if (!entity.isEntityAlive() || entity.isChild()) continue;
        if (entity instanceof IShearable && !(entity instanceof EntityMooshroom)) {
          IShearable sheep = (EntitySheep) entity;
          if (sheep.isShearable(
              null, world, entity.serverPosX, entity.serverPosY, entity.serverPosZ)) {
            // If I ever implement that it uses Shears, then this would be the place to damage it.
            ArrayList<ItemStack> items =
                sheep.onSheared(
                    null, world, entity.serverPosX, entity.serverPosY, entity.serverPosZ, 1);
            for (ItemStack wool : items) {
              if (InvUtil.putIntoFirstSlot(chest, wool, false) != null) break;
            }
          }
        } else if (entity instanceof EntityCow) {
          ItemStack bucket = InvUtil.getFirstItem(chest, new ItemStack(Items.bucket), true);
          if (bucket != null) {
            if (InvUtil.putIntoFirstSlot(chest, new ItemStack(Items.milk_bucket), false) == null) {
              InvUtil.getFirstItem(chest, new ItemStack(Items.bucket), false);
            }
          }
          if (entity instanceof EntityMooshroom) {
            ItemStack bowl = InvUtil.getFirstItem(chest, new ItemStack(Items.bowl), true);
            if (bowl != null) {
              if (InvUtil.putIntoFirstSlot(chest, new ItemStack(Items.mushroom_stew), false)
                  == null) {
                InvUtil.getFirstItem(chest, new ItemStack(Items.bowl), false);
              }
            }
          }
        }
      }
    }
  }