use of net.minecraft.entity.passive.SheepEntity in project EdenClient by HahaOO7.
the class AutoSheer method onTick.
private void onTick(ClientPlayerEntity player) {
if (!enabled)
return;
ClientPlayerInteractionManager interactionManager = MinecraftClient.getInstance().interactionManager;
if (interactionManager == null)
return;
Vec3d pos = player.getPos();
PlayerInventory inv = player.getInventory();
Hand shearHand;
if (inv.getMainHandStack().getItem() == Items.SHEARS)
shearHand = Hand.MAIN_HAND;
else if (inv.offHand.get(0).getItem() == Items.SHEARS)
shearHand = Hand.OFF_HAND;
else
return;
if (shearHand == Hand.MAIN_HAND) {
player.clientWorld.getEntitiesByClass(SheepEntity.class, player.getBoundingBox().expand(5), SheepEntity::isShearable).forEach(sheep -> {
if (!sheep.isShearable())
return;
if (sheep.getPos().squaredDistanceTo(pos) < 25) {
interactionManager.interactEntity(player, sheep, Hand.MAIN_HAND);
}
});
} else {
player.clientWorld.getEntitiesByClass(SheepEntity.class, player.getBoundingBox().expand(5), SheepEntity::isShearable).forEach(sheep -> {
if (!sheep.isShearable())
return;
if (sheep.getPos().squaredDistanceTo(pos) < 25) {
interactionManager.interactEntity(player, sheep, Hand.MAIN_HAND);
interactionManager.interactEntity(player, sheep, Hand.OFF_HAND);
}
});
}
}
use of net.minecraft.entity.passive.SheepEntity in project Jineric-Mod by Jiingy.
the class ManxLoaghtan method getChildColor.
private DyeColor getChildColor(AnimalEntity firstParent, AnimalEntity secondParent) {
DyeColor dyeColor = ((SheepEntity) firstParent).getColor();
DyeColor dyeColor2 = ((SheepEntity) secondParent).getColor();
CraftingInventory craftingInventory = createDyeMixingCraftingInventory(dyeColor, dyeColor2);
return (DyeColor) this.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, this.world).map(recipe -> recipe.craft(craftingInventory)).map(ItemStack::getItem).filter(DyeItem.class::isInstance).map(DyeItem.class::cast).map(DyeItem::getColor).orElseGet(() -> this.world.random.nextBoolean() ? dyeColor : dyeColor2);
}
use of net.minecraft.entity.passive.SheepEntity in project minecolonies by ldtteam.
the class EntityAIWorkShepherd method shearSheep.
/**
* Shears a sheep, with a chance of dying it!
*
* @return The next {@link IAIState}
*/
private IAIState shearSheep() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_SHEPHERD_SHEARING));
final List<SheepEntity> sheeps = searchForAnimals();
if (sheeps.isEmpty()) {
return DECIDE;
}
if (!equipTool(Hand.MAIN_HAND, ToolType.SHEARS)) {
return PREPARING;
}
final SheepEntity sheep = sheeps.stream().filter(sheepie -> !sheepie.isSheared() && !sheepie.isBaby()).findFirst().orElse(null);
if (worker.getMainHandItem() != null && sheep != null) {
if (walkingToAnimal(sheep)) {
return getState();
}
int enchantmentLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, worker.getMainHandItem());
enchantmentLevel *= Math.max(1.0, (getPrimarySkillLevel() / 5.0));
worker.swing(Hand.MAIN_HAND);
final List<ItemStack> items = new ArrayList<>();
if (!this.world.isClientSide) {
sheep.setSheared(true);
int qty = 1 + worker.getRandom().nextInt(enchantmentLevel + 1);
for (int j = 0; j < qty; ++j) {
items.add(new ItemStack(ITEM_BY_DYE.get(sheep.getColor())));
}
}
sheep.playSound(SoundEvents.SHEEP_SHEAR, 1.0F, 1.0F);
dyeSheepChance(sheep);
worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
worker.getCitizenExperienceHandler().addExperience(XP_PER_ACTION);
incrementActionsDoneAndDecSaturation();
for (final ItemStack item : items) {
InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(item, (worker.getInventoryCitizen()));
}
}
return DECIDE;
}
use of net.minecraft.entity.passive.SheepEntity in project ExtendedMushrooms by cech12.
the class ExtendedMushrooms method onEntityJoinWorld.
/**
* Add eat mushroom goal to sheep entities when configured.
*/
@SubscribeEvent
public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (Config.SHEEP_EAT_MUSHROOM_FROM_GROUND_ENABLED.get()) {
if (event.getEntity() instanceof SheepEntity) {
// also mushroom sheep
SheepEntity sheep = ((SheepEntity) event.getEntity());
sheep.goalSelector.addGoal(5, new EatMushroomGoal(sheep));
}
}
}
use of net.minecraft.entity.passive.SheepEntity in project ExtendedMushrooms by cech12.
the class EatMushroomGoal method tick.
/**
* Keep ticking a continuous task that has already been started
*/
@Override
public void tick() {
this.eatingTimer = Math.max(0, this.eatingTimer - 1);
if (this.eatingTimer == 4) {
BlockPos blockPos = getBlockPos();
if (this.isEntityOnMushroom()) {
MushroomType mushroomType = MushroomType.byItemOrNull(this.entityWorld.getBlockState(this.eaterEntity.blockPosition()).getBlock().asItem());
if (this.entityWorld.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
this.entityWorld.destroyBlock(blockPos, false);
}
this.eaterEntity.ate();
if (Config.SHEEP_ABSORB_MUSHROOM_TYPE_ENABLED.get()) {
if (this.eaterEntity instanceof SheepEntity && mushroomType != null) {
if (this.eaterEntity instanceof MushroomSheepEntity) {
MushroomSheepEntity mushroomSheep = (MushroomSheepEntity) this.eaterEntity;
mushroomSheep.setMushroomType(mushroomType);
mushroomSheep.activateMushroomEffect(mushroomType);
} else {
MushroomSheepEntity.replaceSheep((SheepEntity) this.eaterEntity, mushroomType);
}
}
}
}
}
}
Aggregations