use of net.minecraft.entity.passive.CowEntity in project Culinaire by DawnTeamMC.
the class CowEntityMixin method commonExpansion_interactMob.
@Inject(method = "interactMob", at = @At(value = "HEAD"), cancellable = true)
public void commonExpansion_interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> info) {
CowEntity cowEntity = (CowEntity) (Object) this;
ItemStack itemStack = player.getStackInHand(hand);
if (itemStack.getItem() == Items.GLASS_BOTTLE && !cowEntity.isBaby()) {
player.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F);
ItemStack itemStack2 = ItemUsage.method_30012(itemStack, player, CulinaireItems.MILK_BOTTLE.getDefaultStack());
player.setStackInHand(hand, itemStack2);
info.setReturnValue(ActionResult.success(cowEntity.world.isClient));
}
}
use of net.minecraft.entity.passive.CowEntity in project minecolonies by ldtteam.
the class EntityAIWorkCowboy method milkCows.
/**
* Makes the Cowboy "Milk" the cows (Honestly all he does is swap an empty bucket for a milk bucket, there's no actual "Milk" method in {@link CowEntity}
*
* @return The next {@link IAIState}
*/
private IAIState milkCows() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_COWBOY_MILKING));
worker.getCitizenData().setVisibleStatus(HERD_COW);
if (!worker.getCitizenInventoryHandler().hasItemInInventory(getBreedingItem().getItem()) && InventoryUtils.getCountFromBuilding(getOwnBuilding(), new ItemStorage(new ItemStack(Items.BUCKET, 1))) > 1) {
if (!walkToBuilding()) {
checkAndTransferFromHut(new ItemStack(Items.BUCKET, 1));
} else {
return DECIDE;
}
}
final CowEntity cow = searchForAnimals().stream().findFirst().orElse(null);
if (cow == null) {
return DECIDE;
}
if (!walkingToAnimal(cow) && equipItem(Hand.MAIN_HAND, new ItemStack(Items.BUCKET, 1))) {
if (InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.MILK_BUCKET))) {
worker.getCitizenItemHandler().removeHeldItem();
equipItem(Hand.MAIN_HAND, new ItemStack(Items.MILK_BUCKET));
InventoryUtils.tryRemoveStackFromItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.BUCKET, 1));
}
incrementActionsDoneAndDecSaturation();
worker.getCitizenExperienceHandler().addExperience(1.0);
}
return DECIDE;
}
use of net.minecraft.entity.passive.CowEntity in project ExtendedMushrooms by cech12.
the class MushroomSporesItem method interactLivingEntity.
@Override
public ActionResultType interactLivingEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity target, Hand hand) {
boolean itemUsed = false;
World world = target.level;
if (!world.isClientSide && world instanceof ServerWorld) {
if (target instanceof CowEntity && !(target instanceof MooshroomEntity)) {
// Cow to Mooshroom
target.setSpeed(0);
// create mooshroom
MooshroomEntity mooshroom = EntityType.MOOSHROOM.create(target.level);
if (mooshroom != null) {
mooshroom.copyPosition(target);
mooshroom.finalizeSpawn((ServerWorld) world, world.getCurrentDifficultyAt(target.blockPosition()), SpawnReason.CONVERSION, null, null);
mooshroom.setAge(((CowEntity) target).getAge());
if (target.hasCustomName()) {
mooshroom.setCustomName(target.getCustomName());
mooshroom.setCustomNameVisible(target.isCustomNameVisible());
}
mooshroom.setHealth(target.getHealth());
// replace cow with new mooshroom
target.remove();
world.addFreshEntity(mooshroom);
mooshroom.playSound(SoundEvents.ZOMBIE_VILLAGER_CONVERTED, 2.0F, 1.0F);
// remove one item
stack.setCount(stack.getCount() - 1);
itemUsed = true;
}
} else if (target instanceof SheepEntity && !(target instanceof MushroomSheepEntity)) {
// Sheep to Mushroom Sheep
MushroomSheepEntity.replaceSheep((SheepEntity) target, null);
itemUsed = true;
}
}
if (itemUsed) {
// remove one item
stack.setCount(stack.getCount() - 1);
return ActionResultType.SUCCESS;
}
return ActionResultType.PASS;
}
use of net.minecraft.entity.passive.CowEntity in project quilt-standard-libraries by QuiltMC.
the class QuiltDimensionTest method readyServer.
@Override
public void readyServer(MinecraftServer server) {
ServerWorld overworld = server.getWorld(World.OVERWORLD);
ServerWorld targetWorld = server.getWorld(WORLD_KEY);
if (targetWorld == null) {
throw new AssertionError("Test world somehow doesn't exist.");
}
CowEntity cow = EntityType.COW.create(overworld);
if (!cow.world.getRegistryKey().equals(World.OVERWORLD)) {
throw new AssertionError("Cow was spawned but isn't in the overworld.");
}
var target = new TeleportTarget(Vec3d.ZERO, new Vec3d(1, 1, 1), 45f, 60f);
CowEntity teleportedEntity = QuiltDimensions.teleport(cow, targetWorld, target);
if (teleportedEntity == null || !teleportedEntity.world.getRegistryKey().equals(WORLD_KEY)) {
throw new AssertionError("Cow was not teleported correctly.");
}
if (!teleportedEntity.getPos().equals(target.position)) {
throw new AssertionError("Cow was moved to different world, but not to the correct location.");
}
}
use of net.minecraft.entity.passive.CowEntity in project minecolonies by Minecolonies.
the class EntityAIWorkCowboy method milkCows.
/**
* Makes the Cowboy "Milk" the cows (Honestly all he does is swap an empty bucket for a milk bucket, there's no actual "Milk" method in {@link CowEntity}
*
* @return The next {@link IAIState}
*/
private IAIState milkCows() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_COWBOY_MILKING));
worker.getCitizenData().setVisibleStatus(HERD_COW);
if (!worker.getCitizenInventoryHandler().hasItemInInventory(getBreedingItem().getItem()) && InventoryUtils.hasBuildingEnoughElseCount(building, new ItemStorage(new ItemStack(Items.BUCKET, 1)), 2) > 1) {
if (!walkToBuilding()) {
checkAndTransferFromHut(new ItemStack(Items.BUCKET, 1));
} else {
return DECIDE;
}
}
final CowEntity cow = searchForAnimals().stream().findFirst().orElse(null);
if (cow == null) {
return DECIDE;
}
if (!walkingToAnimal(cow) && equipItem(Hand.MAIN_HAND, new ItemStack(Items.BUCKET, 1))) {
if (InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.MILK_BUCKET))) {
worker.getCitizenItemHandler().removeHeldItem();
equipItem(Hand.MAIN_HAND, new ItemStack(Items.MILK_BUCKET));
InventoryUtils.tryRemoveStackFromItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.BUCKET, 1));
}
incrementActionsDoneAndDecSaturation();
worker.getCitizenExperienceHandler().addExperience(1.0);
}
return DECIDE;
}
Aggregations