use of net.minecraftforge.common.IShearable in project BetterWithAddons by DaedalusGame.
the class HardcoreWoolHandler method shearSheep.
private void shearSheep(PlayerInteractEvent event, Entity target) {
if (!InteractionBWM.HARDCORE_SHEARING)
return;
World world = event.getWorld();
EntityPlayer player = event.getEntityPlayer();
BlockPos pos = player.getPosition();
ItemStack tool = event.getItemStack();
if (!world.isRemote && target instanceof IShearable && isShears(tool)) {
event.setCanceled(true);
event.setCancellationResult(EnumActionResult.PASS);
IShearable sheep = (IShearable) target;
if (!sheep.isShearable(tool, world, pos))
return;
java.util.Random rand = new java.util.Random();
for (ItemStack stack : InteractionBWM.convertShearedWool(sheep.onSheared(tool, world, pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, tool)))) {
EntityItem ent = target.entityDropItem(stack, 1.0F);
ent.motionY += rand.nextFloat() * 0.05F;
ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
}
tool.damageItem(1, player);
event.setCancellationResult(EnumActionResult.SUCCESS);
}
}
use of net.minecraftforge.common.IShearable in project BetterWithAddons by DaedalusGame.
the class HardcoreWoolHandler method sheepDropEvent.
@SubscribeEvent
public void sheepDropEvent(LivingDropsEvent event) {
Entity entity = event.getEntity();
World world = entity.world;
if (entity instanceof IShearable && !world.isRemote) {
InteractionBWM.convertShearedWoolEntities(event.getDrops());
}
}
use of net.minecraftforge.common.IShearable in project BetterWithAddons by DaedalusGame.
the class ItemPickaxeConvenient method onBlockStartBreak.
@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
if (player.world.isRemote || player.capabilities.isCreativeMode) {
return false;
}
IBlockState state = player.world.getBlockState(pos);
Block block = state.getBlock();
if (canShear(itemstack, state) && block instanceof IShearable) {
IShearable target = (IShearable) block;
if (target.isShearable(itemstack, player.world, pos)) {
List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
for (ItemStack stack : drops) {
InventoryUtil.addItemToPlayer(player, stack);
}
itemstack.damageItem(1, player);
player.addStat(getBlockStats(block));
// TODO: Move to IShearable implementors in 1.12+
player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
return true;
}
}
return false;
}
use of net.minecraftforge.common.IShearable in project EnderIO by SleepyTrousers.
the class ItemDarkSteelShears method itemInteractionForEntity.
@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack itemstack, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
if (entity.world.isRemote) {
return false;
}
int powerStored = getStoredPower(player);
if (powerStored < Config.darkSteelShearsPowerUsePerDamagePoint) {
return super.itemInteractionForEntity(itemstack, player, entity, hand);
}
if (entity instanceof IShearable) {
AxisAlignedBB bb = new AxisAlignedBB(entity.posX - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posY - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posZ - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posX + Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posY + Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posZ + Config.darkSteelShearsEntityAreaBoostWhenPowered);
List<Entity> sortedTargets = new ArrayList<Entity>(entity.world.getEntitiesWithinAABB(Entity.class, bb, selectShearable));
entityComparator.refPoint = entity;
Collections.sort(sortedTargets, entityComparator);
boolean result = false;
int maxSheep = Math.min(sortedTargets.size(), powerStored / Config.darkSteelShearsPowerUsePerDamagePoint);
for (int i = 0; i < maxSheep; i++) {
Entity entity2 = sortedTargets.get(i);
if (entity2 instanceof EntityLivingBase && super.itemInteractionForEntity(itemstack, player, (EntityLivingBase) entity2, hand)) {
result = true;
}
}
return result;
}
return false;
}
use of net.minecraftforge.common.IShearable in project EnderIO by SleepyTrousers.
the class TreeFarmer method harvestSingleBlock.
void harvestSingleBlock(@Nonnull IFarmer farm, @Nonnull final World world, @Nonnull final HarvestResult result, @Nonnull final BlockPos harvestPos) {
float chance = 1.0F;
NNList<ItemStack> drops = new NNList<>();
final IBlockState state = farm.getBlockState(harvestPos);
final Block blk = state.getBlock();
if (blk instanceof IShearable && hasShears && ((shearCount / result.getHarvestedBlocks().size() + noShearingPercentage) < 100)) {
drops.addAll(((IShearable) blk).onSheared(farm.getTool(FarmingTool.SHEARS), world, harvestPos, 0));
shearCount += 100;
farm.registerAction(FarmingAction.HARVEST, FarmingTool.SHEARS, state, harvestPos);
hasShears = farm.hasTool(FarmingTool.SHEARS);
if (!hasShears) {
farm.setNotification(FarmNotification.NO_SHEARS);
}
} else {
FarmingTool tool = isWood(blk) || !hasHoe ? FarmingTool.AXE : FarmingTool.HOE;
blk.getDrops(drops, world, harvestPos, state, fortune);
EntityPlayerMP joe = farm.startUsingItem(tool);
chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, harvestPos, state, fortune, chance, false, joe);
farm.registerAction(FarmingAction.HARVEST, tool, state, harvestPos);
NNList.wrap(farm.endUsingItem(tool)).apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack drop) {
result.getDrops().add(new EntityItem(world, harvestPos.getX() + 0.5, harvestPos.getY() + 0.5, harvestPos.getZ() + 0.5, drop.copy()));
}
});
if (tool == FarmingTool.AXE) {
hasAxe = farm.hasTool(FarmingTool.AXE);
if (!hasAxe) {
farm.setNotification(FarmNotification.NO_AXE);
}
} else {
hasHoe = farm.hasTool(FarmingTool.HOE);
if (!hasHoe) {
farm.setNotification(FarmNotification.NO_HOE);
}
}
}
BlockPos farmPos = farm.getLocation();
for (ItemStack drop : drops) {
if (world.rand.nextFloat() <= chance) {
result.getDrops().add(new EntityItem(world, farmPos.getX() + 0.5, farmPos.getY() + 0.5, farmPos.getZ() + 0.5, drop.copy()));
}
}
farm.getWorld().setBlockToAir(harvestPos);
}
Aggregations