net.minecraft.entity.passive.CowEntity Java Examples

The following examples show how to use net.minecraft.entity.passive.CowEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DispenserBehaviorBucketCowsMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(
        method = "dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;",
        at = @At("HEAD"), cancellable = true
)
private void milkCow(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir)
{
    if (!CarpetExtraSettings.dispensersMilkCows)
        return;
    World world = pointer.getWorld();
    
    if (!world.isClient)
    {
        BlockPos pos = pointer.getBlockPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
        List<CowEntity> cows = world.getEntities(CowEntity.class, new Box(pos), e -> e.isAlive() && !e.isBaby());
        if (!cows.isEmpty())
        {
            stack.decrement(1);
            if (stack.isEmpty())
            {
                cir.setReturnValue(new ItemStack(Items.MILK_BUCKET));
            }
            else
            {
                if (((DispenserBlockEntity)pointer.getBlockEntity()).addToFirstFreeSlot(new ItemStack(Items.MILK_BUCKET)) < 0)
                {
                    this.dispense(pointer, new ItemStack(Items.MILK_BUCKET));
                }
                cir.setReturnValue(stack);
            }
        }
    }
}
 
Example #2
Source File: MixinMooshroomEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<ItemStack> onSheared(ItemStack item, IWorld world, BlockPos pos, int fortune) {
	List<ItemStack> drops = new ArrayList<>();
	this.world.addParticle(ParticleTypes.EXPLOSION, this.x, this.y + (double) (this.getHeight() / 2.0F), this.z, 0.0D, 0.0D, 0.0D);

	if (!this.world.isClient) {
		this.remove();

		CowEntity cow = EntityType.COW.create(this.world);
		cow.refreshPositionAndAngles(this.x, this.y, this.z, this.yaw, this.pitch);
		cow.setHealth(this.getHealth());
		cow.field_6283 = this.field_6283;

		if (this.hasCustomName()) {
			cow.setCustomName(this.getCustomName());
		}

		this.world.spawnEntity(cow);
		Block mushroom = this.getMooshroomType().getMushroomState().getBlock();

		// TODO: Fixes forge bug where shearing brown mooshrooms always drop red mushrooms (Fixed in 1.15)
		for (int i = 0; i < 5; ++i) {
			drops.add(new ItemStack(mushroom));
		}

		this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F);
	}

	return drops;
}
 
Example #3
Source File: PumpcownEntity.java    From the-hallow with MIT License 4 votes vote down vote up
public PumpcownEntity(EntityType<? extends CowEntity> entity, World world) {
	super(entity, world);
}
 
Example #4
Source File: PumpcownEntity.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean interactMob(PlayerEntity player, Hand hand) {
	ItemStack stack = player.getStackInHand(hand);
	if (stack.getItem() == Items.SHEARS && this.getBreedingAge() >= 0) {
		this.world.addParticle(ParticleTypes.EXPLOSION, this.getX(), this.getY() + (double) (this.getHeight() / 2.0F), this.getZ(), 0.0D, 0.0D, 0.0D);
		if (!this.world.isClient) {
			this.remove();
			
			if (this.world.getDimension().getType() == HallowedDimensions.THE_HALLOW) {
				this.world.createExplosion(this, this.getX(), this.getY(), this.getZ(), 3.0F, Explosion.DestructionType.BREAK);
			} else {
				CowEntity cow = EntityType.COW.create(this.world);
				cow.updatePositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch);
				cow.setHealth(this.getHealth());
				cow.bodyYaw = this.bodyYaw;
				if (this.hasCustomName()) {
					cow.setCustomName(this.getCustomName());
				}
				this.world.spawnEntity(cow);
			}
			
			for (int i = 0; i < 5; ++i) {
				this.world.spawnEntity(new ItemEntity(this.world, this.getX(), this.getY() + (double) this.getHeight(), this.getZ(), new ItemStack(STEM_FEATURE.getBlock())));
			}
			
			stack.damage(1, player, ((player_1) -> {
				player_1.sendToolBreakStatus(hand);
			}));
			this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F);
		}
		return true;
	} else if (stack.getItem() == Items.BOWL && this.getBreedingAge() >= 0 && !player.abilities.creativeMode) {
		stack.decrement(1);
		ItemStack stew = new ItemStack(HallowedItems.PUMPKIN_STEW);
		
		if (stack.isEmpty()) {
			player.setStackInHand(hand, stew);
		} else if (!player.inventory.insertStack(stew)) {
			player.dropItem(stew, false);
		}
		
		this.playSound(SoundEvents.ENTITY_MOOSHROOM_MILK, 1.0F, 1.0F);
		
		return true;
	} else {
		return super.interactMob(player, hand);
	}
}
 
Example #5
Source File: MixinMooshroomEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public MixinMooshroomEntity(EntityType<? extends CowEntity> entityType, World world) {
	super(entityType, world);
}