use of net.dries007.tfc.api.capability.food.IFood in project firmalife by eerussianguy.
the class BlockString method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
TEString te = Helpers.getTE(world, pos, TEString.class);
if (te == null)
return false;
ItemStack held = player.getHeldItem(hand);
if (held.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
return false;
IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (inv == null)
return false;
ItemStack current = inv.getStackInSlot(0);
if (!held.isEmpty() && current.isEmpty()) {
IFood cap = held.getCapability(CapabilityFood.CAPABILITY, null);
if (cap != null) {
List<FoodTrait> traits = cap.getTraits();
boolean isFoodValid = (traits.contains(FoodTrait.BRINED) && OreDictionaryHelper.doesStackMatchOre(held, "categoryMeat") && HeatRecipe.get(held) != null) || OreDictionaryHelper.doesStackMatchOre(held, "cheese");
if (!traits.contains(FoodDataFL.SMOKED) && isFoodValid) {
ItemStack leftover = inv.insertItem(0, held.splitStack(1), false);
Helpers.spawnItemStack(world, pos.add(0.5D, 0.5D, 0.5D), leftover);
te.markForSync();
return true;
}
}
} else if (held.isEmpty() && !current.isEmpty()) {
Helpers.spawnItemStack(world, pos, inv.extractItem(0, 1, false));
te.markForSync();
return true;
}
}
return false;
}
use of net.dries007.tfc.api.capability.food.IFood in project firmalife by eerussianguy.
the class PizzaRecipe method getCraftingResult.
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack output = super.getCraftingResult(inv);
IFood food = output.getCapability(CapabilityFood.CAPABILITY, null);
if (food instanceof ItemPizza.PizzaHandler) {
ItemPizza.PizzaHandler trailMix = (ItemPizza.PizzaHandler) food;
List<FoodData> ingredients = new ArrayList<>();
getIngredients(inv, ingredients);
if (ingredients.size() < 1)
return ItemStack.EMPTY;
trailMix.initCreationFoods(ingredients);
// Meals get decay reset as they have on average, high decay modifiers. Also it's too much of a pain to re-calculate a remaining decay fraction average
trailMix.setCreationDate(CalendarTFC.PLAYER_TIME.getTicks());
}
return output;
}
use of net.dries007.tfc.api.capability.food.IFood in project firmalife by eerussianguy.
the class SandwichBasedRecipe method getIngredients.
protected void getIngredients(InventoryCrafting inv, List<FoodData> ingredients) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack ingredientStack = inv.getStackInSlot(i);
IFood ingredientCap = ingredientStack.getCapability(CapabilityFood.CAPABILITY, null);
if (ingredientCap != null) {
if (ingredientCap.isRotten()) {
// Found a rotten ingredient, aborting
ingredients.clear();
return;
}
ingredients.add(ingredientCap.getData());
}
}
}
use of net.dries007.tfc.api.capability.food.IFood in project firmalife by eerussianguy.
the class TrailMixRecipe method getCraftingResult.
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack output = super.getCraftingResult(inv);
IFood food = output.getCapability(CapabilityFood.CAPABILITY, null);
if (food instanceof ItemTrailMix.TrailMixHandler) {
ItemTrailMix.TrailMixHandler trailMix = (ItemTrailMix.TrailMixHandler) food;
List<FoodData> ingredients = new ArrayList<>();
getIngredients(inv, ingredients);
if (ingredients.size() < 1)
return ItemStack.EMPTY;
trailMix.initCreationFoods(ingredients);
// Meals get decay reset as they have on average, high decay modifiers. Also it's too much of a pain to re-calculate a remaining decay fraction average
trailMix.setCreationDate(CalendarTFC.PLAYER_TIME.getTicks());
}
return output;
}
use of net.dries007.tfc.api.capability.food.IFood in project firmalife by eerussianguy.
the class ItemMetalMallet method onItemUse.
@Override
@Nonnull
@SuppressWarnings("deprecation")
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) {
Block block = worldIn.getBlockState(pos).getBlock();
if (block instanceof BlockPlacedItemFlat) {
TEPlacedItemFlat tile = (TEPlacedItemFlat) worldIn.getTileEntity(pos);
if (tile == null)
return EnumActionResult.FAIL;
CrackingRecipe entry = CrackingRecipe.get(tile.getStack());
if (entry == null)
return EnumActionResult.FAIL;
if (Constants.RNG.nextInt(100) < entry.getChance()) {
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), entry.getOutputItem(tile.getStack()));
worldIn.playSound(null, pos, SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 2.0F, 1.0F);
} else
worldIn.playSound(null, pos, SoundEvents.BLOCK_WOOD_FALL, SoundCategory.BLOCKS, 2.0F, 1.0F);
tile.setStack(ItemStack.EMPTY);
worldIn.setBlockToAir(pos);
player.getHeldItem(hand).damageItem(1, player);
return EnumActionResult.SUCCESS;
} else if (block == BlocksFL.MELON_FRUIT) {
List<ItemStack> drops = block.getDrops(worldIn, pos, worldIn.getBlockState(pos), 0);
ItemStack stack = drops.get(0);
if (stack.getItem() == Item.getItemFromBlock(block)) {
IFood cap = stack.getCapability(CapabilityFood.CAPABILITY, null);
if (cap != null) {
if (!cap.isRotten()) {
for (int i = 0; i < 2 + RNG.nextInt(4); i++) Helpers.spawnItemStack(worldIn, pos, new ItemStack(ItemsFL.getFood(FoodFL.MELON)));
}
}
}
worldIn.destroyBlock(pos, false);
worldIn.playSound(null, pos, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1.0f, 1.0f);
return EnumActionResult.SUCCESS;
}
BlockPos offsetPos;
BlockPos logPos = pos;
IBlockState logState = worldIn.getBlockState(pos);
Block logBlock = logState.getBlock();
// grabbing the registry to verify you're clicking a nut tree
NutRecipe entry = NutRecipe.get(logBlock);
if (entry == null)
return EnumActionResult.FAIL;
int leafCount = 0;
for (int i = 1; i < 14; i++) {
logPos = pos.up(i);
logState = worldIn.getBlockState(logPos);
if (// we already verified that logBlock is correct
logState.getBlock() != logBlock)
break;
for (// this is a crappy leaf counting algorithm
EnumFacing d : // this is a crappy leaf counting algorithm
EnumFacing.HORIZONTALS) {
IBlockState leafState;
for (int j = 1; j < 5; j++) {
offsetPos = logPos.offset(d, j);
leafState = worldIn.getBlockState(offsetPos);
if (// offset the thing if the trunk seems to curve
j == 1 && leafState.getBlock() == logBlock)
pos = pos.offset(d, j);
if (worldIn.isAirBlock(offsetPos))
continue;
if (leafState.getBlock() == entry.getLeaves())
leafCount++;
}
}
}
if (leafCount > 0) {
Month month = CalendarTFC.CALENDAR_TIME.getMonthOfYear();
if (!(month == Month.OCTOBER || month == Month.NOVEMBER)) {
player.sendStatusMessage(new TextComponentTranslation("tooltip.firmalife.not_fall"), true);
return EnumActionResult.PASS;
}
IPlayerDataFL playerData = player.getCapability(CapPlayerDataFL.CAPABILITY, null);
if (playerData != null) {
boolean timePassed = (int) CalendarTFC.CALENDAR_TIME.getTicks() - playerData.getNuttedTime() > ConfigFL.General.BALANCE.nutTime;
boolean distanced = playerData.getNutDistance(pos) > ConfigFL.General.BALANCE.nutDistance;
if (distanced && timePassed) {
playerData.setNuttedTime();
playerData.setNutPosition(pos);
leafCount = (int) Math.ceil(leafCount * 0.66);
while (// batches drops a few times
leafCount > 0) {
int dropCount = Math.min(Constants.RNG.nextInt(4) + 1, leafCount);
BlockPos dropPos = logPos.offset(EnumFacing.random(Constants.RNG), Constants.RNG.nextInt(3) + 1);
// should be querying nut
Helpers.spawnItemStack(worldIn, dropPos, new ItemStack(entry.getNut().getItem(), Constants.RNG.nextInt(dropCount)));
TFCParticles.LEAF1.sendToAllNear(worldIn, dropPos.getX() + RNG.nextFloat() / 10, dropPos.getY() - RNG.nextFloat() / 10, dropPos.getZ() + RNG.nextFloat() / 10, (RNG.nextFloat() - 0.5) / 10, -0.15D + RNG.nextFloat() / 10, (RNG.nextFloat() - 0.5) / 10, 90);
leafCount -= dropCount;
}
worldIn.playSound(null, pos, SoundEvents.BLOCK_WOOD_PLACE, SoundCategory.BLOCKS, 3.0F, 1.0F);
player.getHeldItem(hand).damageItem(1, player);
player.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 200, 1));
} else {
if (!timePassed) {
player.sendStatusMessage(new TextComponentTranslation("tooltip.firmalife.refractory"), true);
} else {
player.sendStatusMessage(new TextComponentTranslation("tooltip.firmalife.distance"), true);
}
player.addPotionEffect(new PotionEffect(MobEffects.MINING_FATIGUE, 200, 1));
player.addPotionEffect(new PotionEffect(PotionEffectsTFC.THIRST, 200, 0));
}
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.FAIL;
}
Aggregations